From b519b48e8366a9f5e6ea591ad2e6c20a1461ed25 Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Thu, 25 Nov 2021 10:00:49 +0000 Subject: [PATCH] ssh: Add systemd ssh@ unit for persistent master connections These rely on SSH configuring ControlMaster and ControlSocket for the host so the connection can be reused. Signed-off-by: Joe Groocock --- ssh/askpass | 13 +++++++++++++ systemd/user/ssh@.service | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 ssh/askpass create mode 100644 systemd/user/ssh@.service diff --git a/ssh/askpass b/ssh/askpass new file mode 100755 index 0000000..45fb64b --- /dev/null +++ b/ssh/askpass @@ -0,0 +1,13 @@ +#!/bin/sh -e + +if [ -z "$SSH_HOST" ]; then + >&2 echo 'Missing SSH_HOST variable' + exit 1 +fi + +case "$SSH_HOST" in + *) + echo 'Unknown SSH host' + exit 1 + ;; +esac diff --git a/systemd/user/ssh@.service b/systemd/user/ssh@.service new file mode 100644 index 0000000..236e436 --- /dev/null +++ b/systemd/user/ssh@.service @@ -0,0 +1,13 @@ +[Unit] +Description=SSH persistent connection to %i + +[Service] +Type=forking +Slice=ssh.slice +Environment=SSH_ASKPASS=%E/ssh/askpass +Environment=SSH_HOST=%i +ExecStart=/usr/bin/ssh -fNT %i +Restart=on-failure + +[Install] +WantedBy=ssh.target