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.
By default, you can’t login to the root account via SSH on Ubuntu 22.04. This is a security feature because you would not want someone gaining root access to your server through brute forcing the root password in SSH. However, it is easy enough to enable root login if you want to forego this security recommendation.
In this tutorial, you will learn how to enable SSH access for a root user on Ubuntu 22.04 Jammy Jellyfish.
In this tutorial you will learn:
- How to enable root access to SSH
- How to restart SSH service
|Category||Requirements, Conventions or Software Version Used|
|System||Ubuntu 22.04 Jammy Jellyfish|
|Other||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 22.04 step by step instructions
- Start by opening a command line terminal and opening the
/etc/ssh/sshd_configSSH configuration file with nano or your preferred text editor. Be sure to do this with root permissions.
$ sudo nano /etc/ssh/sshd_config
- Inside this file, we need to uncomment the
#PermitRootLogin prohibit-passwordand change the setting to
yes. See below to see how your line should look.
FROM: #PermitRootLogin prohibit-password TO: PermitRootLogin yes
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
- Now we must 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 22.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
- Given that your Ubuntu 22.04 system allows incoming traffic on port 22/ssh, you should now be ready to SSH login as root:
$ sudo ufw allow ssh
$ ssh root@ubuntu-server
In this tutorial, we learned how to enable root SSH login in Ubuntu 22.04 Jammy Jellyfish Linux. This makes it more convenience for the owner, since they can SSH directly into the root account. Although there is a slight security concern with this configuration, it should not be much of a problem as long as your root account has a secure password and there is only one user on the system.