summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2016-07-22 16:51:08 +0100
committerColin Watson <cjwatson@debian.org>2016-07-22 16:51:08 +0100
commitb66f1de1c94fcf912b3a1bc0cd73c3b73cdae8a1 (patch)
tree76bc05af9b826471b6c1af83ccf9ba572e9e05d3
parent4e620d6d9ebe0eda9ceddb28134d1fc465dd925c (diff)
Add a session cleanup script and a systemd unit file to trigger it, which serves to terminate SSH sessions cleanly if systemd doesn't do that itself, often because libpam-systemd is not installed (thanks, Vivek Das Mohapatra, Tom Hutter, and others; closes: #751636).
-rw-r--r--debian/changelog4
-rwxr-xr-xdebian/openssh-server.install2
-rwxr-xr-xdebian/rules2
-rwxr-xr-xdebian/systemd/ssh-session-cleanup11
-rw-r--r--debian/systemd/ssh-session-cleanup.service13
5 files changed, 32 insertions, 0 deletions
diff --git a/debian/changelog b/debian/changelog
index 1e1229042..b2e6d64de 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -14,6 +14,10 @@ openssh (1:7.2p2-6) UNRELEASED; urgency=medium
14 * Backport upstream patch to close ControlPersist background process 14 * Backport upstream patch to close ControlPersist background process
15 stderr when not in debug mode or when logging to a file or syslog 15 stderr when not in debug mode or when logging to a file or syslog
16 (closes: #714526). 16 (closes: #714526).
17 * Add a session cleanup script and a systemd unit file to trigger it,
18 which serves to terminate SSH sessions cleanly if systemd doesn't do
19 that itself, often because libpam-systemd is not installed (thanks,
20 Vivek Das Mohapatra, Tom Hutter, and others; closes: #751636).
17 21
18 -- Colin Watson <cjwatson@debian.org> Sat, 30 Apr 2016 11:29:20 +0100 22 -- Colin Watson <cjwatson@debian.org> Sat, 30 Apr 2016 11:29:20 +0100
19 23
diff --git a/debian/openssh-server.install b/debian/openssh-server.install
index 06e0c71b7..dabc440ab 100755
--- a/debian/openssh-server.install
+++ b/debian/openssh-server.install
@@ -10,6 +10,8 @@ debian/openssh-server.ufw.profile => etc/ufw/applications.d/openssh-server
10debian/systemd/ssh.socket lib/systemd/system 10debian/systemd/ssh.socket lib/systemd/system
11debian/systemd/ssh@.service lib/systemd/system 11debian/systemd/ssh@.service lib/systemd/system
12debian/systemd/sshd.conf usr/lib/tmpfiles.d 12debian/systemd/sshd.conf usr/lib/tmpfiles.d
13debian/systemd/ssh-session-cleanup usr/lib/openssh
14debian/systemd/ssh-session-cleanup.service lib/systemd/system
13 15
14# dh_apport would be neater, but at the time of writing it isn't in unstable 16# dh_apport would be neater, but at the time of writing it isn't in unstable
15# yet. 17# yet.
diff --git a/debian/rules b/debian/rules
index 3a8c86cdc..201fc204b 100755
--- a/debian/rules
+++ b/debian/rules
@@ -215,6 +215,8 @@ override_dh_installdocs:
215override_dh_systemd_enable: 215override_dh_systemd_enable:
216 dh_systemd_enable -popenssh-server --name ssh ssh.service 216 dh_systemd_enable -popenssh-server --name ssh ssh.service
217 dh_systemd_enable -popenssh-server --name ssh --no-enable ssh.socket 217 dh_systemd_enable -popenssh-server --name ssh --no-enable ssh.socket
218 dh_systemd_enable -popenssh-service --name ssh-session-cleanup \
219 ssh-session-cleanup.service
218 220
219override_dh_installinit: 221override_dh_installinit:
220 dh_installinit -R --name ssh 222 dh_installinit -R --name ssh
diff --git a/debian/systemd/ssh-session-cleanup b/debian/systemd/ssh-session-cleanup
new file mode 100755
index 000000000..f283cc967
--- /dev/null
+++ b/debian/systemd/ssh-session-cleanup
@@ -0,0 +1,11 @@
1#! /bin/sh
2
3ssh_session_pattern='sshd: \S.*@pts/[0-9]+'
4
5IFS="$IFS@"
6pgrep -a -f "$ssh_session_pattern" | while read pid daemon user pty; do
7 echo "Found ${daemon%:} session $pid on $pty; sending SIGTERM"
8 kill "$pid" || true
9done
10
11exit 0
diff --git a/debian/systemd/ssh-session-cleanup.service b/debian/systemd/ssh-session-cleanup.service
new file mode 100644
index 000000000..b86727227
--- /dev/null
+++ b/debian/systemd/ssh-session-cleanup.service
@@ -0,0 +1,13 @@
1[Unit]
2Description=OpenBSD Secure Shell session cleanup
3Wants=network.target
4After=network.target
5
6[Service]
7ExecStart=/bin/true
8ExecStop=/usr/lib/openssh/ssh-session-cleanup
9RemainAfterExit=yes
10Type=oneshot
11
12[Install]
13WantedBy=multi-user.target