From 0f3d969c76fc0d82380fdc3482d9df9ac5bdbc24 Mon Sep 17 00:00:00 2001 From: Filip Borum Poulsen Date: Sun, 8 Dec 2024 20:49:24 +0100 Subject: [PATCH] Added autossh --- auto-ssh-systemd-hosts.conf | 10 ++++++++++ autossh.service | 14 ++++++++++++++ install.sh | 3 +++ 3 files changed, 27 insertions(+) create mode 100644 auto-ssh-systemd-hosts.conf create mode 100644 autossh.service diff --git a/auto-ssh-systemd-hosts.conf b/auto-ssh-systemd-hosts.conf new file mode 100644 index 0000000..a77c69f --- /dev/null +++ b/auto-ssh-systemd-hosts.conf @@ -0,0 +1,10 @@ +Host bpfilip.dk + HostName bpfilip.dk + IdentityFile /home/pi/.ssh/id_rsa + User root + Port 2223 + LocalForward 22 127.0.0.1:2222 + RemoteForward 2222 127.0.0.1:22 + RemoteForward 10.0.1.25:8081 127.0.0.1:8080 + GatewayPorts yes + Compression yes diff --git a/autossh.service b/autossh.service new file mode 100644 index 0000000..bdc7a72 --- /dev/null +++ b/autossh.service @@ -0,0 +1,14 @@ +[Unit] +Description=Keeps an SSH tunnel to 'bpfilip.dk' open +After=network-online.target + +[Service] +ExecStart=/usr/bin/autossh -M 0 -N -q -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" bpfilip.dk +ExecStop=/usr/bin/killall -s KILL autossh +User=1000 +Group=1000 +Restart=always +RestartSec=3 + +[Install] +WantedBy=multi-user.target diff --git a/install.sh b/install.sh index 3547cce..939a3a2 100644 --- a/install.sh +++ b/install.sh @@ -23,8 +23,11 @@ git pull npm install sudo cp remote-relay.service /etc/systemd/system/remote-relay.service +sudo cp autossh.service /etc/systemd/system/autossh.service sudo systemctl daemon-reload sudo systemctl enable remote-relay.service sudo systemctl restart remote-relay.service +sudo systemctl enable autossh.service +sudo systemctl restart autossh.service popd