Skip to content

Instantly share code, notes, and snippets.

@Tugzrida
Created October 16, 2022 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tugzrida/cbe56f17a373254f28bfc6541af21de3 to your computer and use it in GitHub Desktop.
Save Tugzrida/cbe56f17a373254f28bfc6541af21de3 to your computer and use it in GitHub Desktop.
Persistent SSH connection for remote access
command="echo 'Dialout only'",restrict,port-forwarding,permitlisten="localhost:jumpbox_port",permitopen="[100::]:1" ssh_key
[Unit]
Description=Remote access to local ssh daemon
After=network.target
[Service]
Environment="AUTOSSH_GATETIME=0"
Environment="AUTOSSH_PORT=0"
ExecStart=/usr/bin/autossh -o ServerAliveInterval=60 -o ServerAliveCountMax=2 -i /path/to/key -o ExitOnForwardFailure=yes -o VerifyHostKeyDNS=yes -N -R jumpbox_port:127.0.0.1:22 user@jumpbox
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Host remote_device
User user
ProxyCommand ssh -W 127.0.0.1:jumpbox_port jumpbox
ClientAliveInterval 60
ClientAliveCountMax 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment