Enable SSH root login on Ubuntu 20.04 Focal Fossa Linux

SSH (Secure Shell) is used to handle network services securely over an unsecured network. Some examples include: remote command-line, login, and remote command execution. Normally to log into SSH, it must be done as a normal user, and then you can elevate to the root user after logging in. But it is possible to bypass this behavior with a simple config edit. In this tutorial, you will learn how to enable SSH root login on Ubuntu 20.04 Server/Desktop.

In this tutorial you will learn:

  • How to enable root access to SSH
  • How to restart SSH service
Allow SSH root login on Ubuntu 20.04 Focal Fossa Linux
Allow SSH root login on Ubuntu 20.04 Focal Fossa Linux

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed or upgraded Ubuntu 20.04 Focal Fossa
Software SSH
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Allowing SSH root login on Ubuntu 20.04 step by step instructions



WARNING
SSH root login is disabled by default as a security feature. If you are still determined to enable root login, ensure that you are using a very secure password for your root account. If the root account gets accessed by a hacker, your whole system will be compromised.
  1. Open the /etc/ssh/sshd_config file with administrative privileges and change the following line:
    FROM:
    #PermitRootLogin prohibit-password
    TO:
    PermitRootLogin yes
    

    The quick way to do this job could be just to simply use the sed command as shown below:

    $ sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
    
  2. Restart SSH service:
    $ sudo systemctl restart ssh
    
  3. By default the root’s password is not set on Ubuntu 20.04 and the error message Permission denied, please try again will appear when attempting to SSH login as a root user. From this reason we need to set root’s password. When prompted enter your current user password followed by new root password:
    $ sudo passwd
    [sudo] password for linuxconfig: 
    Enter new UNIX password: 
    Retype new UNIX password: 
    passwd: password updated successfully
    



  4. Given that your Ubuntu 20.04 system allows incoming traffic on port 22/ssh, you should now be ready to SSH login as root:
    $ ssh root@ubuntu-server
    root@ubuntu-server's password: 
    Welcome to Ubuntu Focal Fossa (GNU/Linux 5.3.0-23-generic x86_64)
    

Allowing SSH root login on Ubuntu 20.04

Allowing SSH root login on Ubuntu 20.04