Skip to main content

Resetting the root password on RHEL 7 Systems

How to Reset Root Passwords on RHEL 7 and CentOS 7 Linux Systems

If you have forgotten your root password on a RHEL 7 server or a CentOS 7 server, you can reset your root password as long as you have access to the GRUB 2 bootloader. (The following example was performed on a RHEL 7.5 server)
To access the GRUB 2 bootloader, boot your system and wait for the GRUB 2 menu to appear:

Boot System and wait for GRUB 2 menu

Boot your system and wait until the GRUB2 menu appears. On some systems you may need to press the "Escape" key to access the GRUB 2 menu.



Highlight OS Entry

Highlight your Operating System and then press "e" to edit.


Find line beginning linux


Find the line beginning with linux. In this example the line begins linux16.


Manually Edit Line


Using the arrow keys and the delete key, manually delete the following entries rhgb and quiet from the line.

Next, append the following statement to the end of the line init=/bin/sh

Don't worry if your command is spread across more than one line. A continuation character "\ will be inserted automatically.


Ctrl +X to reboot using the specified options


To reboot your system now using the options specified, press the keys Ctrl +X

Once the system has re-booted, you will be presented with a shell prompt without having to enter any user name or password information

At this command prompt you will need to enter the following commands below:

Load Local SELinux Policy


Load the installed SELinux policy: /usr/sbin/load_policy -i

Remount "/" Filesystem in Read/Write mode


Remount the "/" root filesystem in Read/Write mode: mount -o remount,rw /

Issue passwd Command


Issue the passwd command to reset the root account password: passwd

Remount "/" Filesystem as Read Only


Remount the "/" root filesystem in Read Only mode: mount -o remount,ro /


Now reboot the system


You can now reboot the system. You can issue the command "exec /sbin/init 6" to reboot.

Once your system is backup, you should be able to login with the new "root" password.

Login with New Password


You should now have arrived at the login screen. Here you will be able to login with your root account using your new password. (You may need to login as a normal user then "su" to root depending on your system set-up)

Comments

Popular posts from this blog

Cheat Sheet

Bash: echo $? - exit status of last command (0 no error) ' - Single quote removes meaning special meaning of special character. find /qwe -type f -iname *.js -exec cp --parents -t /tmp/ {} + -- find all js files and copy with parent directory ystemctl set-default graphical.target (ls -l /lib/systemd/system/runlevel*) -- set runlevel echo <password> | sudo -S for i in t@01 st@02 ba@sta03;do ssh -o RequestTTY=true $i "sudo -l";done -- allow tty present VIM: :r! sed -n '16,812 p' < input_file.txt -- copy line range from input_file :1,10d -- delete line from 1 to 10 :se nu -- show line numbers Apache: Redirection in Apache (By default, the Redirect directive establishes a 302, or temporary, redirect.): URL:https://www.digitalocean.com/community/tutorials/how-to-create-temporary-and-permanent-redirects-with-apache-and-nginx <VirtualHost *:80> ServerName www.domain1.com Redirect 301 /oldlocation http://www.domain2.com/newlocation </VirtualHo

Salt -- cheat sheet

      The Salt system is a Python-based open-source remote execution framework for configuration management, automation, provisioning and orchestration.  A basic Salt implementation consists of a Salt master managing one or more Salt minions.

Euro trip. Chapter1: Bucovice-Prague-Nuremberg-Leipzig-Dresden

    Begin to write something every time is complicated for me. Any way i should start. So this trip was somehow unplanned. Where to go, stay ... everything planned on way.    Trip started 2nd of July from Bucovice to Prague. Made reservation on "Hotel Globus" for one night. After check-inn we went to centre walk, see landmarks  of Prague. Additional we have a lunch at asian cafe.     3rd July. Next our plan was drove from Prague to Munich stay one night in camp hostel, visit Munich Zoo. But plans changed on way and we decided drove first Nuremberg to see my friend. Made reservation at "Azimut Hotel". As we arrived earlier check-inn was after 3PM, parked car and we decided not to waste time go and see Nuremberg. We have a lunch some soup and german sausage. And also for 30 euros we took city tour by bus about 2 hour. We saw almost whole city with information (recommended). Evening we meet my friend have a lunch thanks special thanks Fagani. Before driving to Leipzig