Tip Cache
Your source for tech tips
Tip: Reuse an existing ssh connection
Posted By: phrakture
Speed up additional SSH connections to the same server
We can reuse an already connected SSH session to make additional ssh sessions on the same remote machine.
To do this, add the following entries to ~/.ssh/config
host *
controlmaster auto
controlpath /tmp/ssh-%r@%h:%p
What this does is set a 'master control' socket when you make an SSH connection. The socket is named based on the 'controlpath' setting (%r = username, %h = hostname, %p = port).
This master socket is used for each successive connection after the first, as long as one connection still exists. That is, if I connect via "ssh myuser@myhost.com", a socket named /tmp/ssh-myuser@myhost.com:22 is created. If I then ssh again to the same host, the socket is found and the remote ssh session is told to spawn a new shell. This shell does not require a login, and spawns immediately, as you're already logged in.
