in Python

AutoRoot – Automatically Reset The root Password On Linux Machines

AutoRoot will scan for any logical volume containing the word root or for block devices starting from /dev/sda1…/dev/sda10, /dev/sdb1…/dev/sdb10, /dev/sdc1…/dev/sdc10, it will then try to mount the volume and check for the password file,if found, it will change the root password to:

This started as a simple exercise to get familiar with the python subprocess module, then things got interesting. I thought it ill be useful if I can automate the reset of the root password on various Linux distribution.


How it Work ?

The script is written in python and need to be added to the iso image of system rescue cd which can be found on
To automate the script execution, an autorun file need also to be added to the iso image, this autorun file is used to run

autorun content

python /livemnt/boot/

After the machine reboot using the iso file, the AutoRoot script will take care of looking for the root file system, chroot to it and then change the password, after that all you need to do is reboot your machine without the cdrom attached.

On which Linux distribution it work ?

I have tested it, and it successfully/automatically reset the root password on the following distribution, using Logical Volume or block devices

  • Debian 8.5.0
  • Linux Mint 17.3 cinnamon 32bit
  • Ubuntu 16.04 server
  • Fedora 23
  • CentOS 6.7

How to Use it ?

You have two options here:

  1. I have already prepared an iso image of system rescue cd which contain the required files ( and autorun), I have also modified the isolinux.cfg file so the machine will reboot without needing your interaction. You can download the ready-to-use iso image.
  2. Download the iso image directly from and then put and autorun on the root directory of the iso image, for Windows users, you can use a tool like WinISO to do this, then reboot, auto-hack and enjoy.

If everything goes perfectly, you should see a screen like this

reset root password on linux centos

To-Do List

  • The fun part: Adding Windows support 😀
  • Rewrite the script
  • Stripe down the system rescue CD size.
  • Add more Linux distribution/configuration support

Share your thoughts