Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Enable Root Login via SSH in Ubuntu

This guide shows how to let the root user log in over SSH on an Ubuntu server. It needs root access.

Web Hosting2 min read10 steps
Note: You need root access, or a user that can use sudo. These steps are for VPS and dedicated server customers.

What is root login?

Root is the all-powerful admin user on a Linux server. SSH is a safe way to control a server by typing commands from your own computer. On many Ubuntu systems, root login over SSH is turned off by default. This is for safety, because everyone knows the root name, so attackers try it first.

This guide is written for Ubuntu 18.04 and 20.04. These are older versions. Newer versions work in a similar way.

Warning

Allowing root login makes a server easier to attack. Use a very strong password, or better, an SSH key. A key is a long secret file that is safer than a password. Make a copy of the config file before you change it.

Steps

  1. Log in to your server with your normal user, over SSH.
  2. Set a password for root, if it has none:
sudo passwd root

This asks you to type a new root password twice.

  1. Back up the SSH settings file:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

This makes a safe copy you can restore.

  1. Open the file in an editor:
sudo nano /etc/ssh/sshd_config
  1. Find the line that starts with PermitRootLogin. It may have a # in front.
  2. Change it to read:
PermitRootLogin yes
  1. If you want password logins, check that PasswordAuthentication yes is set.
  2. Press Ctrl+O, then Enter to save. Press Ctrl+X to leave.
  3. Restart SSH:
sudo systemctl restart ssh

This applies the new setting. Keep your current session open.

  1. Open a second terminal and test:
ssh root@your-server-address

If you get in, it works.

If it fails

  • Check the spelling in the file.
  • Use your first session to restore the backup.
  • Check that the firewall allows SSH.

Need help? Open a support ticket.

Quick recap

  • Root login over SSH is off by default on Ubuntu.
  • Edit /etc/ssh/sshd_config and set PermitRootLogin yes.
  • Back up the file first.
  • Restart SSH and test in a second window.
  • Use strong passwords or keys.