Prerequisites
Before enabling root login, make sure you have:
- SSH access to your VPS with a sudo user
- Your server IP address
- Sudo user password
⚠️ Security Warning: Enabling root login is a security risk. Only do this temporarily or if you understand the implications.
Step 1: Connect to Your VPS with Sudo User
ssh username@YOUR_SERVER_IP -p 22Step 2: Edit SSH Configuration
Open the SSH daemon config file:
sudo nano /etc/ssh/sshd_configStep 3: Find and Change PermitRootLogin
Look for this line:
PermitRootLogin noChange it to:
PermitRootLogin yesIf the line doesn't exist, add it:
PermitRootLogin yesOther options you can use:
PermitRootLogin yes- Allow root login with password (least secure)PermitRootLogin prohibit-password- Allow root only with SSH keysPermitRootLogin forced-commands-only- Only for specific commands
Step 4: Restart SSH Service
sudo systemctl restart sshdFor older systems:
sudo service ssh restartStep 5: Test Root Login
Open a new terminal window and try:
ssh hxroot@YOUR_SERVER_IP -p 22Enter the root password when prompted.
Alternative Method: Temporary Root Access via Sudo
If you only need root temporarily, don't enable root login. Instead:
ssh username@YOUR_SERVER_IPsudo -iThis gives you a root shell without enabling root SSH login.
Enable Root Login with SSH Key Only (More Secure)
This method allows root login but only with an SSH key, not password:
sudo nano /etc/ssh/sshd_configSet:
PermitRootLogin prohibit-passwordThen restart SSH:
sudo systemctl restart sshdNow copy your SSH key to root:
sudo ssh-copy-id hxroot@YOUR_SERVER_IPCheck Current Root Login Status
sudo grep PermitRootLogin /etc/ssh/sshd_configDisable Root Login Again (Reversing Changes)
sudo nano /etc/ssh/sshd_configChange back to:
PermitRootLogin nosudo systemctl restart sshdWhy Root Login is Disabled by Default
- Brute force attacks target root user
- Root has unlimited system access
- No audit trail (sudo commands are logged)
- Accidental mistakes as root can break server
- Industry security best practice
Best Practices Instead of Root Login
- Use a sudo user for daily tasks
- Use SSH keys instead of passwords
- Change SSH port from 22 to a custom port
- Set up Fail2ban to block failed attempts
- Use 2FA for SSH
✅ Root login has been enabled (or disabled). Remember to revert to a more secure setup when possible.