Skip to content

Instantly share code, notes, and snippets.

@sjmuniz
Forked from thomasfr/autossh.service
Last active November 27, 2017 04:01
Show Gist options
  • Save sjmuniz/5e52ef9cdeb791e598e4200aa84265e2 to your computer and use it in GitHub Desktop.
Save sjmuniz/5e52ef9cdeb791e598e4200aa84265e2 to your computer and use it in GitHub Desktop.
Systemd service for autossh
[Unit]
Description=Keeps a tunnel to 'remote.example.com' open
After=network-online.target ssh.service
[Service]
Environment="AUTOSSH_DEBUG=1"
# User=autossh
# -p [PORT]
# -l [user]
# -M 0 --> no monitoring
# -N Just open the connection and do nothing (not interactive)
# LOCALPORT:IP_ON_EXAMPLE_COM:PORT_ON_EXAMPLE_COM
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
[Install]
WantedBy=multi-user.target
@sjmuniz
Copy link
Author

sjmuniz commented Nov 27, 2017

On Ubuntu (at least from version 16.x Xenual Xerus), create the above file as a normal user, then install it with:
$ sudo mv autossh.service /etc/systemd/system/

Make it visible for systemd with
$ sudo systemctl daemon-reload

Enable as follows:
$ sudo sudo systemctl enable autossh.service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment