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.
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
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
Log in as the OS user
Substitute your user name and the server’s IP address:
ssh ubuntu@203.0.113.10If you log in with a password, enter this user’s password. Nothing appears as you type; that is expected.
Run sudo -i
The command opens a root shell:
sudo -iIf sudo asks for a password, enter the password of the
ubuntuuser (the one you logged in as), not root’s.Check that you are root
The prompt changes from
ubuntu@…:~$toroot@…:~#. You can also ask the system:whoamiThe answer
rootmeans you have the privileges. To go back to your normal user, runexit.
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.
Make sure you log in as the user with a key
In the next step, the key you use to log in as
ubuntuis 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.Copy the key to the root user
These commands create the
/root/.sshfolder 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_keysIf 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/.sshFind 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 linePermitRootLogin no, go to step 4. If it showsprohibit-password(or the old spellingwithout-password), or there are no active lines at all, root can already log in with a key: go straight to step 6.Allow root to log in with a key
Open the file the command showed, for example:
sudo nano /etc/ssh/sshd_configReplace
PermitRootLogin nowith the line below. If several lines were found, change them all.PermitRootLogin prohibit-passwordSave the file:
Ctrl+O,Enter, thenCtrl+X. If nano is not installed on the server, open the file invi.Check the settings and restart SSH
The check prints nothing if there are no errors:
sudo sshd -tThen restart the SSH service. On Ubuntu and Debian it is called
ssh:sudo systemctl restart sshOn Rocky Linux it is
sshd:sudo systemctl restart sshdTest login in a new window
Without closing the old connection, open a new terminal window:
ssh root@203.0.113.10If 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 see | Why | What to do |
|---|---|---|
Please login as the user "ubuntu" rather than the user "root". | Root login is blocked in root’s key file | Log in as ubuntu and run sudo -i. If you need root login, repeat steps 2–6. |
Permission denied (publickey). when logging in as root | Root does not have your key, and password login is off | Log 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 password | Check the user name: log in as ubuntu, debian or rocky, not as root. |
sudo asks for a password you do not know | It needs the OS user’s password from your login details | If the password is lost, reset it through rescue mode: how to reset the password. |
| The password link from the OVH email no longer opens | The link has expired | Reset the password through rescue mode, or reinstall the system if there is no data on the server yet. |
sudo sshd -t prints an error line | A typo in the configuration file | Fix 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 closed | An error in the SSH settings | Log 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?
sudo -i. Root has a password only if you set one yourself.Is there no root on an OVH VPS either?
ubuntu or debian, and sudo -i gives you root privileges.I forgot the password of the ubuntu user. What can I do?
passwd ubuntu: step by step. The data on the disks is not erased.Did this guide help?
Thank you! This tells us which guides work.
What went wrong?
Tell support at which step you got stuck and include the link to this guide, so you don’t have to explain from scratch.