Dan’s View

2009/04/09

Use ssh ControlMaster to improve speed of connection time

Filed under: Geek,Server,linux — Tags: , — dan @ 18:02

I often work on many machines and end up with multiple sessions to each. Therefore I finally got around to checking out the ControlMaster and ControlPath configuration of ssh. I added the following to my ~/.ssh/config which is for a virtual machine I use on my laptop, so no network issues in play.

Host vm
 Hostname 192.168.100.101
 User dan
 ControlMaster auto
 ControlPath /Users/dan/.ssh/master-vm

Then in a terminal I ran the following, twice. Once on its own then with an ssh session running in another terminal.

for X in `seq 1 5`; do time ssh vm "pwd; uptime; hostname;" >/dev/null; done;

Without avg.: 0.268s
With avg.: 0.035s

I think that is quite impressive.

For the raw terminal output, please see here.

Update

Of course you can do this dynamically.

Host *
   ControlMaster auto
   ControlPath ~/.ssh/master-%r@%h:%p

Then each socket will be used only when the user, host and port are the same.

Powered by WordPress