Skip to content

Instantly share code, notes, and snippets.

@rtomayko
Created June 7, 2017 19:43
Show Gist options
  • Select an option

  • Save rtomayko/502aefc63d26e80ab6d7c0db66f2cb69 to your computer and use it in GitHub Desktop.

Select an option

Save rtomayko/502aefc63d26e80ab6d7c0db66f2cb69 to your computer and use it in GitHub Desktop.

Revisions

  1. rtomayko created this gist Jun 7, 2017.
    54 changes: 54 additions & 0 deletions ssh-persistent-control-master.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    # SSH Persistent Control Master Config

    Add to `~/.ssh/config`:

    ```
    Host *
    # Enable persistent connection multiplexing
    ControlMaster auto
    ControlPath ~/.ssh/-%r@%h:%p
    ControlPersist 600
    ```

    Now first connection to host will establish persistent daemon connection; subsequent
    commands will multiplex over existing connection, reducing setup/connect overhead by ~10x.

    ### Demo

    First connection establishes persistent control master daemon:

    ```
    $ time ssh example.com true
    real 0m1.687s
    user 0m0.066s
    sys 0m0.014s
    ```

    Subsequent connections:

    ```
    $ time ssh example.com true
    real 0m0.162s
    user 0m0.053s
    sys 0m0.010s
    ```

    ### Management commands

    Idle connections with no riders are auto stopped after 10 mins (`ControlPersist 600`)
    but you can manage connections manually w/ `ssh -O`:

    ```
    $ ssh -O check example.com
    Master running (pid=40196)
    $ ssh -O stop example.com
    Stop listening request sent.
    ```

    ### See Also

    - http://man.openbsd.org/ssh_config
    - http://man.openbsd.org/ssh
    - https://developer.rackspace.com/blog/speeding-up-ssh-session-creation/