This guide explains how to reset your user account password if you have lost access to your server.
Without a different mode of authentication or another user account, losing your password means you can no longer log in to your server in a regular way.
In this case, you can connect to your server via the OVHcloud rescue mode, which allows you to log in with a provisional password and modify your files.
To recover access to a server that you log in to with an SSH key, refer to our guide on How to replace an SSH key pair instead.
Requirements
- A dedicated server or a VPS with a Linux-based OS in your OVHcloud account
- Access to the OVHcloud Control Panel
This guide does not apply to Windows server installations. Please refer to our guides on How to change the admin password on a Windows dedicated server and How to change the admin password on a Windows VPS.
Instructions
Be sure to consult our "Getting started" guides as well:
- For a dedicated server
- For a dedicated server of the Eco product line
- For a VPS
This tutorial is designed to help you as much as possible with common tasks. If you are having difficulty performing these actions, please contact a specialized service provider. OVHcloud can't provide you with technical support in this regard.
Step 1: Restart the server in rescue mode
Use the corresponding rescue mode guide to connect to your server and mount your partitions:
Dedicated server
See the full Dedicated server rescue mode guide here.
Unless you intend to configure the server's disks in a way that requires them to be detached (unmounted), you need to first mount the system partition in order to access your data from rescue mode.
Firstly, list all partitions to retrieve the name of the partition you need to mount:
Output examples:
Then mount the pertinent partition accordingly:
The partition to mount should be easily identifiable by the SIZE indicated in the table (sda2 in the first example, nvme1n1p3 in the second). Using the folder name mnt as mount point, for the first example the mount command would therefore be as follows:
Command to enter for the second example:
NOTE: The examples above illustrate the necessary steps based on a typical server configuration. The information in the output table depends on your server's hardware and its partition scheme. When in doubt, consult the documentation of your operating system.
If you require professional assistance with server administration, consider the details in the Go further section of this guide.
To see more technical information about the server's disks and partitions, enter:
Some tasks may require that disks or partitions be detached. To do this, use the unmount command:
VPS
See the full VPS rescue mode guide here.
Once you have successfully accessed your VPS via SSH, the first step will be to mount the partition to the Rescue Mode environment. We can find out which partition we need to mount using the following command:
# lsblk
Here is a sample output of this command:
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 20G 0 disk
├─sdb1 8:17 0 19.9G 0 part
├─sdb14 8:30 0 4M 0 part
└─sdb15 8:31 0 106M 0 part
This VPS has 20 GB of storage space. That means that the partition we need to mount is sdb1 since it contains 19.9 GB of storage and thus, contains the Linux filesystem. This partition will be in the /dev directory by default.
NOTE: The name of your partition may be different, so follow the output of your system. In this article, we will call it sdb1.
After identifying the storage device, create a root directory within the /mnt directory, and then use the mount command to mount the partition to the Rescue Mode environment:
# mkdir /mnt/root
# mount /dev/sdb1 /mnt/root
Now, navigate to the newly mounted device and then use the chroot command to give yourself root access to the mounted filesystem:
# cd /mnt/root
# chroot /mnt/root
Now, we can change the root password using the following command:
# passwd
If you wish to change the password for a different user, just append the username to the end of the above command, and it will change the password for that user. If you don't specify a user, as we did above, you are changing the root password by default.
NOTE: If you are using a Red Hat based OS (e.g., CentOS, Fedora, AlmaLinux, Rocky Linux, etc.), you will need to perform one additional step here. Run the command touch /.autorelabel to make the OS reset SELinux contexts on boot.
Exit Rescue Mode and reboot your server. If you did everything correctly, your new password will grant you access to your live server environment.
WARNING: To proceed, your system partition must be mounted, and you must have write access to your file system. See the accordion menus above for instructions for mounting a partition.
This means that you have entered a version of the following command into the rescue mode shell:
The exact command depends on the mountpoint you used. For example, if you have mounted your partition at /mnt, it would be the following:
Step 2: Identify the user account(s) and reset the user password
After mounting the partition and running chroot /mnt (or the equivalent), you have root privileges on the mounted system.
If needed, before changing a password, identify existing accounts using the following command:
Example output (shortened):
Find your user name(s) in the list of accounts.
To change the password for a specific account (e.g. ,user1), enter this command:
Enter the new password twice and confirm:
On a GNU/Linux distribution, a password prompt does not display your keyboard input.
Avoid running the passwd command without arguments: This command modifies the password of the current account, which is root after executing chroot.
Always specify passwd <user>.
Remember to use the regular boot mode of your server when restarting it in your OVHcloud Control Panel.
Refer to the corresponding rescue mode guide if necessary.
The modified user account now has access to the server with the new password.
Go further
How to configure user accounts and root access on a server
For more information and tutorials, please see our other Dedicated Servers support guides or explore the guides for other OVHcloud products and services.