How To Enable Root Login On Ubuntu Focal 20.04 / 18.04

We can easily enable and install the OpenSSH server on ubuntu. You can also check ssh service and enable root login in ubuntu. Let’s see, how to enable root in ubuntu.

How To Enable Root Login On Ubuntu Focal 20.04 / 18.04

When you try to login with root user on ubuntu. So, you won’t be able to login because it’s not enabled. First of all, the SSH package won’t be pre-installed by default on the ubuntu machine.

Check Out: How To Install The Arc GTK Theme & Icons On Ubuntu 18.04

  1. Check SSH install on Ubuntu using the below command. if you see “No” output means it’s not installed. 
sudo which sshd

2. Install the OpenSSH package on ubuntu with the below command. 

ubuntu@ubuntu:~$ sudo apt install openssh-server 
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following additional packages will be installed:
ncurses-term openssh-sftp-server ssh-import-id
Suggested packages:
molly-guard monkeysphere ssh-askpass
The following NEW packages will be installed:
ncurses-term openssh-server openssh-sftp-server ssh-import-id
0 upgraded, 4 newly installed, 0 to remove and 3 not upgraded.
Need to get 688 kB of archives.
After this operation, 6,010 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

Once the package is installed, we need to start and enable the service using the following command. 

ubuntu@ubuntu:~$ sudo systemctl start ssh
ubuntu@ubuntu:~$ sudo systemctl enable ssh
Synchronizing state of ssh.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable ssh

Check ssh service status on ubuntu using the below command. 

sudo systemctl status ssh

Try to login with your user from a different terminal, you must be able to log in except the root user. The first time it will ask you for connection establishment.

user@Inspiro7573:~$ ssh ubuntu@192.168.145.148
The authenticity of host '192.168.145.148 (192.168.145.148)' can't be established.
ECDSA key fingerprint is SHA256:VCSFKIW+VBAvY8oZuXfCw0H0FhSEJ1AuSrD+uZ/FU.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.145.148' (ECDSA) to the list of known hosts.
ubuntu@192.168.145.148's password: 
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-42-generic x86_64)

3. We have to make some changes in /etc/ssh/sshd_config file. I will create a backup of the original file before making any changes. 

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config-org

Check Out: How To Install Node.js And NPM On Ubuntu 19.10

Now open the sshd_config file and search for “PermitRootLogin” changed it to “Yes“. 

PermitRootLogin yes

We need to set the root password using the below command. 

ubuntu@ubuntu:~$ sudo passwd root
New password: 
Retype new password: 
passwd: password updated successfully

4. you need to restart the ssh service using the below command and try to login with the root user. 

ubuntu@ubuntu:~$ sudo service sshd restart
ubuntu@ubuntu:~$ exit
user@Inspiro7573:~$ ssh root@192.168.145.148 
root@192.168.145.148's password: 
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-42-generic x86_64)
root@ubuntu:~#

As you can see, we’re now able to login with the root user on the remote ubuntu machine.

Restrict Root Password On Ubuntu: 

Suppose, the root user is able to reach the server using ssh service but not able to login with the password. you just need to uncomment the below parameter in /etc/ssh/sshd_config file. 

Check Out: How To Set Ulimit Users and File Descriptions On Linux Server

PermitRootLogin prohibit-password

Now restart the ssh service and try to login with the root user. you will be able to reach but not able to login with the same root password.

That’s it.

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment