By default, SSH on Ubuntu comes configured in a way that disables the root users log in. Uou can usually get around the need for root ssh login by using the sudo command. In some cases, though it’s just more convenient to get directly logged in as root.
How to Enable root login over SSH
- Login to your server with user root.
- Edit the sshd_config file found in /etc/ssh/sshd_config
nano /etc/ssh/sshd_config
Add the following line to the file, you can add it anywhere.
PermitRootLogin yes
When using SSH Keys, you can set the PermitRootLogin value to `without-password` instead of Yes.
PermitRootLogin without-password
Disable login Using Password in Ubuntu
You should also disable password login.
PasswordAuthentication no
Save and exit the file (Ctrl + X select Y and Enter)
Restart the SSH Server
systemctl restart sshd
or
service sshd restart