Disabling Root Login and Using sudo
You'll learn how to lock down direct root access via SSH and enforce privilege escalation through sudo instead—a critical hardening step for any remote server.
Why This Matters
Allowing direct root login via SSH is like handing out master keys to your building's front door. If an attacker guesses or steals root credentials, they have immediate, unrestricted control. By disabling root login, you force everyone (including administrators) to log in with personal accounts first, then explicitly escalate privileges—creating an audit trail and limiting damage from compromised credentials.
The Configuration
The key setting lives in /etc/ssh/sshd_config:
PermitRootLogin no
After changing this directive, restart SSH:
systemctl restart sshd
Now root cannot log in remotely—period. Administrators must:
- SSH in with their personal account
- Use
sudoto run privileged commands - Create accountability (sudo logs who did what)
How It Works
When PermitRootLogin is set to no, the SSH daemon refuses authentication attempts for the root user, even with correct credentials. This forces the "two-step" security model: authenticate as yourself, then prove you're authorized to escalate.
This pairs perfectly with your existing sudo configuration knowledge—you've already set up which users can elevate privileges and how they're logged.
Analogy: Think of it like a bank vault requiring two different managers with separate keys. One person can't just walk in and take everything—there must be verification at multiple stages.
Key Takeaway: Setting PermitRootLogin no blocks direct root SSH access, forcing administrators to use personal accounts and sudo for privilege escalation, creating accountability and reducing attack surface.