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
|Requirements, Conventions or Software Version Used
|Ubuntu 20.04 Focal Fossa
|Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – 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.
- Open the
/etc/ssh/sshd_configfile with administrative privileges, using
nanoor which ever text editor you prefer.
$ nano /etc/ssh/sshd_config
- Within this file, find and change the following line:Change from:
The quick way to do this job could be just to simply use the
sedcommand as shown below:
$ sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
- 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
- By default the root’s password is not set on Ubuntu 20.04 and the error message
Permission denied, please try againwill 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
- Be sure that your firewall also allows incoming connection on port 22 (default port of SSH).
$ sudo ufw allow ssh
- Finally, you are ready to login to SSH with the root user account on Ubuntu 20.04.
$ ssh root@ubuntu-server
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.