Why do people disable root login over SSH?
Because root is the one account every attacker knows exists. Bots spend most of their guesses on it, and if they ever succeed they have the whole machine. Logging in as a named user and raising privileges with sudo also leaves an audit trail of who did what, which matters as soon as more than one person administers the box. The trade-off is a little extra typing, and on a team server that is a good deal.
What do the PermitRootLogin values do?
| Value | Root may log in with | Typical use |
|---|---|---|
yes | Password or key | First boot only; risky long term |
prohibit-password | Keys only | Single admin who wants root access by key |
forced-commands-only | Keys with a fixed command= | Backup pulls, automation |
no | Nothing | Teams; all admin work through sudo |
Upstream OpenSSH defaults to prohibit-password, and without-password is an older spelling of the same value. Because our machines arrive with a root password shown in the panel, the first login works with that password; tightening the setting is your call once your own access is in place.
How do I set up a sudo user first?
Never remove root access before another admin path works. On Ubuntu and Debian:
adduser --gecos "" mara usermod -aG sudo mara install -d -m 700 -o mara -g mara /home/mara/.ssh install -o mara -g mara -m 0600 /root/.ssh/authorized_keys /home/mara/.ssh/
On Rocky Linux, AlmaLinux and CentOS Stream the admin group is wheel, and the account is created with useradd -m mara plus passwd mara. On FreeBSD, use pw groupmod wheel -m mara and install the sudo or doas package. If root has no authorized_keys yet, paste your public key into the new file instead of copying it.
Now, from a second terminal, log in as the new user and run sudo -v. Only continue when it asks for the user's password and succeeds.
How do I change the root login setting?
Use a drop-in so the change survives package updates. sshd uses the first value it reads for most options, and drop-ins are read before the rest of the main file, so a drop-in wins over a line further down:
echo 'PermitRootLogin no' > /etc/ssh/sshd_config.d/20-root.conf sshd -t && systemctl reload ssh # use sshd as the unit name on Enterprise Linux sshd -T | grep -i permitrootlogin
The last command prints the effective value. If it still shows yes, another drop-in with a lower number sets it first; grep -ri permitrootlogin /etc/ssh/ finds it.
When is key-only root login acceptable?
When one person manages the machine, keys are protected with a passphrase, and convenience matters. prohibit-password blocks all password guessing against root while letting your key in. Many single-purpose boxes, such as a game server or a backup target owned by one admin, run fine that way. Add a source restriction in authorized_keys to narrow it further:
from="198.51.100.0/24" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGx... mara@laptop
How do backups log in as root safely?
With forced-commands-only and a dedicated key that can run exactly one command. Prefix the key in root's authorized_keys with command="/usr/local/sbin/backup-stream",restrict. Whatever the client asks for, the server runs only that script, with no shell, no port forwarding and no terminal. A stolen backup key then exposes only the backup stream.
What if I disable root and lose the sudo user?
Without an out-of-band console in the offer, a machine where no account can log in has one way back: a reinstall from the panel, which wipes the drives. That is why the order above matters, and why it pays to keep a second admin key, stored safely offline, in the sudo user's authorized_keys.
Does disabling root login stop root from working at all?
No. Root still exists and runs services; only direct SSH logins are affected. sudo -i gives you a root shell when you need one, and console logins, if you ever have one on a self-hosted system, are controlled separately.
Keep Reading
Harden SSH on Linux
A practical hardening list for sshd on a fresh dedicated box: keys, users, rate limits, firewall scope and an outside audit.
OpenSet up passwordless SSH
Go from a root password to key-only access in one careful pass: user, key, agent, then switch off every password method on the server.
OpenFix "Permission denied (publickey)"
Trace a publickey refusal to its real cause: wrong key, wrong user, loose file modes, SELinux labels or an old RSA signature.
OpenUbuntu
Ubuntu 24.04 or 22.04 LTS on a whole machine: the default pick when you want the biggest pool of packages and how-tos.
OpenFAQ
Quick Answers
Yes. The panel shows a root password so you can log in at once. Tighten the setting once your own user and key work.
prohibit-password lets root log in with a key but never a password; no blocks every root login over SSH.
A drop-in file read earlier may set it first. Run sshd -T to see the effective value and grep /etc/ssh for other lines.
sudo on Ubuntu and Debian, wheel on Rocky Linux, AlmaLinux, CentOS Stream and FreeBSD.
Yes. Change the drop-in value and reload sshd from a sudo session.