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
- Log in to your server with your normal user, over SSH.
- Set a password for root, if it has none:
sudo passwd root
This asks you to type a new root password twice.
- 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.
- Open the file in an editor:
sudo nano /etc/ssh/sshd_config
- Find the line that starts with
PermitRootLogin. It may have a#in front. - Change it to read:
PermitRootLogin yes
- If you want password logins, check that
PasswordAuthentication yesis set. - Press Ctrl+O, then Enter to save. Press Ctrl+X to leave.
- Restart SSH:
sudo systemctl restart ssh
This applies the new setting. Keep your current session open.
- 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_configand setPermitRootLogin yes. - Back up the file first.
- Restart SSH and test in a second window.
- Use strong passwords or keys.