Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Autossh using systemd
1) ==== Autossh using systemd ====
Example from
https://gist.github.com/drmalex07/c0f9304deea566842490
2) =============
Install autossh
3) ==== /etc/default/secure-tunnel@yourjumpsshserver == change yourjumpsshserver to your ip or dnsname
TARGET=yourjumpsshserver
LOCAL_ADDR=0.0.0.0
LOCAL_PORT=22
REMOTE_PORT=54322
USERNAME=user
SSH_TARGET_PORT=443
4) ==== /etc/systemd/system/secure-tunnel@.service
[Unit]
Description=Setup a secure tunnel to %I
After=network.target
[Service]
Environment="LOCAL_ADDR=localhost"
EnvironmentFile=/etc/default/secure-tunnel@%i
###ExecStart=/usr/bin/ssh -NT -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -L ${LOCAL_ADDR}:${LOCAL_PORT}:localhost:${REMOTE_PORT} ${USERNAME}@${TARGET}
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -M 0 -o "ExitOnForwardFailure=yes" -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -NR ${REMOTE_PORT}:${LOCAL_ADDR}:${LOCAL_PORT} -p ${SSH_TARGET_PORT} ${USERNAME}@${TARGET}
# Restart every >2 seconds to avoid StartLimitInterval failure
RestartSec=5
Restart=always
[Install]
WantedBy=multi-user.target
6) ===== SSH key copy to yourjumpsshserver
As root
ssh-copy-id user@yourjumpsshserver -p 443
5) ============ systemctl
systemctl daemon-reload
systemctl status secure-tunnel@yourjumpsshserver
systemctl enable secure-tunnel@yourjumpsshserver
systemctl start secure-tunnel@yourjumpsshserver
systemctl stop secure-tunnel@yourjumpsshserver
==== Autossh using systemd ====
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.