summaryrefslogtreecommitdiff
path: root/port-forward/persistent-ssh.sh
diff options
context:
space:
mode:
Diffstat (limited to 'port-forward/persistent-ssh.sh')
-rwxr-xr-xport-forward/persistent-ssh.sh35
1 files changed, 35 insertions, 0 deletions
diff --git a/port-forward/persistent-ssh.sh b/port-forward/persistent-ssh.sh
new file mode 100755
index 0000000..36d14dd
--- /dev/null
+++ b/port-forward/persistent-ssh.sh
@@ -0,0 +1,35 @@
1#!/bin/bash
2
3echo "selinux command is untested. copy paste systemd file if you want"
4echo "reboot afterwards(selinux unset, need reboot to take effect, or just do sudo setenforce 0 for temp unset)"
5echo "make sure /root/m exists"
6echo "remember to change the remote port or host if needed"
7
8# disable selinux
9sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
10
11sudo cat << 'EOF' > /etc/systemd/system/ssh-tunnel.service
12[Unit]
13Description=Persistent SSH Tunnel
14After=network.target
15StartLimitIntervalSec=0
16
17[Service]
18Type=simple
19ExecStart=/usr/bin/ssh \
20 -i /root/m \
21 -o "ExitOnForwardFailure=yes" \
22 -o "StrictHostKeyChecking=no" \
23 -N -R 24:localhost:22 root@p.0nom.ch
24Restart=always
25RestartSec=10
26RemainAfterExit=no
27KillMode=process
28
29[Install]
30WantedBy=multi-user.target
31EOF
32
33sudo chmod 600 /root/m
34sudo systemctl daemon-reload
35sudo systemctl enable --now ssh-tunnel