diff options
author | Colin Watson <cjwatson@debian.org> | 2016-07-22 16:51:08 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2016-07-22 16:51:08 +0100 |
commit | b66f1de1c94fcf912b3a1bc0cd73c3b73cdae8a1 (patch) | |
tree | 76bc05af9b826471b6c1af83ccf9ba572e9e05d3 | |
parent | 4e620d6d9ebe0eda9ceddb28134d1fc465dd925c (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/changelog | 4 | ||||
-rwxr-xr-x | debian/openssh-server.install | 2 | ||||
-rwxr-xr-x | debian/rules | 2 | ||||
-rwxr-xr-x | debian/systemd/ssh-session-cleanup | 11 | ||||
-rw-r--r-- | debian/systemd/ssh-session-cleanup.service | 13 |
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 | |||
10 | debian/systemd/ssh.socket lib/systemd/system | 10 | debian/systemd/ssh.socket lib/systemd/system |
11 | debian/systemd/ssh@.service lib/systemd/system | 11 | debian/systemd/ssh@.service lib/systemd/system |
12 | debian/systemd/sshd.conf usr/lib/tmpfiles.d | 12 | debian/systemd/sshd.conf usr/lib/tmpfiles.d |
13 | debian/systemd/ssh-session-cleanup usr/lib/openssh | ||
14 | debian/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: | |||
215 | override_dh_systemd_enable: | 215 | override_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 | ||
219 | override_dh_installinit: | 221 | override_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 | |||
3 | ssh_session_pattern='sshd: \S.*@pts/[0-9]+' | ||
4 | |||
5 | IFS="$IFS@" | ||
6 | pgrep -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 | ||
9 | done | ||
10 | |||
11 | exit 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] | ||
2 | Description=OpenBSD Secure Shell session cleanup | ||
3 | Wants=network.target | ||
4 | After=network.target | ||
5 | |||
6 | [Service] | ||
7 | ExecStart=/bin/true | ||
8 | ExecStop=/usr/lib/openssh/ssh-session-cleanup | ||
9 | RemainAfterExit=yes | ||
10 | Type=oneshot | ||
11 | |||
12 | [Install] | ||
13 | WantedBy=multi-user.target | ||