Ssh – make ssh tell me which control file it would use for multiplexing

multiplexingssh

I am using the following options in my ~/.ssh/config in order to enable connection multiplexing:

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

However, this has the annoying problem that the first shell to connect to a particular server must be the last to disconnect, because it is the master connection that all the other connections are using. So if you log out of the master, it appears to just hang. To solve this, I would like to wrap ssh with a script that checks if the control master file exists, and if not, starts a master ssh process in the background. Then it would start a slave ssh session.

In order to accomplish this, my script would have to determine the path to the control file that ssh would use. This would entail parsing the ssh command line options and config files and implementing the logic for determining the ControlPath. Is there any way to just ask ssh what path it would use, so I can check it?

Best Answer

Just found it. ssh -O check HOST