line34
Coding, Scripting, Administration

Share what you open

I often work remotely on a server with two or more shells running at once. Lately the thought that one ssh connection should be enough for a couple of shells got stuck in my mind. I checked the man page and discovered the ControlPath and ControlMaster parameters. The former specifies the location of a control socket that is used for a shared connection, while the latter determines if the current ssh process should manage the shared connection or just connect to the socket as a slave. Adding the lines

ControlPath ~/.ssh/ssh-%r@%h:%p.sock
ControlMaster auto

to your ssh config file (usually ~/.ssh/config) causes a starting ssh process to check the specified location for a socket and, if it exists, connect to it, or if it doesn't, create a new shared connection including the socket.

NB. If your connection (shared or not) gets stuck when you leave it idle for a while, it could be due to firewall restrictions. Check the ServerAliveInterval parameter.

9th November 2014Filed under: ssh