By default, Ubuntu disables root login via SSH for security reasons. However, in some cases, you may need to enable it for administrative purposes. This guide will walk you through the steps to enable root login via SSH securely in Ubuntu.
Before enabling root login, ensure that you have root access. You can switch to the root user with:
sudo -i
If you haven’t set a root password yet, you can create one using:
sudo passwd root
Enter and confirm the new root password.
To allow root login via SSH, you need to modify the SSH configuration file.
sudo nano /etc/ssh/sshd_config
PermitRootLogin prohibit-password
PermitRootLogin yes
Apply the changes by restarting the SSH service:
sudo systemctl restart ssh
If you have UFW (Uncomplicated Firewall) enabled, allow SSH traffic:
sudo ufw allow ssh
sudo ufw reload
Now, try logging in as root from another system using:
ssh root@your-server-ip
Enter the root password when prompted.
For security reasons, consider restricting root login by allowing only specific IPs. Edit the SSH configuration file again:
sudo nano /etc/ssh/sshd_config
Add the following line:
AllowUsers root@your-trusted-ip
Save the file and restart SSH:
sudo systemctl restart ssh
Enabling root login via SSH in Ubuntu should be done cautiously due to security risks. It is recommended to use SSH key authentication and restrict access to trusted IP addresses. Following these steps, you can safely enable and manage root SSH access as needed.