#/lib/systemd/system/autossh.service
[Unit]
Description=Auto Reverse SSH
Requires=systemd-networkd-wait-online.service
After=systemd-networkd-wait-online.service
[Service]
Type=forking
ExecStart=/usr/bin/autossh -M 0 -f -N -R 2255:localhost:22 user@domain -g -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes
[Install]
WantedBy=multi-user.target
再起動後
sudo systemctl status autossh.service
● autossh.service - Auto Reverse SSH
Loaded: loaded (/lib/systemd/system/autossh.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2018-01-17 00:05:15 -03; 5min ago
Process: 807 ExecStart=/usr/bin/autossh -M 0 -f -N -R 2255:localhost:22 user@domain -g -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes (code=exited, status=0/SUCCESS)
Main PID: 815 (autossh)
CGroup: /system.slice/autossh.service
└─815 /usr/lib/autossh/autossh -M 0 -N -R 2255:localhost:22 user@domain -g -o ServerAliveInterval=60 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes
Jan 17 00:06:28 raspberrypi autossh[815]: ssh exited with error status 255; restarting ssh
Jan 17 00:07:00 raspberrypi autossh[815]: starting ssh (count 10)
Jan 17 00:07:00 raspberrypi autossh[815]: ssh child pid is 2166
Jan 17 00:07:01 raspberrypi autossh[815]: ssh exited with error status 255; restarting ssh
Jan 17 00:07:51 raspberrypi autossh[815]: starting ssh (count 11)
Jan 17 00:07:51 raspberrypi autossh[815]: ssh child pid is 2188
Jan 17 00:07:53 raspberrypi autossh[815]: ssh exited with error status 255; restarting ssh
Jan 17 00:09:05 raspberrypi autossh[815]: starting ssh (count 12)
Jan 17 00:09:05 raspberrypi autossh[815]: ssh child pid is 2213
Jan 17 00:09:05 raspberrypi autossh[815]: ssh exited with error status 255; restarting ssh
ssh exited with error status 255
トンネルを通しては届かないからuser@domain
ssh -R 2255:localhost:22 user@domain
そして
/usr/bin/autossh -M 0 -f -N -R 2255:localhost:22 user@domain -g -o ServerAliveInterval=60 -o ServerAliveCountMax=3
うまくいきます。 2台のコンピュータ間で継続的な接続を希望します。
試してみましたが、Type=simple
結局得ました。Active: inactive (dead)