SSH Reusable Connections

SSH Reusable Connections

Fast, persistent, reusable connections. Something like connection sharing. Something like: really fast

The transparent multi-hop connections can be very useful but you may find that it takes a second or two to establish each connection.

The good news is that if you can configure SSH to reuse an existing connection.

Step one - create a directory which SSH will use to keep track of established connections:

mkdir "%HOMEDRIVE%%HOMEPATH%\.ssh\tmp_controlmaster_sockets"

Step two - execute this only once to add two lines at the beginning of your SSH config:

set F="%HOMEDRIVE%%HOMEPATH%\.ssh\config"

rename %F% config.backup
echo ControlPersist 4h >> %F%
echo ControlMaster auto >> %F%
echo ControlPath "%HOMEDRIVE%%HOMEPATH%/.ssh/tmp_controlmaster_sockets/%h-%p-%r" >> %F%
echo. >> %F%
type %F%.backup >> %F%

Option ControlPersist automatically starts a background multiplexer when connecting to a host for the first time. This background connection can stay alive indefinitely or it can be set to close after a specified duration of inactivity.

Not working

I get an error: mm_send_fd: UsePrivilegeSeparation=yes not supported when trying to start second connection. And at the same moment, the first connection gets aborted.

Also, on my system ControlPersist directive is not supported so I had to disable it.

Sources: SSH Can Do That? 9 Awesome SSH Tricks SSH Tricks

date 01. Jan 0001 | modified 28. May 2021
filename: SSH Reusable Connections