Allow SSH root login on Ubuntu 22.04 Jammy Jellyfish 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.

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
Allowing SSH root login on Ubuntu 22.04 Jammy Jellyfish
Allowing SSH root login on Ubuntu 22.04 Jammy Jellyfish
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 22.04 Jammy Jellyfish
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 22.04 step by step instructions

  1. Start by opening a command line terminal and opening the /etc/ssh/sshd_config SSH configuration file with nano or your preferred text editor. Be sure to do this with root permissions.
    $ sudo nano /etc/ssh/sshd_config
  2. Inside this file, we need to uncomment the #PermitRootLogin prohibit-password and change the setting to yes. See below to see how your line should look.
    #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. Now we must 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 22.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. 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

Closing Thoughts

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.