How to reset your root password for Linux operating systems

Support Article

This guide will show you how to reset a forgotten/lost password when the server is running a Linux/Unix based operating system like CentOS/Ubuntu/Debian

Provisioning into Rescue System

  1. Head over to the Zare control panel and click manage on the server you wish to reset the password on. You will now need to provision this server into rescue mode by clicking the provision tab and selecting "Sysrcd 5.1.0 [rescue system]". The server will being to provision into rescue mode and you will receive a temporary login after 5-10 minutes on your email.
  2. Using SSH, login with the temporary credentials and you will see a similar layout to normal command line/SSH terminals.

Mounting your disk

  1. You will now need to mount your primary operating disk into a temporary directory. This allows you to access your operating system and issues commands to reset your password, simply using passwd. You can find your primary drive (usually /dev/mapper/vg-root in CentOS, /dev/sda5 in Debian and Ubuntu or /dev/md1 in Intel RAID-1. As many setups vary, its hard to tell you exactly where the root partition is, so you will usually want to look for the biggest one or try a few) by using the following command
    fdisk -l

  2. Next step is to mount that disk so that you can access it. You can do this by using the following command (change the /dev/mapper/vg-root part to whatever your primary operating system disk is). This command does the following 1. Creates a new directory called rescue in mtn 2. mounts your primary drive onto the newly made directory. 3. Set the root environment as the mounted drive.
    mkdir /mnt/rescue mount /dev/mapper/vg-root /mnt/rescue chroot /mnt/rescue /bin/bash

  3. Now to change the actual root password. Execute the following command and you will be able to set a new password for the root user.
  4. passwd

Cleaning up

  1. To finish we have to now clean up and reboot the server, execute the below commands.
  2. exit umount /mnt/rescue reboot -n

Unable to find the answer you're looking for? Get in touch today!

Get in touch