How to Enable Root Login on a Linux Server
On most Linux servers, direct root login over SSH and SFTP is disabled by default. In this tutorial, you’ll learn how to enable it when you need it and how to disable it again.
What you need before you start
- A VPS or dedicated server running Linux.
- A user with sudo privileges.
- An SSH client. More: How to use PuTTY.
The root user has unlimited privileges, and every bot knows its name and constantly tries to guess passwords. Enable root login only when you really need it, use a strong password and disable it again when you’re done.
Setting up root login
-
Connect to the server
Connect to the server via SSH with your regular user.
-
Set a root password
On Ubuntu, the root password isn’t set by default, so login would fail. Set it with:
sudo passwd rootEnter the new password twice. The characters aren’t shown as you type, which is normal. If root already has a password, skip this step.
-
Open the SSH configuration file
Open the file in the editor:
sudo nano /etc/ssh/sshd_configPress Ctrl + W and search for PermitRootLogin. The line usually looks like this:
#PermitRootLogin prohibit-password -
Change the PermitRootLogin setting
Remove the # at the start of the line and change the value:
PermitRootLogin yesTo block root login again, change the value to:
PermitRootLogin noHow to saveCtrl + O and Enter saves the file, Ctrl + X exits the editor.
On some servers, e.g. Ubuntu, settings may be overridden by files in /etc/ssh/sshd_config.d/. Check that there’s no other PermitRootLogin value there:
sudo grep -ri permitrootlogin /etc/ssh/sshd_config.d/ -
Test the configuration and restart SSH
First, check the file for errors. If the command prints nothing, everything is fine:
sudo sshd -tThen restart the SSH service. The command depends on the system:
sudo systemctl restart sshsudo systemctl restart sshdDon’t close your current windowKeep your current SSH session open until you’ve confirmed the new login works. If something goes wrong, you can use it to undo the changes.
Did it work?
Check which PermitRootLogin value SSH is actually using:
sudo sshd -T | grep permitrootloginThen, in a new window, try logging in as root, replacing server_ip with your server IP:
ssh root@server_ipFAQ
I get “Access denied” when logging in as root
Check that you set a root password (step 2) and that no files in /etc/ssh/sshd_config.d/ contain PermitRootLogin or PasswordAuthentication no lines overriding your setting.
“Unit sshd.service not found”
On Ubuntu and Debian, the SSH service is called ssh. Use sudo systemctl restart ssh.
Is there a more secure option?
Yes. Set PermitRootLogin prohibit-password and log in with an SSH key instead of a password. Even better, work with a separate user and use sudo.
Does this setting also apply to SFTP?
Yes. SFTP uses the same SSH service, so root login via WinSCP or FileZilla follows the same setting.
What’s next
If you run into trouble, contact us via live chat or email.