Table of Contents
SSH root login security is one of the most critical aspects of protecting your server from unauthorized access. In this guide, we’ll walk you through two essential security measures: disabling root login and using SSH keys for authentication.
Why SSH Security Matters
Secure Shell (SSH) is the primary method for accessing and administering Linux servers remotely. Weak SSH configurations can compromise SSH root login security, exposing your system to brute-force attacks, credential stuffing, and unauthorized logins — especially when root access is allowed or password-based logins are enabled.
Step 1: Disable Root Login
The root user has full control over the system. Allowing root to log in over SSH can be dangerous — especially if password authentication is enabled.
How to Disable Root Login
1. Connect to your server using a non-root user (or root for now if it’s your first time).
2. Open the SSH configuration file:
sudo nano /etc/ssh/sshd_config
3. Find the line:
PermitRootLogin yes
And change it to:
PermitRootLogin no
If the line doesn’t exist, add it at the end of the file.
4. Save and exit (Ctrl+X, then Y and Enter).
5. Restart the SSH service:
sudo systemctl restart sshd
Important: Ensure you’ve created a non-root user with SSH access before disabling root login.
Secure Your Server – Disable Root & Use SSH Keys
Protect SSH Access – Follow Best Practices
Explore SSH Best Practices