Instructions

Changing the password if you still have access (sudo user or root)

Log in to your server via SSH. Switch to the root user, if necessary:

~$ sudo su -
~#

To change the password of the current user, type passwd:

~# passwd

New password:
Retype new password:
passwd: password updated successfully

On a GNU/Linux distribution, the password you enter will not appear.

Changing the password if you have lost it

Step 1: Identify the system partition

After restarting your server into rescue mode, you will need to identify the system partition. You can do this with the following command:

# fdisk -l

Disk /dev/hda 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 1305 10482381 83 Linux
/dev/hda2 1306 4800 28073587+ 83 Linux
/dev/hda3 4801 4865 522112+ 82 Linux swap / Solaris

Disk /dev/sda 8254 MB, 8254390272 bytes
16 heads, 32 sectors/track, 31488 cylinders
Units = cylinders of 512 * 512 = 262144 bytes

Device Boot Start End Blocks Id System
/dev/sda1 1 31488 8060912 c W95 FAT32 (LBA)

In the example above, the system partition is /dev/hda1.

If your server has a RAID configuration, you will need to mount your raid volume.

  • If you are using Softraid, your root partition will be /dev/mdX.
  • If you are using Hardraid, your root partition will be /dev/sdX.

Step 2: Mount the system partition

Once you have identified the system partition, you can mount it with the following command:

# mount /dev/hda1 /mnt/

Step 3: Edit the root partition

The system partition is locked for editing by default so you need to open it for write access first, which you can do with the following command:

# chroot /mnt

Step 4: Change the root password

The final step is to change the password with the following command:

# passwd

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

When this is done, change the boot mode of your server back to Boot from the hard disk and restart it. Your root password will now be changed.

Was this answer helpful? 331 Users Found This Useful (5541 Votes)