Tools
Log in
English

Learn to codeSecurity check

SSH root login allowed

HighL01Linux servers

Stop direct SSH logins as root and sign in with a normal account plus sudo…

What is the risk

Every Linux server has a root account, so brute-force attacks try it first. One guessed password gives away the whole server.

Signing in as a normal user and using sudo also leaves a record of who did what.

How to check

Linux

sudo sshd -T | grep -i permitrootlogin

sshd -T prints the effective value after all config files. Fix it if it says yes.

How to fix

Debian / Ubuntu

sudo adduser newadmin
sudo usermod -aG sudo newadmin

Only if you have no normal sudo account yet. Pick your own name instead of newadmin.

RHEL / Rocky / Alma

sudo useradd -m newadmin
sudo passwd newadmin
sudo usermod -aG wheel newadmin

Linux

grep -n '^Include' /etc/ssh/sshd_config
echo 'PermitRootLogin no' | sudo tee /etc/ssh/sshd_config.d/10-appdogu.conf
sudo sshd -t

If the first line prints Include /etc/ssh/sshd_config.d/*.conf, add a separate file like this. The first value read wins, so a name starting with 10- is safe. Without Include, change the PermitRootLogin line in /etc/ssh/sshd_config to no. No output from sshd -t means the config is valid. If root must log in with a key only, use prohibit-password instead of no.

Debian / Ubuntu

sudo systemctl reload ssh

Keep your current session open and test a new login as the normal user first.

RHEL / Rocky / Alma

sudo systemctl reload sshd

How to prevent it

  • Use keys instead of passwords (L02).
  • Open the SSH port only to the IPs you connect from (L03).
  • Turn on brute-force protection (L09).

Check again after fixing

Linux

sudo sshd -T | grep -i permitrootlogin

It should say no.

Run the downloaded check again and make sure this item passes.

Security check home