Back Back

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.
Consider the risk

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

  1. Connect to the server

    Connect to the server via SSH with your regular user.

  2. Set a root password

    On Ubuntu, the root password isn’t set by default, so login would fail. Set it with:

    sudo passwd root

    Enter the new password twice. The characters aren’t shown as you type, which is normal. If root already has a password, skip this step.

  3. Open the SSH configuration file

    Open the file in the editor:

    sudo nano /etc/ssh/sshd_config

    Press Ctrl + W and search for PermitRootLogin. The line usually looks like this:

    #PermitRootLogin prohibit-password
  4. Change the PermitRootLogin setting

    Remove the # at the start of the line and change the value:

    PermitRootLogin yes
    How to save

    Ctrl + 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/
  5. Test the configuration and restart SSH

    First, check the file for errors. If the command prints nothing, everything is fine:

    sudo sshd -t

    Then restart the SSH service. The command depends on the system:

    sudo systemctl restart ssh
    Don’t close your current window

    Keep 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 permitrootlogin

Then, in a new window, try logging in as root, replacing server_ip with your server IP:

ssh root@server_ip

FAQ

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.

Similar articles

How to Install Java on a VPS

How to Install Java on a VPS A Minecraft server and many other applications need Java. In this tutorial, you’ll install the Java version you...

Read
VPS Tutorials