You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Task "Ensure ssh service is started after disabling socket activation" fails #941
I run into this as well on my test ubuntu 24.04.4 install. To fix, I have to go in and delete the socket want for ssh.service. I'm also on 13.5 and am only using the following ssh_ var: ssh_permit_root_login: prohibit-password
@WhatsCS this is interesting, we have one task that deletes all remaining files before restarting ssh.service. Can you check the output of the task Remove ssh service systemd-socket file on your test machine? Does it include the socket want file for you?
Possible stupid question: Should this be ran locally? The task order is to shut down ssh for the socket activation, then deletes the want, then restarts. Unless I've misconfigured ansible, wouldn't that logically kill the ssh connection?
Should this be ran locally? The task order is to shut down ssh for the socket activation, then deletes the want, then restarts. Unless I've misconfigured ansible, wouldn't that logically kill the ssh connection?
The role can be applied locally and remote via SSH. A running SSH connection has a forked server process and stopping the systemd service only makes new connections impossible.
Okay, so my ssh connection is definitely not surviving then for one reason or another. Thus causing the deletion of files to not trigger. I'll try locally as well to triple check.
Works when ran locally, so I suspect either I'm not facing the same issue (sorry!) or they are seeing the same but it's propagating as a different error for one reason or another?
I needed controlpath configurations setup so this was an issue of ansible just not being configured for persistent ssh connections. I suspect similar for OP but they've unfortunately not provided prior task info so no way to know if they're hitting something similar.
Apparently my Ubuntu 24.04 image had ssh.socket configured with RequiredBy=ssh.service in its [Install] section which created a /etc/systemd/system/ssh.service.requires/ssh.socket symlink. That's what added Requires=ssh.socket to ssh.service at runtime. ssh-hardening removes the symlink but systemctl mask doesn't trigger a daemon_reload. So systemd's in-memory state still sees the Requires dependency and the fail starts. So I had to remove the symlink + daemon_reload in as a "pre_task":
Note: This is just a workaround for Ubuntu; I don't think it's a good solution, but I hope it can serve as a basis for a proper fix for the devsec.hardening.ssh_hardening role.
Log showing the error when running the Enable and start classic ssh.service task:
TASK [Gathering Facts] *******************************************************************************************************************************************************************
ok: [host.example.org]
TASK [devsec.hardening.ssh_hardening : Validating arguments against arg spec 'main' - The main entry point for the ssh hardening role.] **************************************************
ok: [host.example.org]
TASK [devsec.hardening.ssh_hardening : Include hardening tasks] **************************************************************************************************************************
included: /Users/username/.ansible/collections/ansible_collections/devsec/hardening/roles/ssh_hardening/tasks/hardening.yml for host.example.org
TASK [devsec.hardening.ssh_hardening : Fetch OS dependent variables] *********************************************************************************************************************
ok: [host.example.org] => (item=/Users/username/.ansible/collections/ansible_collections/devsec/hardening/roles/ssh_hardening/vars/Debian.yml)
TASK [devsec.hardening.ssh_hardening : Set OS dependent variables, if not already defined by user] ***************************************************************************************
ok: [host.example.org] => (item={'key': 'ssh_pkgs', 'value': ['openssh-server', 'openssh-client']})
ok: [host.example.org] => (item={'key': 'sshd_path', 'value': '/usr/sbin/sshd'})
ok: [host.example.org] => (item={'key': 'ssh_host_keys_dir', 'value': '/etc/ssh'})
ok: [host.example.org] => (item={'key': 'sshd_service_name', 'value': 'ssh'})
ok: [host.example.org] => (item={'key': 'ssh_owner', 'value': 'root'})
ok: [host.example.org] => (item={'key': 'ssh_group', 'value': 'root'})
ok: [host.example.org] => (item={'key': 'ssh_host_keys_owner', 'value': 'root'})
ok: [host.example.org] => (item={'key': 'ssh_host_keys_group', 'value': 'root'})
ok: [host.example.org] => (item={'key': 'ssh_host_keys_mode', 'value': '0600'})
ok: [host.example.org] => (item={'key': 'ssh_selinux_packages', 'value': ['policycoreutils-python-utils', 'checkpolicy']})
ok: [host.example.org] => (item={'key': 'ssh_kerberos_support', 'value': True})
ok: [host.example.org] => (item={'key': 'ssh_pam_support', 'value': True})
ok: [host.example.org] => (item={'key': 'sshd_moduli_file', 'value': '/etc/ssh/moduli'})
ok: [host.example.org] => (item={'key': 'sshd_disable_crypto_policy', 'value': False})
TASK [devsec.hardening.ssh_hardening : Install openssh package and configure the service] ************************************************************************************************
included: /Users/username/.ansible/collections/ansible_collections/devsec/hardening/roles/ssh_hardening/tasks/install.yml for host.example.org
TASK [devsec.hardening.ssh_hardening : Install openssh package(s)] ***********************************************************************************************************************
ok: [host.example.org] => (item=openssh-server)
ok: [host.example.org] => (item=openssh-client)
TASK [devsec.hardening.ssh_hardening : Change Debian/Ubuntu systems so ssh starts traditionally instead of socket-activated] *************************************************************
included: /Users/username/.ansible/collections/ansible_collections/devsec/hardening/roles/ssh_hardening/tasks/disable-systemd-socket.yml for host.example.org
TASK [devsec.hardening.ssh_hardening : Disable systemd-socket activation] ****************************************************************************************************************
changed: [host.example.org]
TASK [devsec.hardening.ssh_hardening : Remove ssh service systemd-socket file] ***********************************************************************************************************
ok: [host.example.org] => (item=/etc/systemd/system/ssh.service.d/00-socket.conf)
changed: [host.example.org] => (item=/etc/systemd/system/ssh.service.requires/ssh.socket)
changed: [host.example.org] => (item=/etc/systemd/system/sockets.target.wants/ssh.socket)
TASK [devsec.hardening.ssh_hardening : Ensure ssh service is started after disabling socket activation] **********************************************************************************
[ERROR]: Task failed: Module failed: Unable to start service ssh: Failed to start ssh.service: Unit ssh.socket is masked.
Origin: /Users/username/.ansible/collections/ansible_collections/devsec/hardening/roles/ssh_hardening/tasks/disable-systemd-socket.yml:18:3
16 - /etc/systemd/system/sockets.target.wants/ssh.socket
17
18 - name: Ensure ssh service is started after disabling socket activation
^ column 3
fatal: [host.example.org]: FAILED! => {"changed": false, "msg": "Unable to start service ssh: Failed to start ssh.service: Unit ssh.socket is masked.\n"}
PLAY RECAP *******************************************************************************************************************************************************************************
host.example.org : ok=75 changed=25 unreachable=0 failed=1 skipped=2 rescued=0 ignored=0
Disable systemd-socket activation
↓
Remove ssh service systemd-socket file
↓
Ensure ssh service is started after disabling socket activation
I think it should be
Remove ssh service systemd-socket file
↓
systemctl daemon-reload
↓
Disable systemd-socket activation
↓
Ensure ssh service is started after disabling socket activation
Also affects Ubuntu 26.04.1 (resolute) with devsec.hardening 11.0.0 (openssh-server 1:10.2p1-2ubuntu3.8, ansible-core 2.21.5). After the failed task, ssh.service still has Requires=ssh.socket and nothing listens on port 22 anymore, so a remote host is locked out except for the session that's still open.
I tested #986 on the same fresh setup: it fixes this. sshd runs as a service, the socket is masked, logins work, a second run is clean, and SSH survives a restart.
Until it's released, a workaround before the role is to remove /etc/systemd/system/ssh.service.requires/ssh.socket, run systemctl daemon-reload, then mask ssh.socket and start ssh.service.
Activity
schurzi commentedon Mar 30, 2026
@pbol-samedi Can you please add some more information:
pbol-samedi commentedon Mar 31, 2026
Hi @schurzi, thanks for creating the new issue.
ssh_variables (some might still be from the dev-sec role):WhatsCS commentedon Apr 12, 2026
I run into this as well on my test ubuntu 24.04.4 install. To fix, I have to go in and delete the socket want for ssh.service. I'm also on 13.5 and am only using the following
ssh_var:ssh_permit_root_login: prohibit-passwordschurzi commentedon Apr 12, 2026
@WhatsCS this is interesting, we have one task that deletes all remaining files before restarting
ssh.service. Can you check the output of the taskRemove ssh service systemd-socket fileon your test machine? Does it include the socket want file for you?WhatsCS commentedon Apr 12, 2026
Possible stupid question: Should this be ran locally? The task order is to shut down ssh for the socket activation, then deletes the want, then restarts. Unless I've misconfigured ansible, wouldn't that logically kill the ssh connection?
schurzi commentedon Apr 12, 2026
The role can be applied locally and remote via SSH. A running SSH connection has a forked server process and stopping the systemd service only makes new connections impossible.
WhatsCS commentedon Apr 12, 2026
Okay, so my ssh connection is definitely not surviving then for one reason or another. Thus causing the deletion of files to not trigger. I'll try locally as well to triple check.
WhatsCS commentedon Apr 12, 2026
Works when ran locally, so I suspect either I'm not facing the same issue (sorry!) or they are seeing the same but it's propagating as a different error for one reason or another?
WhatsCS commentedon Apr 12, 2026
I needed controlpath configurations setup so this was an issue of ansible just not being configured for persistent ssh connections. I suspect similar for OP but they've unfortunately not provided prior task info so no way to know if they're hitting something similar.
pbol-samedi commentedon May 8, 2026
Apparently my Ubuntu 24.04 image had ssh.socket configured with RequiredBy=ssh.service in its [Install] section which created a /etc/systemd/system/ssh.service.requires/ssh.socket symlink. That's what added Requires=ssh.socket to ssh.service at runtime. ssh-hardening removes the symlink but systemctl mask doesn't trigger a daemon_reload. So systemd's in-memory state still sees the Requires dependency and the fail starts. So I had to remove the symlink + daemon_reload in as a "pre_task":
xorcare commentedon Jun 18, 2026
Hello, I ran into a similar problem on Ubuntu 24.04:
This was fixed by adding
Reload systemd units; see below for more details:Note: This is just a workaround for Ubuntu; I don't think it's a good solution, but I hope it can serve as a basis for a proper fix for the
devsec.hardening.ssh_hardeningrole.Log showing the error when running the
Enable and start classic ssh.servicetask:eyebrowkang commentedon Aug 10, 2026
I think it's caused by this commit: d748703
NOW it's
I think it should be
jdreesen commentedon Oct 20, 2026
Also affects Ubuntu 26.04.1 (resolute) with devsec.hardening 11.0.0 (openssh-server
1:10.2p1-2ubuntu3.8, ansible-core 2.21.5). After the failed task,ssh.servicestill hasRequires=ssh.socketand nothing listens on port 22 anymore, so a remote host is locked out except for the session that's still open.I tested #986 on the same fresh setup: it fixes this. sshd runs as a service, the socket is masked, logins work, a second run is clean, and SSH survives a restart.
Until it's released, a workaround before the role is to remove
/etc/systemd/system/ssh.service.requires/ssh.socket, runsystemctl daemon-reload, then maskssh.socketand startssh.service.