Prerequisites
Before disabling root login, make sure you have:
- A working sudo user account with SSH access
- Tested that your sudo user can run commands with
sudo - SSH access to your VPS
⚠️ Critical: Do NOT disable root login until you have verified your sudo user works. Otherwise you will lock yourself out!
Step 1: Connect with Your Sudo User
ssh username@YOUR_SERVER_IP -p 22Replace username with your sudo user (not root).
Step 2: Test Sudo Access
Verify you can run privileged commands:
sudo whoamiShould output:
rootStep 3: Edit SSH Configuration
sudo nano /etc/ssh/sshd_configStep 4: Find and Change PermitRootLogin
Locate the line:
PermitRootLogin yesChange it to:
PermitRootLogin noIf the line is commented out (# at start), remove the # and change it.
If the line doesn't exist, add it:
PermitRootLogin noStep 5: Save and Exit
In nano: Press Ctrl+X, then Y, then Enter.
Step 6: Verify SSH Configuration
Check for syntax errors before restarting:
sudo sshd -tIf no output, configuration is valid.
Step 7: Restart SSH Service
sudo systemctl restart sshdFor older systems:
sudo service ssh restartStep 8: Test That Root is Disabled
Open a new terminal and try to login as root:
ssh hxroot@YOUR_SERVER_IP -p 22You should see:
Permission denied (publickey,password).Step 9: Test Your Sudo User Still Works
In the new terminal, connect with your sudo user:
ssh username@YOUR_SERVER_IP -p 22sudo ls /rootShould work and show root directory contents.
Alternative: Disable Root Password but Allow Key
More secure than completely disabling:
sudo nano /etc/ssh/sshd_configSet:
PermitRootLogin prohibit-passwordThis allows root login with SSH keys only.
Set Up Sudo User (If You Haven't Already)
If you don't have a sudo user, create one before disabling root:
adduser usernameusermod -aG sudo usernameAdditional Security After Disabling Root
- Change SSH port from 22 to something else:
sudo nano /etc/ssh/sshd_configPort 2222sudo systemctl restart sshd- Disable password authentication (use SSH keys only):
PasswordAuthentication no- Install Fail2ban:
sudo apt install fail2ban -yIf You Get Locked Out
If you accidentally lock yourself out:
- Use Hostxpeed portal to access server console
- Contact Hostxpeed support for emergency access
- Reinstall OS (last resort)
To recover via portal:
- Log in to Hostxpeed Client Area
- Go to My Services → Your VPS
- Look for "Console Access" or "Recovery Console"
- Use console to re-enable root login
Verify Root Login Status from Inside Server
sudo grep PermitRootLogin /etc/ssh/sshd_config
✅ Root SSH login has been disabled. Your server is now more secure. Always use your sudo user and sudo for administrative tasks.