Wesbytes Knowledge Base

Search our articles or browse by category below

Changing Root Password on Linux Dedicated Server

Last modified: June 17, 2022
You are here:
Estimated reading time: 1 min

When you install or reinstall a distribution or operating system, a root access password is provided. It’s recommended to change it to secure your Dedicated Server. You may also find that you have lost this password, or need to change it.

To change the password after you lost it:

  1. Firstly, put your server into rescue mode.

  2. Then, identify the system partition with the following command:
    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.

  3. Next, mount the system partition using the following commands:
    # mount /dev/hda1 /mnt/
  4. By default, the system partition is locked for editing. You need to enable it to write access:
    # chroot /mnt
  5. Lastly, change the password:
    # passwd
    
    Enter new UNIX password:
    Retype new UNIX password:
    passwd: password updated successfully
    When this is done, change the boot mode on your server back to boot from hard disk and restart it. Your root password is successfully changed.
Was this article helpful?
Dislike 0
Views: 50