Last active
July 13, 2025 08:03
-
-
Save MParvin/7f2ee9423c95f3fb79356f044ea13738 to your computer and use it in GitHub Desktop.
SSH tunnel systemd service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=SSH Tunnel | |
After=network.target | |
[Service] | |
Type=forking | |
EnvironmentFile=/etc/default/ssh_tunnel | |
ExecStart=/usr/bin/ssh -fN -D "$SOCKS_PORT" -i "$SSH_KEY" -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes "$USER"@"$SSH_SERVER" | |
ExecStartPost=/bin/bash -c "/usr/bin/curl --silent --fail --max-time 10 -x socks5h://localhost:$SOCKS_PORT http://ifconfig.me/ip || /bin/kill -9 -- $MAINPID" | |
ExecReload=/bin/kill -1 -- $MAINPID | |
ExecStop=/bin/kill -9 -- $MAINPID | |
Restart=always | |
RestartSec=5 | |
KillMode=process | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Content of /etc/default/ssh_tunnel