Sometimes you forget stuff. I do. I forget important passwords for important websites sometimes. Retrieving your forgotten passwords for most websites are easy, all one have to does remember few details that were used when Signing up for the service to get a password of reset for an account.
the difference is forgetting a password to a system or device with no easy-to-reset it while locked out. CentOS 7 is one such system. If You forget the root password to your CentOS 7 machine, it's almost virtually impossible to reset it while you ' re locked Out.
This brief tutorial are going to show you a simple trick the can use of reset your forgotten root password for CentOS 7 servers. This would definitely come in handy for webmasters who is locked out of the Your CentOS machine and can ' t sign on.
This tutorial would only work if you had direct access to the machine or serial terminal access with boot menu options. You can ' t reset the root password if you ' re remotely connected since you need boot menu access.
To get started, turn on the machine so you ' ve forgotten the root password on. For CentOS 7 devices, you'll be given 5 seconds at the boot menu to select the operating system kernel to boot into.
That 5 seconds are important, because allows for admins to select different kernels or edit existing kernel parameters bef Ore booting.
At the boot menu, press e to edit the existing kernel (Core) as shown below.
650) this.width=650; "class=" AlignCenter size-full wp-image-31361 "src=" https://www.liberiangeek.net/wp-content/ Uploads/2014/09/centos7-forgot-root-password.png "alt=" changing root password on CentOS 7 "width=" 721 "height=" 385 " style= "padding:0px;border:0px none;margin:0px Auto;font-family:inherit;font-size:inherit;font-style:inherit; Font-variant:inherit;font-weight:inherit;line-height:inherit;vertical-align:middle;width:auto;height:auto; "/ >
next, scroll down to the list until you see the line underlined below (ro ). What the We need to does is the change of that RO to RW and the start into a bash shell. It should look like This RW init=/sysroot/bin/sh.
650) this.width=650; "class=" AlignCenter size-full wp-image-31362 "src=" https://www.liberiangeek.net/wp-content/ Uploads/2014/09/centos7-forgot-root-password-1.png "alt=" forgotten root password on CentOS 7 "width=" 721 "height=" 400 " style= "padding:0px;border:0px none;margin:0px Auto;font-family:inherit;font-size:inherit;font-style:inherit; Font-variant:inherit;font-weight:inherit;line-height:inherit;vertical-align:middle;width:auto;height:auto; "/ >
change the ro line to RW and add init=/sysroot/bin/sh
RW init=/sysroot/bin/sh
650) this.width=650; "class=" AlignCenter size-full wp-image-31363 "src=" https://www.liberiangeek.net/wp-content/ Uploads/2014/09/centos7-forgot-root-password-2.png "alt=" changing root password on CentOS "width=" 721 "height=" 400 " style= "padding:0px;border:0px none;margin:0px Auto;font-family:inherit;font-size:inherit;font-style:inherit; Font-variant:inherit;font-weight:inherit;line-height:inherit;vertical-align:middle;width:auto;height:auto; "/ >
after changing that, Press control + X or ctrl + X on your keyboard to start in single user mode using the bash shell specified above. In this mode, we ' re going to change the root password.
In the single user mode, run the command as shown below
chroot /sysroot
650) this.width=650; "class=" AlignCenter size-full wp-image-31364 "src=" https://www.liberiangeek.net/wp-content/ Uploads/2014/09/centos7-forgot-root-password-3.png "alt=" Password change on CentOS 7 "width=" 721 "height=" 402 "style=" padding:0px;border:0px none;margin:0px Auto;font-family:inherit;font-size:inherit;font-style:inherit; Font-variant:inherit;font-weight:inherit;line-height:inherit;vertical-align:middle;width:auto;height:auto; "/ >
finally, run the commands below to change the root password.
650) this.width=650; "class=" AlignCenter size-full wp-image-31365 "src=" https://www.liberiangeek.net/wp-content/ Uploads/2014/09/centos7-forgot-root-password-4.png "alt=" Change password on CentOS 7 "width=" 721 "height=" 98 "style=" padding:0px;border:0px none;margin:0px Auto;font-family:inherit;font-size:inherit;font-style:inherit; Font-variant:inherit;font-weight:inherit;line-height:inherit;vertical-align:middle;width:auto;height:auto; "/ >
You'll be prompted to create and confirm a new password. After creating the password, run the commands below to update SELinux parameters
touch /.autorelabel
Exit and reboot your system. You should is able to sign on and use the system with the new password you created. That's the root password on CentOS 7.
enjoy!
This article from "Vincent" blog, declined reprint!
How to Reset Your forgotten Root Password on CentOS 7 Servers