Ubuntu 20.04 ssh root login enable

The purpose of this tutorial is to enable root login over SSH on Ubuntu 20.04 Focal Fossa Linux. After installing OpenSSH, logging into the root account is disabled by default. This is done for security purposes. In case an account is compromised, it means the attacker will not automatically have root permissions as well.

If you would like to do without this security recommendation and be able to login to SSH with your root account, there’s a simple setting you can change in the SSH server configuration file to enable root login. In this tutorial, you will see how how to enable root SSH login on the Ubuntu 20.04 Server or Desktop.

In this tutorial you will learn:

  • How to enable root access to SSH
  • How to restart SSH service
  • How to set a password for the root account
  • How to allow port 22 (SSH) through ufw firewall
Ubuntu 20.04 ssh root login enable
Ubuntu 20.04 ssh root login enable
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 20.04 Focal Fossa
Software OpenSSH Server
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

The root’s ssh remote shell access is denied by default. Follow the instructions below to enable SSH login for the root account.

  1. Open the /etc/ssh/sshd_config file with administrative privileges, using nano or which ever text editor you prefer.
    $ nano /etc/ssh/sshd_config
  2. Within this file, find and change the following line:Change from:
    #PermitRootLogin prohibit-password


    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
  3. When you have finished making this change, save the file and then restart the SSH service in order for the changes to take effect.
    $ sudo systemctl restart ssh
  4. 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. For 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
  5. Be sure that your firewall also allows incoming connection on port 22 (default port of SSH).
    $ sudo ufw allow ssh
  6. Finally, you are ready to login to SSH with the root user account on Ubuntu 20.04.
    $ ssh root@ubuntu-server

Closing Thoughts

In this tutorial, we saw how to enable root SSH login in Ubuntu 20.04 Focal Fossa Linux. Although it’s a default security feature to have root logins disabled by default, it’s typically okay to enable the logins as long as you have a secure password. You can also change the default port of SSH to provide you some additional security.