summaryrefslogtreecommitdiff
path: root/port-forward/persistent-ssh.sh
blob: 30218253bb25878d37bc1f9118a51d1fa3fef1c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash

echo "make sure /root/m exists"
echo "remember to change the remote port or host if needed"

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