Log inSign up

Turn off root logins without losing admin access

Create a sudo user, copy your SSH key to it and prove that sudo -v works, then add PermitRootLogin no in a drop-in such as /etc/ssh/sshd_config.d/00-root.conf and restart sshd. Use prohibit-password instead if a tool still needs root with a key, and keep a timed undo running until a fresh login as the new user succeeds.

Topic: Security · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

Why stop logging in as root?

Every bot on the internet tries the user name root, because it exists on every Linux system and has full power. Turning off root over SSH means attackers also have to guess a user name, and it gives you a clean audit trail: actions run through sudo are logged with the real user who ran them. A new BitcoinVPS server starts with root access, using the password shown on the Overview tab of the instance page and any SSH keys you picked on the Deploy page. That makes the first login easy; this guide turns it into a safer daily setup.

How do I prepare a sudo user first?

Create the user, give it admin rights and copy root's authorized keys, so the same key opens both accounts:

adduser deploy
usermod -aG sudo deploy
mkdir -p /home/deploy/.ssh
cp /root/.ssh/authorized_keys /home/deploy/.ssh/
chown -R deploy:deploy /home/deploy/.ssh
chmod 700 /home/deploy/.ssh && chmod 600 /home/deploy/.ssh/authorized_keys

On Rocky Linux and AlmaLinux use useradd -m deploy, passwd deploy and usermod -aG wheel deploy instead of the first two lines, then run restorecon -Rv /home/deploy/.ssh. The sudo user guide covers the details.

How do I prove the new account works?

From your computer, in a new terminal, log in as the new user and check sudo:

ssh deploy@198.51.100.24
sudo -v
sudo whoami

The last command must print root. Do not continue until it does. If you skip this step and the user cannot use sudo, disabling root would leave you with a server you can reach but not manage. The only way out then is a reinstall from the Settings tab, which erases the disk.

How do I see what sshd allows today?

Read the effective value rather than the main file, because drop-in files can override it:

sudo sshd -T | grep -i permitrootlogin
sudo grep -ri permitrootlogin /etc/ssh/sshd_config /etc/ssh/sshd_config.d/

Debian and Ubuntu default to prohibit-password, which already refuses root passwords but accepts root keys. Some Rocky and AlmaLinux images ship a file such as 01-permitrootlogin.conf that sets yes. sshd uses the first value it finds, and drop-ins are read in name order before the rest of the main file, so a file named 00-root.conf wins over all of them.

How do I disable root login with a safety net?

Arm an automatic undo, write the setting, check it, and restart:

sudo systemd-run --on-active=10min --unit=root-undo /bin/sh -c "rm -f /etc/ssh/sshd_config.d/00-root.conf; systemctl restart sshd || systemctl restart ssh"
echo "PermitRootLogin no" | sudo tee /etc/ssh/sshd_config.d/00-root.conf
sudo sshd -t && sudo sshd -T | grep -i permitrootlogin

Then restart the daemon: sudo systemctl restart ssh on Ubuntu and Debian, sudo systemctl restart sshd on Rocky and AlmaLinux. Open two new terminals. In the first, ssh deploy@198.51.100.24 must work. In the second, ssh root@198.51.100.24 must fail with Permission denied. When both results match, cancel the undo with sudo systemctl stop root-undo.timer.

Can I allow root only from one address or with a key?

Yes. If a backup system or a configuration tool must log in as root, use prohibit-password so only keys work, and combine it with a Match block that limits the source. Put the block at the very end of the main /etc/ssh/sshd_config, since every line after a Match belongs to it:

Match Address 203.0.113.7,2001:db8:4f2a::7
    PermitRootLogin prohibit-password

Keep PermitRootLogin no in the drop-in for everyone else. For a single automated command, a key with a forced command is even tighter: set PermitRootLogin forced-commands-only in the Match block and prefix the key line in /root/.ssh/authorized_keys with command="/usr/local/sbin/backup-run",restrict. Test again with sudo sshd -t and the same two-terminal check.

Should I also lock the root password and limit su?

Locking the root password stops password based su and console style logins, while sudo keeps working:

sudo passwd -l root
sudo passwd -S root

The status shows L or LK for locked. Ubuntu locks it out of the box. To make sure only admins can even try su, enable the wheel rule in /etc/pam.d/su by removing the # before auth required pam_wheel.so use_uid (on Debian and Ubuntu also create the group with sudo groupadd -f wheel and add your admin users to it). Test with su - from a non admin account, which should now be refused. After a reinstall the server starts again with a fresh root password on the Overview tab, and you repeat these steps.

How do I check that bots now fail?

Watch the journal for refused root attempts:

sudo journalctl -u ssh -u sshd --since today | grep -i "root" | tail

Lines such as ROOT LOGIN REFUSED or Failed publickey for root confirm the rule. Add fail2ban to ban those addresses and login alerts so you hear about every successful login.

Questions about Disable or restrict root login

Is prohibit-password good enough?

It blocks root password guessing completely, which removes most of the risk. Setting no also removes root as a target for a stolen key and forces every admin action through sudo, which is easier to audit.

Will the root password on the Overview tab still work?

Not over SSH once root login is disabled, and not at all after passwd -l root. Use your sudo user instead.

How do I run a command as root now?

Prefix it with sudo, or open a root shell with sudo -i for longer tasks. Both are logged with your user name.

Can SFTP clients still edit root owned files?

Not directly. Upload to your home directory and move the file with sudo, or give your user write access to the specific web directory.

What if I already locked myself out?

If an older session is still open, undo the change from there. Otherwise open a support ticket; if access cannot be restored, reinstalling from the Settings tab gives a fresh system but erases the disk.