|Description=Keeps a tunnel to 'remote.example.com' open|
|# -p [PORT]|
|# -l [user]|
|# -M 0 --> no monitoring|
|# -N Just open the connection and do nothing (not interactive)|
|ExecStart=/usr/bin/autossh -M 0 -N -q -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -p 22 -l autossh remote.example.com -L 7474:127.0.0.1:7474 -i /home/autossh/.ssh/id_rsa|
Jan 10, 2023
@jotakar I've been using:
[Unit] Description=Keep open a reverse tunnel to my computer via the DMZ server After=network.target [Service] ExecStart=/usr/bin/ssh -NT tunnel RestartSec=5 Restart=always [Install] WantedBy=multi-user.target
tunnel defined in
Host tunnel HostName <redacted> User <redacted> IdentityFile ~/.ssh/id_tunnel ProxyCommand ssh bastion -W %h:%p RemoteForward <redacted port> localhost:22 ExitOnForwardFailure yes ServerAliveCountMax 5
bastion host also defined in the same file as
Host bastion HostName <redacted> User <redacted> IdentityFile ~/.ssh/id_tunnel ForwardAgent yes
I also have
Host * ServerAliveInterval 60 IdentitiesOnly yes
at the top of my
/root/.ssh/config, on the off-chance that's relevant.
I've found this to be very consistent and stable, and easy to test (
ssh -NT tunnel) when setting it up. Perhaps removing autossh and setting it up this way might help?
Mar 22, 2023
For completeness, you should also add:ExecStop=kill -9 autossh
systemctl stop autosshwon't do anything.
I think it would be better idea to add
.service file because that will kill everything that was started (recursively) and nothing more. In addition, it will first send
SIGTERM and use
SIGKILL only if the process will not stop nicely.
If you randomly kill one or all
autossh processes in the system, you might kill more than expected if
autossh is used for other stuff, too.
See https://www.freedesktop.org/software/systemd/man/systemd.kill.html#KillMode= for details
Hi, I have this service for tunnel with autossh
If I run the autossh by hand, in command line, the tunnel remains open and working fine.
But with the service I found that every a while the service restart
My log shows this:
What I see is that service stop autossh every few minutes, why? where is the error?