I want to use autossh to maintain an ssh session configured for multiplexing. This way I can write scripts on my localhost that take advantage of the persistent ssh connection. I'm having trouble getting ssh and autossh to behave consistently and am hoping someone can help me out.

Contents of my ~/.ssh/config file...

 Host cg*
    ServerAliveInterval 300
    ServerAliveCountMax 2

    ControlMaster auto
    ControlPath ~/.ssh/control:%h:%p:%r
    ControlPersist yes

Creating the master ssh connection...
$ ssh -fNn jehudson@cg5
$ ps aux | grep ssh
jehudson 11813 0.0 0.1 5744 628 ? Ss 18:42 0:00 ssh -fNn cg5

Checking to see if the connection is being multiplexed...
$ ssh -O check cg5:
Master running (pid=11813)

Opening and closing a session over the master session...
$ ssh cg5
$ ...
$ exit
Shared connection to cg5 closed.

That much appears to be working correctly. Now I want to do the same thing but using autossh.

Terminating the master connection...
$ ssh -O exit cg5
Exit request sent.

Opening the connection via autossh...
$ autossh -M 0 -fNn jehudson@cg5
$ ps aux | grep autossh
jehudson 11826 0.0 0.1 3660 772 pts/1 S+ 18:45 0:00 grep --color=auto autossh

(!) Well that's weird... autossh doesn't seem to be starting, or if it is it is very quickly dying.

$ ps aux | grep ssh
jehudson 11823 0.0 0.1 5744 916 ? Ss 18:45 0:00 ssh: /home/jehudson/.ssh/control:cg5:22:jehudson [mux]

(!?) It appears the tunnel was opened, but after creating it autossh didn't continue to maintain it! And why is the control file listed in the process description this time?

$ ssh -O check cg5
Master running (pid=11823)

Clearly, a multiplexed ssh session has been established, but it's not being monitored by autossh.
I've tried different combinations of the flags accepted by autossh but I can't find a way to open up a simple, multiplexed ssh connection, send it to the background, and have it monitored by autossh. Please let me know if you see something I may have missed or if you have a suggestion for me to try.

1 Answer 1


It appears autossh does not play well with ControlPersist. If you leave ControlPersist enabled the connection will terminate after the persist period. So:

autossh -f -M0 -N -oControlPersist=no $DEST

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .