Changing your root password on a VPS
Find out how to change the root or admin password of a VPS
Find out how to change the root or admin password of a VPS
Last updated 20th April 2021
It may become necessary to change the root password on your GNU/Linux operating system. There are two possible scenarios:
This guide will explain how to proceed with changing your admin password depending on the initial situation.
OVHcloud is providing you with services for which you are responsible, with regard to their configuration and management. You are therefore responsible for ensuring they function correctly.
This guide is designed to assist you in common tasks as much as possible. Nevertheless, we recommend that you contact a specialist service provider if you have difficulties or doubts concerning the administration, usage or implementation of services on a server.
For more information about connecting to your VPS, please consult the first steps guide.
Log in to your VPS via SSH. Switch to the root user, if necessary:
~$ sudo su -
~#
Change the password of the current user:
~# passwd
New password:
Retype new password:
passwd: password updated successfully
On a GNU/Linux distribution, the password you enter will not appear.
If you need to permit logging in as root, follow the steps in this guide section.
Log in to your OVHcloud Control Panel and reboot the VPS in rescue mode. If you need further instructions about activating rescue mode with a VPS, you may consult the rescue mode guide.
On older VPS ranges, your partitions will be automatically mounted in rescue mode. You can use the following commands to verify this and identify where your partition is mounted:
~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 5.8G 0 5.8G 0% /dev
tmpfs 1.2G 17M 1.2G 2% /run
/dev/sda1 2.4G 1.5G 788M 66% /
tmpfs 5.8G 0 5.8G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 5.8G 0 5.8G 0% /sys/fs/cgroup
/dev/sdb1 49G 1.2G 48G 3% /mnt/sdb1
/dev/sdb15 105M 3.6M 101M 4% /mnt/sdb15
~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 2.5G 0 disk
└─sda1 8:1 0 2.5G 0 part /
sdb 8:16 0 50G 0 disk
├─sdb1 8:17 0 49.9G 0 part /mnt/sdb1
├─sdb14 8:30 0 4M 0 part
└─sdb15 8:31 0 106M 0 part /mnt/sdb15
The example output above shows that the system partition is mounted on /mnt/sdb1.
If your VPS is of the current ranges, the MOUNTPOINT
column should be empty. In that case, mount the partition first:
~$ mkdir -p /mnt/sdb1
~$ mount /dev/sdb1 /mnt/sdb1
You now need to edit the root directory to apply the changes to your system. You can do this by using the chroot
command:
~$ chroot /mnt/sdb1/
You can check by typing the ls -l
command, which will list the content stored in the current directory of your system:
~$ ls -l
In the last step, change your password with the passwd
command.
~# passwd
New password:
Retype new password:
passwd: password updated successfully
If your VPS is of the current ranges (naming scheme: vps-XXXXXXX.vps.ovh.net), you have initially received login credentials for a user with elevated permissions instead of the default "root" account. Additionally, the SSH service is not accepting login requests as root.
It is therefore necessary to enter the username you actually use to log in after passwd
:
~# passwd <username>
New password:
Retype new password:
passwd: password updated successfully
This will ensure that you can log in again with this username after rebooting, in case root login is disabled.
Finally, reboot your VPS in 'normal' mode in your OVHcloud Control Panel.
If your VPS is of the current ranges (naming scheme: vps-XXXXXXX.vps.ovh.net), you have received login credentials for a user with elevated permissions instead of the default "root" account. Additionally, the SSH service is not accepting login requests as root.
Enabling root logins is usually regarded as a security vulnerability and is therefore not recommended.
We recommend taking measures to secure your VPS first. You can refer to our guide on Securing a VPS.
Use a text editor such as vim or nano to edit this configuration file:
~$ nano /etc/ssh/sshd_config
Add the following line.
PermitRootLogin yes
Look for this line and make sure it is commented out:
#PermitRootLogin prohibit-password
Save the file and exit the editor.
~$ systemctl restart sshd
This should be sufficient to apply the changes. Alternatively, reboot the VPS (~$ reboot
).
If you encounter boot issues after you have changed your password and initiated the reboot:
Join our user community on https://community.ovh.com/en/.
Please feel free to give any suggestions in order to improve this documentation.
Whether your feedback is about images, content, or structure, please share it, so that we can improve it together.
Your support requests will not be processed via this form. To do this, please use the "Create a ticket" form.
Thank you. Your feedback has been received.
Access your community space. Ask questions, search for information, post content, and interact with other OVHcloud Community members.
Discuss with the OVHcloud community