SSH allows root to log in with a password
- Check
ssh.root_login- Severity
- high
- Runs
- on the server, in the daily run of the agent
- Looks at
- PermitRootLogin is yes (prohibit-password and no pass)
What the check looks at
The agent reads the effective sshd configuration (sshd -T, which includes all files in
/etc/ssh/sshd_config.d/) and looks at PermitRootLogin. The check fails when the value is yes and SSH
accepts passwords; with yes and passwords off, it warns. The values prohibit-password (root only with a
key, the OpenSSH default), forced-commands-only and no pass.
Why it matters
root exists on every Linux server, so an attacker only has to guess the password. Bots try root with common
and leaked passwords on every public SSH server, all day. With PermitRootLogin yes and password
authentication on, a weak or reused root password is enough to take over the server, with nothing in the logs
that tells you which person logged in.
How to fix it
Create a user with sudo rights and test that you can log in with it and run sudo (see
key-only login). Then add a drop-in file. The file name starts with a low number
because sshd keeps the first value it reads. On RHEL 8, Rocky Linux 8 and AlmaLinux 8, sshd_config does not read /etc/ssh/sshd_config.d/; add the
Include line at the top of it first, as the SSH hardening guide shows.
echo 'PermitRootLogin no' | sudo tee /etc/ssh/sshd_config.d/10-root-login.conf
sudo sshd -t
If a backup or deployment system logs in as root with a key, use prohibit-password instead of no.
Then reload sshd. Open sessions stay connected.
Debian and Ubuntu
sudo systemctl reload ssh
RHEL, Rocky Linux and AlmaLinux
sudo systemctl reload sshd
The RHEL installer has an option to allow root login with a password; on RHEL 9 and later it writes
/etc/ssh/sshd_config.d/01-permitrootlogin.conf. Delete that file or change its value, because 01- is read
before 10-. On RHEL 8 the shipped sshd_config itself has PermitRootLogin yes; the 10- file read
through the Include line at the top wins over it.
Alpine
sudo rc-service sshd reload
If /etc/ssh/sshd_config on your Alpine server does not include sshd_config.d, set PermitRootLogin no
in /etc/ssh/sshd_config itself.
How to check the fix
sudo sshd -T | grep '^permitrootlogin'
The output must be permitrootlogin no, or with keys allowed for root, permitrootlogin prohibit-password
(depending on the version, sshd -T prints the older name without-password: Debian 13 with OpenSSH 10.0
does, Alpine 3.24 with OpenSSH 10.3 does not). From another machine, ssh root@<server> must fail.
When a warning is fine
There is no good reason for root password logins over SSH. On a server that is only reachable through a VPN or a private network, the risk is lower, but a sudo user costs nothing.
Sources
- sshd_config(5) — values of
PermitRootLogin, defaultprohibit-password, first obtained value wins - Red Hat Ceph Storage 8: enabling SSH login as root on RHEL 9 — the drop-in file
01-permitrootlogin.conf