autossh exit when using the -f option

2.1k views Asked by At

When running autossh without the "-f" option, everything works fine. Adding the "-f" option indeed sends autossh to the background, but after the ssh tunneling established correctly the autossh itself exit, leaving the ssh connection without monitor.

Here is the command I'm running: autossh -f -M 20000 -N -L 0.0.0.0:5601:10.10.0.8:5601 10.10.0.8

Anyone knows what can cause this problem? alternatively - anyone knows how can I debug autossh when using the "-f"? (is there any log file produce when using AUTOSSH_DEBUG=1)?

(I'm running on Ubuntu 14.04)

Thanks, Shay

2

There are 2 answers

1
dan4thewin On

Seeing as no one has a better suggestion... Try running autossh under a watchdog like daemontools. With this method autossh runs as a foreground child of a supervise daemon (so, no -f switch). You can start and stop it with the svc command, and you can log all of its output with multilog.

This method has proven sufficiently reliable for me, on a fleet of production boxes.

0
raine On

On macOS I had a problem where autossh -M 0 -R 1234:localhost:22 worked but adding -f to make autossh run in background would log the following and autossh would die instantly:

2018/04/10 12:00:06 autossh[67839]: ssh exited with status 0; autossh exiting

Adding -N ("Do not execute a remote command.") fixed the issue:

autossh -f -M 0 -N -R 1234:localhost:22

Seeing you already had -N in the command this is probably unrelated but possibly helpful to others.