Last Updated: February 25, 2016
·
1.068K
· rodnaph

Reuse SSH Sessions

When logging in to remote servers with SSH, you often find you need another shell (like when you need to tail a log file and use Vim). You can use terminal multiplexors like screen and tmux if they're available, but often it's easier to just open another terminal.

But then of course you need to re-authenticate, and if you're using password pased auth this can be annoying. Add the following snippet to your ~/.ssh/config file to enable reusing existing sessions...

host *
    controlmaster auto
    controlpath /tmp/ssh-%r@%h:%p

Now, when you try and connect to a server you already have a session with it'll reuse the existing session and you'll be straight in! You can alter the host parameter to only enable this for specific servers too.

Using key-based auth is probably better, but this can be useful all the same.