Skip to content

Instantly share code, notes, and snippets.

@brettbeeson
Last active May 5, 2021 06:44
Show Gist options
  • Save brettbeeson/43f50e164f30e83b367c90a1942b1e6a to your computer and use it in GitHub Desktop.
Save brettbeeson/43f50e164f30e83b367c90a1942b1e6a to your computer and use it in GitHub Desktop.
autossh systemd service
[Unit]
Description=Auto Reverse SSH
# No - can fail on dependancy. No sure best way to do this.
# Requires=systemd-networkd-wait-online.service
After=systemd-networkd-wait-online.service
# Try to restart forever!
StartLimitIntervalSec=0
StartLimitInterval=0
[Service]
# run as a user who has .ssh/id_rsa private key available (usually not root)
User=pi
Type=simple
Restart=always
RestartSec=60
[Service]
ExecStart=/usr/bin/autossh -M 0 -N -R 0:localhost:22 ***user@public.com*** -o ForwardX11=no -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o ServerAliveInterval=20
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment