Edit ~/.ssh/config (or /etc/ssh/ssh_config for sitewide configuration) and add the following snippet:
Host * ControlMaster auto ControlPath ~/.ssh/socket-%r@%h:%p
This will create a socket for each set (user, machine, port) when the first SSH session is opened. Further sessions will see the socket and use it instead of opening a new connection, multiplexing all concurrent connections via the same connection. The same goes for scp and sftp.
Nice side-effects of this:
- No functionality is lost at all.
- SSH sessions will open faster, as there is no need to establish a connection.
- You will not need to enter you password everytime (but note that maybe you should be using public-key authentication).
- You can open several sessions to servers which put a limit on the number of simultaneous connections.
- If you are a sysadmin, you can limit the number of SSH connections to exactly one per user
Hope you find this tip useful
Wow, very useful tip, thx. The speed up is really great.
Nice tip.
As counterpart, if someone logged in your machine can read the ~/.ssh/socket-*,he could login to hosts using those credentials.
@aklis: You are right. Fortunately OpenSSH is very picky regarding permissions of the ~/.ssh directory and will print a big warning if its permissions are different from 0700. That’s the reason why I always put session sockets in that directory
. Thanks for pointing out that issue.