Securing SSH: Root Login Best Practices | Generated by AI

Home 2026.01

Question: How to remove an SSH root key (from authorized_keys), and what does “PermitRootLogin” mean? What are the benefits of disabling root login via SSH?

Answer:

There are two related but different things here:

  1. Removing a specific SSH public key for the root user (so root can no longer log in with that particular key).
  2. Disabling root login completely (or restricting it) via the PermitRootLogin setting in SSH — this is usually what people mean when they say “remove SSH root login” or “disable root SSH access”.

1. How to remove a specific SSH public key for root

The public keys that allow login are stored in:

/root/.ssh/authorized_keys

(or sometimes /root/.ssh/authorized_keys2 on very old systems)

Steps to remove one key:

sudo nano /root/.ssh/authorized_keys
# or
sudo vim /root/.ssh/authorized_keys

Faster command-line way (if you know part of the key):

# Example: remove key containing "AAAAB3NzaC1yc2EAAAADAQABAAABAQ..."
sudo sed -i '/AAAAB3NzaC1yc2EAAAADAQABAAABAQ/d' /root/.ssh/authorized_keys

To remove all keys (completely stop key-based root login):

sudo mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bak
# or just delete it
sudo rm /root/.ssh/authorized_keys

After any change to authorized_keys, you usually do not need to restart sshd.

2. What is PermitRootLogin and how to disable root login

This setting is in /etc/ssh/sshd_config (or /etc/ssh/sshd_config.d/ files on modern systems).

Common values:

Recommended secure setting (most servers):

sudo nano /etc/ssh/sshd_config

Change or add:

PermitRootLogin no

Then restart SSH:

# Ubuntu/Debian
sudo systemctl restart ssh

# CentOS/RHEL/AlmaLinux/Rocky
sudo systemctl restart sshd

After this change:

Benefits of disabling root login via SSH (PermitRootLogin no)

Quick summary — what most secure servers do today:

This combination stops ~99% of automated SSH attacks.

References:


Back

x-ai/grok-4.1-fast

Donate