Speed up multiple ssh connections to the same destination

When you are doing multiple ssh connections to one host there’s a way to speed them up by multiplexing them. When you open the first network connection a special socket is created and then all other connections to the destination machine pass through the first network connection and don’t open any new ones. All that is done via ControlMaster and ControlPath settings for ssh_config.

Example usage:
Inside /etc/ssh/ssh_config
ControlMaster auto
ControlPath /tmp/%r@%h:%p

Firsh ssh connection:
% ssh foobar@foo.bar.gr
Password:
Linux foo.bar.gr 2.6.20.1-1-686 #1 SMP Sun Mar 4 12:44:55 UTC 2007 i686 GNU/Linux
foobar@foo:~$

Second ssh connection:
% ssh -p 22 foobar@foo.bar.gr
Linux foo.bar.gr 2.6.20.1-1-686 #1 SMP Sun Mar 4 12:44:55 UTC 2007 i686 GNU/Linux
foobar@foo:~$

No password is asked and the connection opens up immediately.

kudos to apoikos for telling me about this neat feature in fosscomm 🙂

6 Responses to “Speed up multiple ssh connections to the same destination”

  1. Guest
    June 21st, 2008 | 14:54
  2. June 21st, 2008 | 17:36
    Using Mozilla Firefox Mozilla Firefox 3.0 on Gentoo Linux Gentoo Linux

    It would be weird if nobody else had written about it 🙂

    A search for http://www.google.gr/search?q=ssh+controlmaster reveals a lot more articles about it…

  3. sam
    June 22nd, 2008 | 19:51
    Using Mozilla Firefox Mozilla Firefox 3.0 on Linux Linux

    Why not just use agent?

  4. June 23rd, 2008 | 01:43
    Using Opera Opera 9.50 on Linux Linux

    Very very usefull. Thank you 🙂

  5. June 23rd, 2008 | 17:31
    Using Mozilla Firefox Mozilla Firefox 3.0 on Gentoo Linux Gentoo Linux

    @sam: ssh-agent needs public keys. This method doesn’t. And they don’t quite do the same thing. I use ssh-agent daily, but I don’t use public keys in all of the machines I administer.

  6. July 24th, 2008 | 16:17
    Using Safari Safari 525.20.1 on Mac OS X Mac OS X 10.5.4

    Excellent tip! thnx!

Leave a reply