Skip to content

Commit 50743f8

Browse files
committed
disable systemd socket activation
Signed-off-by: Sebastian Gumprich <[email protected]>
1 parent 2658023 commit 50743f8

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

roles/ssh_hardening/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ This role uses the default port 22 or the port configured in the inventory to co
3737

3838
If idempotency is important, please consider using role [`ssh-hardening-fallback`](https://github.com/nununo/ansible-ssh-hardening-fallback), which is a wrapper around this role that falls back to port 22 if the configured port is unreachable.
3939

40+
## Disabling systemd-socket activation on Debian and Ubuntu systems
41+
42+
Since Debian 12 and Ubuntu 22.04 the ssh-daemon is not running by default anymore but is instead activated via systemd.
43+
We revert this change to its traditional behaviour.
44+
For more information, see [this issue](https://github.com/dev-sec/ansible-collection-hardening/issues/763).
45+
4046
<!-- BEGIN_ANSIBLE_DOCS -->
4147

4248
## Supported Operating Systems
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
- name: Remove systemd-socket file
3+
ansible.builtin.file:
4+
path: /etc/systemd/system/ssh.service.d/00-socket.conf
5+
state: absent
6+
7+
- name: Enable normal sshd start
8+
ansible.builtin.systemd:
9+
name: ssh.service
10+
state: started
11+
enabled: true
12+
13+
- name: Disable systemd-socket activation
14+
ansible.builtin.systemd:
15+
name: ssh.socket
16+
state: stopped
17+
enabled: false

roles/ssh_hardening/tasks/hardening.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232
ansible.builtin.set_fact:
3333
sshd_version: "{{ sshd_version_raw.stderr | regex_replace('.*_([0-9]*.[0-9]).*', '\\1') }}"
3434

35+
# see https://github.com/dev-sec/ansible-collection-hardening/issues/763
36+
- name: Change Debian/Ubuntu systems so ssh starts traditionally instead of socket-activated
37+
ansible.builtin.include_tasks: disable-systemd-socket.yml
38+
when:
39+
- ssh_server_hardening | bool
40+
- ssh_server_enabled | bool
41+
- (ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_major_version is version('22.04', '>=')) or
42+
(ansible_facts.os_family == 'Debian' and ansible_facts.distribution_major_version is version('12', '>='))
43+
3544
- name: Set default for ssh_host_key_files if not supplied
3645
ansible.builtin.include_tasks: crypto_hostkeys.yml
3746
when:

0 commit comments

Comments
 (0)