Table of Contents

How to Enable Root Login via SSH in Ubuntu

Step 1: Enable Root User Password

If you haven’t already set a password for the root user, you need to do so. By default, Ubuntu disables root login by not setting a password for the root account. To set or change the root password, run the following command:

 sudo passwd root

You will be prompted to enter a new password for the root user. Make sure to choose a strong password. After you confirm the new password, the root account will be enabled.

Step 2: Edit the SSH Configuration File

To enable root login via SSH, you need to modify the SSH daemon configuration file, sshd_config.

  #Open the SSH configuration file using your preferred text editor. For example:
  sudo nano /etc/ssh/sshd_config
  
  #Look for the following line in the configuration file:
  #PermitRootLogin prohibit-password
  #Change this line to:
  #PermitRootLogin yes
  

This change will allow the root user to log in using a password.

Step 3: Restart the SSH Service

For the changes to take effect, you need to restart the SSH service:

 
 sudo systemctl restart ssh

This command will apply the new settings and enable root login over SSH.