summaryrefslogtreecommitdiff
path: root/port-forward/persistent-ssh.sh
diff options
context:
space:
mode:
authorhc <hc@email.ch>2024-11-23 17:35:46 +0800
committerhc <hc@email.ch>2024-11-23 17:35:46 +0800
commitba9539a4f49d722063e5a322133c89affd6a9fb7 (patch)
tree5f72a881ad2affbf03186976b59c6df1ffb1d51f /port-forward/persistent-ssh.sh
parentab5d9a6966b6b8fdd6ce9821b86ab0f3b74cc6a5 (diff)
persistentssh
Diffstat (limited to 'port-forward/persistent-ssh.sh')
-rwxr-xr-xport-forward/persistent-ssh.sh27
1 files changed, 27 insertions, 0 deletions
diff --git a/port-forward/persistent-ssh.sh b/port-forward/persistent-ssh.sh
new file mode 100755
index 0000000..086bfc6
--- /dev/null
+++ b/port-forward/persistent-ssh.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+sudo cat << 'EOF' > /etc/systemd/system/ssh-tunnel.service
+[Unit]
+Description=Persistent SSH Tunnel
+After=network.target
+StartLimitIntervalSec=0
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/ssh \
+ -i /root/m \
+ -o "ExitOnForwardFailure=yes" \
+ -o "StrictHostKeyChecking=no" \
+ -N -R 24:localhost:22 root@p.0nom.ch
+Restart=always
+RestartSec=10
+RemainAfterExit=no
+KillMode=process
+
+[Install]
+WantedBy=multi-user.target
+EOF
+
+sudo chmod 600 /root/m
+sudo systemctl daemon-reload
+sudo systemctl enable --now ssh-tunnel