Bots start guessing root passwords within minutes of a new server going online. Leaving direct root login open hands them the one username every Linux box has. If you're looking up how to disable root login ssh, the safe answer is short: create a sudo user first, test it, then set PermitRootLogin no and verify. Get that order wrong and you can lock yourself out of your own VPS.
Quick Answer: To disable root SSH login safely, create a non-root user with sudo rights, copy your SSH key to it, and confirm it can log in and run
sudofrom a second terminal. Then addPermitRootLogin noto a drop-in file in/etc/ssh/sshd_config.d/, runsudo sshd -t, restart SSH, and confirmsudo sshd -Treportspermitrootlogin no. As of November 2026, the steps are the same on Ubuntu, Debian, AlmaLinux and Rocky.
Last verified: November 2026. OpenSSH 10.6 upstream; Ubuntu 26.04 LTS ships OpenSSH 10.2; Ubuntu 24.04 LTS ships OpenSSH 9.6; RHEL 9 and 10 family.
Our team resolves 20 to 30 client server issues every day, and SSH lockouts after a rushed hardening job turn up in that queue more than you'd expect. This guide is the exact order we walk clients through, written so you can do it yourself in about 15 minutes.
Why Disable Root SSH Login (and Why the Order Matters)
Disabling root SSH login removes the one account name every attacker already knows. It also makes admins log in as themselves, so every sudo command lands in the logs with a real username attached.
Every internet-facing Linux server has an account called root, so automated scanners only need to guess one thing: the password or the key. Turning off direct root login over SSH removes that target completely. Since 2015, upstream OpenSSH has defaulted to prohibit-password, which blocks root passwords but still accepts root keys, so no is the only value that shuts the door fully.
The setting itself is one line. The risk is in the sequence. According to Hostaccent's support team, who handle 20 to 30 client issues a day, the SSH lockouts that reach us rarely come from the setting. They come from root being switched off before anyone tested the account meant to replace it.
The Two-Window Rule
Our team gives every client the same rule before they touch an SSH config file. We call it the Two-Window Rule:
- Window one stays logged in as root (or your current admin user) the whole time. You don't close it until the very end.
- Window two is where you test. The new user logs in, runs
sudo whoami, and getsrootback. - Close window one only after window two works and a fresh
ssh root@your-serveris refused.
Restarting SSH doesn't drop sessions that are already open. That's what makes window one your safety net if a typo breaks the config.
Do I still need this if I only log in with SSH keys?
Mostly, yes. Keys stop password guessing, but a root key that leaks from a laptop backup or a CI system gives instant, full control. A named user plus sudo adds a second step (the sudo password) and an audit trail of who did what.
If a backup script genuinely needs root, PermitRootLogin forced-commands-only lets that one key run one command and nothing else.
Pro Tip: Take a snapshot before you edit any SSH file. We manage KVM/Proxmox virtualization ourselves, and in our experience a snapshot takes seconds while a rescue-mode recovery can eat an hour.
How to Disable Root Login SSH in 6 Steps
The six steps are: create a sudo user, give it your SSH key, test it, add PermitRootLogin no in a drop-in file, validate and restart, then prove root is refused. Budget about 15 minutes for the whole job.
Step 1: Create a sudo user before disabling root
On Ubuntu and Debian:
bashsudo adduser deploy sudo usermod -aG sudo deploy
On AlmaLinux, Rocky Linux and RHEL:
bashsudo useradd -m deploy sudo passwd deploy sudo usermod -aG wheel deploy
Pick any name except admin, user or ubuntu, because those are the next usernames bots try after root. Our guide to adding a user in Linux with the right groups and permissions goes deeper on group choices.
Step 2: Give the new user your SSH key
If root already logs in with a key, copy that authorized_keys file across and fix the ownership:
bashsudo mkdir -p /home/deploy/.ssh sudo cp /root/.ssh/authorized_keys /home/deploy/.ssh/ sudo chown -R deploy:deploy /home/deploy/.ssh sudo chmod 700 /home/deploy/.ssh sudo chmod 600 /home/deploy/.ssh/authorized_keys
Those permissions aren't optional. With StrictModes yes (the default), sshd quietly ignores a key file that other users can write to, and your login falls back to a password prompt. If 700 and 600 look unfamiliar, here's how Linux file permissions work. No key yet? Generate an Ed25519 key on your own computer first.
Step 3: Test the new user from a second window
Open a new terminal on your computer (this is window two) and run:
bashssh deploy@your-server-ip sudo whoami
You should see root. If the login or the sudo step fails, stop here and fix it. Nothing else in this guide is safe until this works.
Step 4: Set PermitRootLogin no in a drop-in file
Current Ubuntu, Debian and RHEL-family releases load every /etc/ssh/sshd_config.d/*.conf file from an Include line near the top of the main config. A drop-in is cleaner than editing sshd_config directly, and package updates won't overwrite it.
bashecho "PermitRootLogin no" | sudo tee /etc/ssh/sshd_config.d/00-hardening.conf
As of November 2026, sshd on Ubuntu 24.04, Ubuntu 26.04 and RHEL 9 reads the sshd_config.d folder before the rest of sshd_config, and the first value it sees for each setting wins. Drop-in files load in name order, so a file called 00-hardening.conf is read before 01-permitrootlogin.conf or 50-cloud-init.conf and its value sticks.
Editing PermitRootLogin no in sshd_config itself still works on servers with no conflicting drop-ins. The drop-in route simply removes the guesswork.
Step 5: Validate the config and restart SSH
bashsudo sshd -t sudo systemctl restart ssh # Ubuntu, Debian sudo systemctl restart sshd # AlmaLinux, Rocky, RHEL
sshd -t prints nothing when the config is valid. If it prints an error, fix that first, because a broken config stops SSH accepting new connections after the restart.
Ubuntu 24.04 and 26.04 use socket activation, so ssh.service can show as inactive between connections. That's normal. A plain restart covers this change; only Port or ListenAddress edits need sudo systemctl daemon-reload followed by sudo systemctl restart ssh.socket. If sshd -t complains about a missing /run/sshd directory, run sudo mkdir -p /run/sshd and test again. Check your version with ssh -V, and the OpenSSH release notes show what changed in each release.
Step 6: Prove root is refused
bashsudo sshd -T | grep -i permitrootlogin # permitrootlogin no
Then, from your own computer, try ssh root@your-server-ip. You want Permission denied.
sshd -T prints the settings the daemon will actually use after every include and override. Most guides skip it, and it's the check that catches the problems in the next section. The sshd_config manual lists every value PermitRootLogin accepts.
Insider Insight: On cPanel servers, the new user must also be in the wheel group before
su -will work. After 10 years running cPanel/WHM and Plesk fleets, we still see this one trip people up. Add the user under WHM's Manage Wheel Group Users, and our cPanel server setup guide covers what else a proper install needs.
Still working through this server issue?
Send the symptoms, error output, and what you have already tried. We can work with Hostaccent services or infrastructure hosted with another provider.
Why PermitRootLogin No Still Lets Root Log In
If root can still log in after you set PermitRootLogin no, another file is setting the value first, or a Match block is turning it back on for certain connections.
As of 2026, the most common reason PermitRootLogin no seems to do nothing is a drop-in file in /etc/ssh/sshd_config.d/ that sets a different value earlier. RHEL 9 creates 01-permitrootlogin.conf with PermitRootLogin yes when root SSH is allowed during install, and that file wins over anything further down in the main config.
Find the culprit with one command:
bashsudo grep -rniE "permitrootlogin|^match" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/
The usual suspects:
01-permitrootlogin.confon RHEL, AlmaLinux and Rocky 9 and later, written by the installer.50-cloud-init.confon cloud images. It normally setsPasswordAuthentication yes, which matters once you go key-only.- A
Matchblock at the bottom ofsshd_config, such asMatch Address 10.0.0.0/8followed byPermitRootLogin yes. Settings inside a Match block override the global value for connections that match. Test one withsudo sshd -T -C user=root,host=test,addr=10.0.0.5. - No restart, or a restart of the wrong service name (
sshversussshd).
One more trap: prohibit-password still lets root in with a key. If you set that value and tested with a key, root getting in is the expected behaviour, not a bug.
Root Login Disabled but Locked Out? How to Get Back In
If you're locked out, use your provider's web console. PermitRootLogin only controls SSH, so a local console login still works as long as you know the account's password.
- Open the VNC, noVNC or serial console from your hosting control panel and log in locally.
- Fix the cause: delete the bad line, correct the
authorized_keyspermissions, or add the missing sudo or wheel group. - Run
sudo sshd -t, restart SSH, and test again using the Two-Window Rule. - No root password at all (common on cloud images built for keys only)? Boot into rescue mode, mount the disk, and edit the files from there.
One lockout pattern our team sees regularly isn't PermitRootLogin at all. It's AllowUsers added in the same edit with a typo in the username, which blocks every account at once. Across the 4,000+ sites Hostaccent has migrated since 2016, the safest habit hasn't changed: change one SSH setting at a time and test after each one.
Seeing a timeout instead of Permission denied? That points to a firewall or network problem, and fixing an SSH connection timed out error is a separate checklist. If you restored the server from a snapshot and your computer now warns that the host key changed, read Host Key Verification Failed before accepting the new key.
Harden the Rest of SSH in 10 Minutes
With root closed off, three more changes cover most of the remaining risk: SSH key-only login, fewer attempts per connection, and automatic bans for repeat offenders.
Add these lines to the same 00-hardening.conf file:
bashPermitRootLogin no PasswordAuthentication no KbdInteractiveAuthentication no PubkeyAuthentication yes MaxAuthTries 3 LoginGraceTime 30 AllowUsers deploy X11Forwarding no
| sshd_config setting | Recommended value | Upstream default | What it stops |
|---|---|---|---|
| PermitRootLogin | no | prohibit-password | Any direct root login |
| PasswordAuthentication | no | yes | Password guessing (brute force) |
| KbdInteractiveAuthentication | no | yes | PAM password prompts that sneak back in |
| MaxAuthTries | 3 | 6 | Cycling through many keys or passwords per connection |
| LoginGraceTime | 30 | 120 seconds | Half-open logins that tie up slots |
| AllowUsers | your admin user | not set | Logins from every other account |
A server with SSH key-only login, root login disabled and MaxAuthTries set to 3 shuts out the password-guessing bots that fill most SSH logs. As of November 2026, the same settings work unchanged on OpenSSH 8.9 through 10.6, so one drop-in file covers Ubuntu 22.04, 24.04 and 26.04.
Test PasswordAuthentication no in window two before closing window one. It's the setting that locks out anyone without a working key.
Add Fail2ban and a firewall rate limit
Install Fail2ban with sudo apt install fail2ban (or dnf install fail2ban from EPEL on RHEL-family systems). By default its sshd jail bans an address for 10 minutes after 5 failures inside 10 minutes. For a public server we'd raise bantime to 1 hour or more. On Ubuntu, sudo ufw limit 22/tcp adds a second layer by blocking any address that opens 6 or more connections in 30 seconds.
Moving SSH off port 22 is fine for cutting log noise, but don't count it as security. Scanners find a new port quickly, so spend that effort on keys instead. The Ubuntu Server documentation explains OpenSSH and socket activation for each LTS release if you do change it.
Pro Tip: Keep every hardening line in that single
00-hardening.conffile. On your next server, copy the file over, runsudo sshd -t, restart, and the whole job takes about 2 minutes.
Your Next Step: A VPS Where Root Access Stays Yours
- Create and test a sudo user before you touch PermitRootLogin.
- Put your settings in
/etc/ssh/sshd_config.d/00-hardening.confso nothing overrides them. - Trust
sshd -T, not the file you edited. - Keep window one open until root is refused.
You've seen that the setting is the easy part and the order is what saves you. If you'd rather practise this on a server you fully control, Hostaccent's Linux VPS gives you full root access to harden however you like, 24/7 support from our own in-house engineers, and free 30 Gbps DDoS protection. The Standard plan at $12.00/mo renews at the same $12.00/mo and comes with a 30-day money-back guarantee. One honest caveat: it's a self-managed VPS with no control panel licence included, so if you never want to open a terminal, shared hosting will suit you better. Keep this how to disable root login ssh checklist handy and start on the Standard plan for $12.00/mo.
Frequently Asked Questions
How to disable root login ssh on Ubuntu 24.04?
Create a sudo user and copy your SSH key to it, then test that it can log in and run sudo. Next, run echo "PermitRootLogin no" | sudo tee /etc/ssh/sshd_config.d/00-hardening.conf, check the config with sudo sshd -t, and restart with sudo systemctl restart ssh. Finally confirm sudo sshd -T shows permitrootlogin no. Ubuntu 24.04 uses socket activation, but a normal restart is enough for this change.
What is the difference between PermitRootLogin no and prohibit-password?
PermitRootLogin no blocks root over SSH completely, whether the login uses a password or a key. prohibit-password blocks root passwords but still accepts root SSH keys, and it has been the upstream OpenSSH default since 2015. For most servers, no is the better choice because a leaked root key then gets nothing. Keep prohibit-password only when automation really needs root and you can't give it a sudo account instead.
Will disabling root login break cPanel, WHM or my SFTP client?
It won't break cPanel or WHM themselves, because those web panels log in through their own interface, not SSH. It will stop any SFTP or SCP client that connects as root, such as FileZilla profiles saved with root credentials. Switch those profiles to your new sudo user. On cPanel servers, also add that user to the wheel group in WHM, otherwise su - will refuse to switch to root after you log in.
Can I still use sudo su after disabling root login?
Yes. Disabling root login only stops root from connecting directly over SSH. Once you're logged in as your sudo user, sudo -i or sudo su - gives you a full root shell, and su - works too if root has a password. This is actually the point of the change: you still get root powers, but only after logging in as a named user, which leaves a clear record of who ran what.
Does disabling root SSH login stop the console from working?
No. PermitRootLogin is an SSH server setting, so it has no effect on local logins through your provider's VNC, noVNC or serial console. If root has a password, you can still log in as root there, which is why the console is your recovery path after a lockout. Many cloud images ship root without a password, so set one with sudo passwd root beforehand if you want console access as a backup.
Should I also change the SSH port after disabling root?
Changing the port cuts down log noise from bots that only scan port 22, but it isn't real protection, since port scanners find SSH on any port within minutes. Key-only login, MaxAuthTries 3 and Fail2ban do far more. If you change it anyway on Ubuntu 24.04 or 26.04, run sudo systemctl daemon-reload and restart ssh.socket, and open the new port in your firewall before you restart.












Discussion
Have a question or tip about this topic? Share it below — your comment will appear after review.