OpenSSH 4.0 and later support reusing a single SSH connection to run multiple commands. For short commands, this can be a lot faster. The new supports this feature. You can use it to improve performance of anything run over ssh, including CVS and Subversion.

Quick guide

  1. Make sure you have OpenSSH 4.0 or newer. OpenSSH 4.2p1 is highly recommended:

  $ ssh -V
  OpenSSH_4.2p1, OpenSSL 0.9.7f 22 Mar 2005
  1. Add an entry in $HOME/.ssh/config for if you don't already have one, and add the ControlPath option there like this:

     ControlPath /tmp/ssh_gcc_control

  $ ssh -fMN
  1. You're done! Now, all the subsequent connections to will be much faster!

Note for old-time GCC hackers

You *must* use SSH Protocol 2 for this to work. Old GCC hackers might have only a SSH1 public key stored in (many years ago, it used to be the only supported format), so they need to either convert their old SSH1 key with ssh-keyconverter or generate a new SSH2 key (through ssh-keygen , and send the new key to . If you're using SSH Protocol 1, the ControlMaster option fails silently, the socket is not created, and nothing happens. All the ControlMaster =ControlPath= options are still accepted but they are ignored.

If you have an existing cvs/subversion-only account on you can replace your key using the following command:

 $ ssh replacekey < ~/.ssh/

To add an additional ssh key use something like the following command:

 $ ssh appendkey < ~/.ssh/

Technical information

All you need are two things: a master connection and a multiplexing socket. The entry in $HOME/.ssh/config configures the multiplexing socket to use. Now, if the socket /tmp/ssh_HOSTNAME_USERNAME exists, it will be used instead of making a new connection (otherwise a normal connection will be made). To create the socket, you need to open a master connection. Just ssh to using the ControlMaster (-M) option. You don't need to run a command on the remote side, so you should also use -N (no command). Another useful option is -f (fork to the background). Putting this together, this brings to the command line shown above ssh -fMN .

Note that the open connection has your authentication tokens to the remote server. If you leave the machine where you started the master SSH session, you should usually kill it.

Example measurement of the speedup

The following is a misuse of subversion, but it illustrates how the speedup comes about: subversion opens a new connection on every file given on the commandline, hence the time taken for connecting contributes significantly (again: this is not the way one would usually use subversion, cvs does this particular example much faster)

~/src/gcc_svn/gcc/fortran> time svn up *h >/dev/null

real    0m43.647s
user    0m0.290s
sys     0m0.080s
~/src/gcc_svn/gcc/fortran> ssh -M -N -f
~/src/gcc_svn/gcc/fortran> time svn up *h >/dev/null

real    0m26.710s
user    0m0.120s
sys     0m0.060s

Platform specific notes

Unfortunately if you are using OpenSSH on Cygwin you will not be able to take advantage of connection caching because Cygwin does not currently support file descriptor passing via unix-domain sockets.

None: SSH_connection_caching (last edited 2008-05-21 00:45:45 by pool-72-74-94-32)