reset root password in ubuntu

How to Reset Root Password in Ubuntu

Sometimes you may need to reset root password because you may have forgotten or misplaced it, or for some other reason. In this article, we will look at how to reset root password in Ubuntu / Debian systems. For this purpose, we will need to make use of GRUB boot loader, since root password can be reset only at boot time. GRUB is basically a mult-option boot loader that allows you to do many things before system boot, including pause system boot and reset password. It is the first software to be loaded, even before your operating system. So we need to use GRUB to change password before initializing Ubuntu.


How to Reset Root Password in Ubuntu

Here are the steps to reset root password in Ubuntu.


1. Boot/Reboot your system

If your system is running reboot it. Else just boot it on. When the system is booting up, press Shift key on your keyboard immediately to open up the following menu on your screen. It is the GRUB boot menu.


2. Choose OS

You can navigate between the options using up/down arrow keys. Use it to go to option ‘Ubuntu’ and press ‘e’ to edit its settings. You will see the following screen.


3. Make Changes

Again use up/down arrow key to navigate through your screen. Locate the line that starts with ‘linux’. Locate the section that reads ‘ro quiet splash $vt_handoff’ and change it to ‘rw init=/bin/bash’

linux              /boot/vmlinuz-4.10.0-20-generic root=UUID=735db898-\
1af3-269a-3acf-41164ca4efc9  rw quiet splash $vt_handoff

to

linux              /boot/vmlinuz-4.10.0-20-generic root=UUID=735db898-\
1af3-269a-3acf-41164ca4efc9  rw init=/bin/bash

After you make the change, press Ctrl+X or F10 to reboot the system again with new settings. This time it will boot you to a bash terminal. Check that your disk partition is in read-write mode by running the following command.

# mount | grep -w /

You will see the following output.

The last line of the output will contain your disk label, with its type and permissions

/dev/sda1 on / type ext4 (rw, relatime, data=ordered)

In the above message, the part ‘rw’ indicates that your disk is in read-write mode.

Reset password with passwd command.

passwd

You will be asked to enter new password and retype it again for confirmation.

Now reboot the machine with following command.

# exec /sbin/init

This time don’t press any key during bootup. Let it boot as usual. You will be prompted for password. Enter the new root password to log into your system

In this article, we have learnt how to reset root password in Ubuntu. As you can see, it is very tedious and tricky to reset the root password. You can easily change root password from terminal if you know your old password. Also, you can easily reset/change any other user’s password from terminal. But it is a headache to reset root password. So it is advisable to keep your root password always safe and handy.

Also read:

How to Sort CSV File in Python
How to Read Binary File in Python
How to Read User Input in Python
How to Empty List in Python
How to Open Image in Terminal

Leave a Reply

Your email address will not be published.