How to Reset Password in Linux

How to Reset Password in Linux

We may lose our access to the server because of different issues, and the most common and easiest reason is forgetting it. Fortunately, it is always possible to recover the password of your Linux OS. Linux has different distributions, and for each distribution, there is a way to reset the password.

Totally, we recover the password using the single user mode on all of the distributions.

Note: Before starting, consider that you should have Console Access or VNC access to the server to log in to the single-user mode. This interface enables you to access the server console even if you don’t have access to it over the network connection.

If you have your own machines, you already have access to the console. Or, if you have lost the password of your Linux virtual private server, you can grant this access from your client area, or if you don’t find it, ask it from your Linux VPS provider.

To reset the password, you need to go into the single-user mode. This mode is used for debugging, and basic services will run when you log in to this mode. And also, you can use this mode to reset the password of your Linux system, which we need it.

Reset password in CentOS 6

To login into a single-user mode in CentOS 6, you have to stop the bootloader process. Open the console, reboot the machine and stop the booting process by pressing the Space key. Now press the A to be able to modify the setting.

 

Login to single user mode to reset password in centos 6

 

On the new page, add a space and type 1, and press enter. Now the system will automatically reboot and login to the single-user mode.

 

login to single user mode

 

On the new page, we will use the passwd command to change the password. Consider that you cannot see the password text when changing the password because of the security measures.

 

reset the password in centos 6

 

Now, reboot the operating system using the reboot command or the reboot button on top of your console, and you will be able to log in using the new password that you set.

Reset password in CentOS 7 and CentOS 8

To login into the emergency mode in CentOS 7 and reset the password, you have to stop the bootloader process. Open the console, reboot the machine and stop the booting process by pressing the Space key. Now press the E to be able to modify the setting.

 

Stop boot loader process in centos 7

 

Use the up and down arrows to scroll and find the ro word.

 

change arguments to reset pass in centos 7

 

Please change it to rw init=/sysroot/bin/sh and press ctrl + x simultaneously to go to the emergency mode automatically.

 

Change read and write permissions and add init process to the sysroot

 

On the new page, change the directory to sysroot using the following command.

chroot /sysroot

And use the passwd root command to change the root password. Reboot the machine, and you will log in using the new password you’ve set.

 

reset CentOS 7 server password in emergency mode

 

Reset password in Debian 9 and Debian 10

After you buy Linux VPS, such as Debian, you may forget the server’s password for any reason. To reset the password in Debian, reboot the server and stop the automatic boot by pressing the Space key. Once you did it, you should see the Grub section in the following picture.

 

grub in debian 9

 

Now, press e to be able to edit the grub file. Find the line finishing with ro quiet and add init=/bin/bash to the end of it.

 

edit grub menu in Debian

 

Finally, press the control + x buttons simultaneously to log in to the single-user mode.

Enter the following command to adjust the permissions.

mount -n -o remount,rw /

And use passwd command to change the password.

 

change permissions and change password in debian 9 and debian 10

 

Reset Password in Ubuntu 18 and Ubuntu 20

To change the password of ubuntu 18 or ubuntu 20, like the other operating systems, we need to log in to single-user mode. To do this, reboot or start the server and stop the booting process by pressing the Space key.

 

Grub menu in ubuntu

 

Once it was stopped, press the e button to be able to edit the Grub Menu.

 

edit ubuntu grub Menu

 

Find the ro and change it with the rw init=/bin/bash and consider that the line should be finished with the mentioned parameters so change the ro and any other sentences after the ro with rw init=/bin/bash

 

change ro to rw in Ubuntu to reset password

 

Type the following command to modify the permissions.

mount | grep -w /

Once you did it, you should see the message (rw, realtime).

Change the password using passwd command and reboot the server.

 

change password in ubuntu18 and ubuntu 20

 

Summary

This article checked how to change the password on all Linux versions such as Ubuntu, Debian, and CentOS. In this process, we logged in to the single-user mode and reset the password there.

We hope you have enjoyed this post and found it useful.

Leave a Reply

Your email address will not be published. Required fields are marked.