summaryrefslogtreecommitdiff
path: root/setup/port-forward/persistent-ssh.sh
diff options
context:
space:
mode:
authorhc <hc@email.ch>2025-06-25 19:40:43 +0800
committerhc <hc@email.ch>2025-06-25 19:40:43 +0800
commitccdde5f4424836fc8e9cc98c204510fed9612e70 (patch)
treedf1500f00b2f0b32b8729732454585c318b51110 /setup/port-forward/persistent-ssh.sh
parentd6eb567da3e6d2e64ebf22adf1fc6d21c47090f8 (diff)
merged setup and contaienrs
Diffstat (limited to 'setup/port-forward/persistent-ssh.sh')
-rwxr-xr-xsetup/port-forward/persistent-ssh.sh35
1 files changed, 35 insertions, 0 deletions
diff --git a/setup/port-forward/persistent-ssh.sh b/setup/port-forward/persistent-ssh.sh
new file mode 100755
index 0000000..36d14dd
--- /dev/null
+++ b/setup/port-forward/persistent-ssh.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+echo "selinux command is untested. copy paste systemd file if you want"
+echo "reboot afterwards(selinux unset, need reboot to take effect, or just do sudo setenforce 0 for temp unset)"
+echo "make sure /root/m exists"
+echo "remember to change the remote port or host if needed"
+
+# disable selinux
+sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
+
+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