summaryrefslogtreecommitdiff
path: root/.config/systemd/user
diff options
context:
space:
mode:
authorMehdi Sadeghi <mehdi@mehdix.org>2021-04-25 19:05:29 +0200
committerMehdi Sadeghi <mehdi@mehdix.org>2021-04-25 19:05:29 +0200
commitf165be75f782029ca91ad023267a89900b86d9df (patch)
tree1193b8ea2df2b072a5a36475d5dcc204590ff62f /.config/systemd/user
parentecd3c4050cccfe8d4b97276bc01cae86971f2574 (diff)
Add ssh-tunnel template.
Diffstat (limited to '.config/systemd/user')
-rw-r--r--.config/systemd/user/secure-tunnel@.service23
1 files changed, 23 insertions, 0 deletions
diff --git a/.config/systemd/user/secure-tunnel@.service b/.config/systemd/user/secure-tunnel@.service
new file mode 100644
index 0000000..f97f3ba
--- /dev/null
+++ b/.config/systemd/user/secure-tunnel@.service
@@ -0,0 +1,23 @@
+[Unit]
+Description=Setup a secure tunnel to %I
+After=network.target
+
+#
+# Add secure-tunnel@<name> file with necessary env vars:
+#
+#USER= # user to run the unit with
+#REMOTE_PORT= # some port on the remote machine to forward to
+#REMOTE_USER= # user on the remote machine
+#TARGET_PORT= # ssh port of the target machine usually 22
+#
+[Service]
+User="${USER}"
+EnvironmentFile=%h/.config/systemd/user/secure-tunnel@%i
+ExecStart=/usr/bin/ssh -NT -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -R ${REMOTE_PORT}:localhost:${TARGET_PORT} ${TARGET} -l ${REMOTE_USER}
+
+# Restart every >2 seconds to avoid StartLimitInterval failure
+RestartSec=5
+Restart=always
+
+[Install]
+WantedBy=multi-user.target