Skip to content

Instantly share code, notes, and snippets.

@fny
Created May 16, 2020 21:58
Show Gist options
  • Save fny/2ce2ebddd66c0b997cf71f036116d209 to your computer and use it in GitHub Desktop.
Save fny/2ce2ebddd66c0b997cf71f036116d209 to your computer and use it in GitHub Desktop.
Ubuntu service to start an AutoSSH tunnel
[Unit]
Description=AutoSSH tunnel service
After=network-online.target sshd.service
[Service]
Environment="AUTOSSH_GATETIME=0"
Environment="AUTOSSH_PORT=0"
ExecStart=/usr/bin/autossh -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -N -R 2222:localhost:22 -R 8888:localhost:8888 user@middlman.dev
[Install]
WantedBy=multi-user.target
@fny
Copy link
Author

fny commented May 16, 2020

mv autossh-tunnel.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable autossh-tunnel.service
systemctl start autossh-tunnel.service

Make sure you have SSH keys on every server set up as needed.

To allow binding to all ports
ssh -R *:8080:localhost:80 -N user@middleman.dev

To allow binding to the server IPv4
ssh -R 0.0.0.0:8080:localhost:80 -N user@middleman.dev

To allow binding to the server IPv6
ssh -R "[::]:8080:localhost:80" -N user@middleman.dev

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