OVHcloud

OVH server login as ubuntu or debian: sudo and root

After OVH installs Linux, you cannot log in as root over SSH: login is open to a user named after the system, such as ubuntu. That user gets root privileges with sudo -i, and most of the time that is all you need.

  • Time: 10 minutes
  • Level: Intermediate

In short

  • Log in as the user named after the OS: ubuntu, debian, rocky. Root is disabled at installation, and root login over SSH is blocked. OVH VPS work the same way.
  • For root privileges, run sudo -i; if sudo asks for a password, enter your user’s password. The command prompt then ends in #.
  • If you cannot do without direct root login, enable it with a key (PermitRootLogin prohibit-password), not with a password.
Contents
  1. Which user to log in as
  2. How to get root privileges with sudo -i
  3. If you need direct root login over SSH
  4. How to check that everything works
  5. If it did not work
  6. FAQ

You will need

  • The server’s IP address and login details: from us in the ticket when the server is delivered, or in the OVH email after a reinstall you started yourself.
  • An SSH client: how to connect to a server via SSH.
  • For root login with a key: your own SSH key that you already use to log in as the OS user.

Which user to log in as

When OVH installs Linux, it creates a user with sudo rights and names it after the system. Root is disabled, and root login over SSH is blocked. The user name depends on the OS:

  • Ubuntu: ubuntu;
  • Debian: debian;
  • Rocky Linux: rocky.

Other systems also use the OS name, and the exact name is in your login details. If the password in the OVH email is behind a link, open it right away and save the password in a password manager: the link may stop working later.

On an OVH Windows server, you log in over RDP: how to connect to a Windows server.

How to get root privileges with sudo -i

  1. Log in as the OS user

    Substitute your user name and the server’s IP address:

    ssh ubuntu@203.0.113.10

    If you log in with a password, enter this user’s password. Nothing appears as you type; that is expected.

  2. Run sudo -i

    The command opens a root shell:

    sudo -i

    If sudo asks for a password, enter the password of the ubuntu user (the one you logged in as), not root’s.

  3. Check that you are root

    The prompt changes from ubuntu@…:~$ to root@…:~#. You can also ask the system:

    whoami

    The answer root means you have the privileges. To go back to your normal user, run exit.

For a single command you do not need a root shell: just put sudo in front of it, for example sudo apt update.

To change your user’s password, run passwd: it asks for the current password, then for the new one twice.

If you need direct root login over SSH

Direct root login is sometimes needed by programs that connect to a server only as root. If you have no such program, leave everything as it is and work through sudo -i.

If you do need it, enable it with a key. Any server with SSH open gets constant attempts to guess the root password, and a key cannot be brute-forced. With the prohibit-password setting, root logs in only with a key, and the server rejects every attempt to log in as root with a password.

Do not close your current connection until you have tested login in a new window. If you make a mistake in the SSH settings and close the session, the only way back in is the KVM console (IPMI) or rescue mode.

  1. Make sure you log in as the user with a key

    In the next step, the key you use to log in as ubuntu is copied for root. If you still log in with a password, first add your key for the user: how to log in with an SSH key.

  2. Copy the key to the root user

    These commands create the /root/.ssh folder and put your key in it with the right permissions:

    sudo install -d -m 700 /root/.ssh
    sudo cp ~/.ssh/authorized_keys /root/.ssh/authorized_keys
    sudo chmod 600 /root/.ssh/authorized_keys

    If root already had a key file, it is replaced. That is intended: the old file may contain the block on root login, the very one that prints “Please login as the user…”.

    On Rocky Linux, restore the SELinux labels afterwards, otherwise SSH may not be able to read the file:

    sudo restorecon -R /root/.ssh
  3. Find the PermitRootLogin setting

    The command shows which SSH configuration files set it:

    sudo grep -rn PermitRootLogin /etc/ssh/sshd_config /etc/ssh/sshd_config.d/

    Lines that start with # are comments; ignore them. If the command found the line PermitRootLogin no, go to step 4. If it shows prohibit-password (or the old spelling without-password), or there are no active lines at all, root can already log in with a key: go straight to step 6.

  4. Allow root to log in with a key

    Open the file the command showed, for example:

    sudo nano /etc/ssh/sshd_config

    Replace PermitRootLogin no with the line below. If several lines were found, change them all.

    PermitRootLogin prohibit-password

    Save the file: Ctrl+O, Enter, then Ctrl+X. If nano is not installed on the server, open the file in vi.

  5. Check the settings and restart SSH

    The check prints nothing if there are no errors:

    sudo sshd -t

    Then restart the SSH service. On Ubuntu and Debian it is called ssh:

    sudo systemctl restart ssh

    On Rocky Linux it is sshd:

    sudo systemctl restart sshd
  6. Test login in a new window

    Without closing the old connection, open a new terminal window:

    ssh root@203.0.113.10

    If you get in, the setup is done. If not, go back to the old window and check the table below.

Root login with a password (not recommended)

Set a root password, long and not used anywhere else:

sudo passwd root

Then, in the file with the setting from step 3, set PermitRootLogin yes. If password login is turned off on the server altogether, find that setting too with sudo grep -rn PasswordAuthentication /etc/ssh/sshd_config /etc/ssh/sshd_config.d/ and set PasswordAuthentication yes. Check the settings and restart SSH as in step 5. A server that accepts a root password over SSH will face brute-force attempts, so switch back to a key as soon as the task is done.

How to check that everything works

Login as the OS user works, and after sudo -i the whoami command answers root. If you enabled root login, ssh root@203.0.113.10 in a new window lets you in with your key, without asking for the server password.

If it did not work

What you seeWhyWhat to do
Please login as the user "ubuntu" rather than the user "root".Root login is blocked in root’s key fileLog in as ubuntu and run sudo -i. If you need root login, repeat steps 2–6.
Permission denied (publickey). when logging in as rootRoot does not have your key, and password login is offLog in as the OS user and copy the key for root (step 2).
Permission denied, please try again.Wrong password, or root may not log in with a passwordCheck the user name: log in as ubuntu, debian or rocky, not as root.
sudo asks for a password you do not knowIt needs the OS user’s password from your login detailsIf the password is lost, reset it through rescue mode: how to reset the password.
The password link from the OVH email no longer opensThe link has expiredReset the password through rescue mode, or reinstall the system if there is no data on the server yet.
sudo sshd -t prints an error lineA typo in the configuration fileFix the line the command names, and do not restart SSH until the check stops printing errors.
After editing the settings you cannot get in at all, and the old window is closedAn error in the SSH settingsLog in through the KVM console (IPMI) or boot the server into rescue mode and fix the file.

If none of this helps, send us in a ticket the command you connect with and the full error text. Do not put passwords in the ticket.

FAQ

What is the default root password on an OVH server?
There is none: when OVH installs Linux, root is disabled. Log in as the OS user and get root privileges with sudo -i. Root has a password only if you set one yourself.
Is there no root on an OVH VPS either?
That’s right: on an OVH VPS you also log in by default as a user named after the system, such as ubuntu or debian, and sudo -i gives you root privileges.
I forgot the password of the ubuntu user. What can I do?
Boot the server into rescue mode, mount the system disk and change the password with passwd ubuntu: step by step. The data on the disks is not erased.

Did this guide help?

Questions?