Debiana

Reset Root Password Debian

Reset Root Password Debian

How to Reset the Root Password on Debian 9 Stretch

In this article, I will show you how to configure sudo, set root password, disable root login and reset root password. This can be done even if you don't have sudo enabled and you don't remember the password.  Let's get started.

Installing and Configuring sudo

If you have set up a root password while installing Debian 9 Stretch on your machine, then there's a chance sudo won't be configured. So you won't be able to run any commands as root user if you're logged in as an ordinary user.

In this section, I am going to show you how to install and configure sudo to run commands as root user without login in as user root.

First log in as root with the following command:

$ su -

Now type in your root password and press .

You should be logged in as root user.

Now update the apt package repository cache with the following command:

# apt-get update

The apt package repository cache should be updated.

Now install sudo with the following command:

# apt-get install sudo

It should be installed. In my case it is already installed.

Now to add your ordinary user, let's say shovon to the sudoers file, run the following command:

# usermod -aG sudo shovon

NOTE: Here shovon is an ordinary user account on my Debian 9 Stretch system.

Now exit out of the root user with the following command:

# exit

Now the ordinary user shovon can run any command as root using sudo as follows:

$ sudo ls /var/log

Enter the login password of user shovon and press .

The command should run as root as you can see from the screenshot below.

Setting Root Password

If you haven't set a root password while installing Debian 9 Stretch, then root password by default won't be set. But sudo should be configured for your ordinary user.

To set a root password then, run the following command:

$ sudo passwd

Now type in the password for your logged in user and press to continue.

Now type in your desired root password and press .

Now retype the root password and press .

The root password should be set. Now you can login as root using your root password.

Changing Root Password

If you want to change the root password, all you have to do is run the following command again:

$ sudo passwd

Now do the same things as you did on the Setting Root Password section of this article.

Disabling Root Login

If you don't want to allow root login, then you can lock the root account with the following command:

$ sudo passwd -l root

To allow root login again, just set a root password again. For more information, take a look at the Setting Root Password section of this article.

Recovering Lost Root Password

If you happen to forget the root password and you don't have sudo configured, then don't give up just yet and think about reinstalling the operating system again. There is a way to reset the root password.

First reboot your computer. You should see the GRUB menu when your computer boots as shown in the screenshot below. Select Debian GNU/Linux and press e.

You should see the following window. Now go to the end of the line as marked in the screenshot below.

Now remove 'ro quiet' part from the end of the line and append 'init=/bin/bash' to the end of the line as marked in the screenshot below. Once you're done, press F10.

You should see the following window.

Now run the following command to remount the root (/) partition as readable and writable:

$ mount -o remount,rw /

Now run the following command to remount the /proc filesystem:

$ mount -o remount,rw /proc

Now to reset the root password, run the following command:

$ passwd

Now type in your new root password and press to continue.

Now re-type your new root password and press to continue.

You root password should be changed.

Now press + + and your Debian 9 Stretch machine should reboot.

Now you can login as root with your new root password as you can see in the screenshot below.

Before Login:

After Login:

This is how you reset your root password on Debian 9 Stretch. Thanks for reading this article.

Middle mouse button not working in Windows 10
The middle mouse button helps you scroll through long webpages and screens with a lot of data. If that stops, well you will end up using the keyboard ...
How to change Left & Right mouse buttons on Windows 10 PC
It's quite a norm that all computer mouse devices are ergonomically designed for right-handed users. But there are mouse devices available which are s...
Emulate Mouse clicks by hovering using Clickless Mouse in Windows 10
Using a mouse or keyboard in the wrong posture of excessive usage can result in a lot of health issues, including strain, carpal tunnel syndrome, and ...