Skip to content

Instantly share code, notes, and snippets.

@trysten
Last active October 14, 2018 20:53
Show Gist options
  • Save trysten/a78ac5608a4f79c699b7e733701ed7b3 to your computer and use it in GitHub Desktop.
Save trysten/a78ac5608a4f79c699b7e733701ed7b3 to your computer and use it in GitHub Desktop.
autossh v0.3
# This unit file is meant to be run on a user service.
# Put it in ~/.config/systemd/user/ and enable it with `systemctl --user enable autossh`
# Use `loginctl enable-linger username` to start systemd user service at boot
# help here: https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files
[Unit]
Description=Maintain an ssh tunnel with systemd. What could go wrong?
After=network.target
[Service]
#user should set automatically
# User = user
# Run in foreground, binding stdin and stdout as usual
Type = simple
# Restart every >2 seconds to avoid StartLimitInterval failure
RestartSec=60
Restart=always
# -N Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only).
# -T no terminal
# -C use compression gzip (for slow links)
# ExitOnForwardFailure -- reset if we can't set up the tunnel because that's all that matters
# StrictHostKeyChecking -- Try to log in no even if host changes
# ServerAliveInterval -- check an inactive tunnel for connectivity
ExecStart=/usr/bin/ssh -NT -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -R :0:localhost:22 -i /home/%u/.ssh/id_rsa %[email protected]
[Install]
#systemd --user targets are different from system-wide targets. see man 7 systemd.special
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment