Enable SSH Root Login on Ubuntu 22.04¶
By default, Ubuntu disables root login over SSH for security reasons. Enabling root login is strongly discouraged in production environments because it increases the attack surface. However, if you need it (e.g., for testing or internal use), follow these steps carefully.
Prerequisites:¶
-
Server running Ubuntu 22.04 LTS.
-
Access as a non-root user with sudo privileges.
-
SSH already installed and running.
Steps to Enable SSH Root Login¶
1. Login as a sudo user¶
Connect to your server using your regular user account:
2. Switch to the root user¶
Once logged in, elevate privileges:
You should now see the prompt as root@your_server:~#.
3. Edit the SSH configuration file¶
Open the SSH daemon config file:
Look for the following parameters and modify as needed:
- PermitRootLogin Change from
prohibit-passwordornoto:
- PasswordAuthentication Make sure it’s set to:
⚠️ Notes:
-
If lines are commented with
#, remove the#before editing. -
Using
yesallows password login, which is less secure. A better alternative isPermitRootLogin prohibit-passwordwith SSH keys.
4. Save and exit¶
In nano, press:
-
CTRL + O→ Enter (save) -
CTRL + X→ Exit
5. Restart SSH service¶
Apply changes by restarting the SSH service:
Check service status:
Make sure it shows active (running).
6. Test SSH root login¶
From your local machine, try connecting directly as root:
If you enabled password authentication, enter the root password when prompted.
Security Recommendations¶
Enabling root login directly over SSH is not recommended. To improve security:
- Use SSH keys Generate a key pair on your local machine: Copy it to the server: Then disable password authentication:
- Restrict SSH access Edit
/etc/ssh/sshd_config: - Change default SSH port In
/etc/ssh/sshd_config: (Don’t forget to allow the new port in your firewall). - Use a firewall (UFW or iptables) to limit SSH access. Example with UFW:
✅ Now you should be able to log in as root via SSH, but consider disabling it once your task is complete for better security.