

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Reset the root user password on rhel7 xcentos7 x
This article will be helpful if we forget the root password on Centos 7.x or RHEL 7.x. In the previous version of RHEL, we can easily break the root password, as by default SE-Linux is enabled. Also note that, RHEL has brought many special new features.
Resting the Root Password
Reboot/Restart the system.
Press ‘e‘ at the grub boot menu to edit the default boot menu.
This screen looks like this for RHEL 7.x –
Press us thr down arrow key to find the line which contains similar to the ‘linux16 …… rhgb quit …..” and replace the ‘rhgb quiet’ words with ‘init=/bin/bash’. Once we edit the line just press Ctrl – x to boot the system and after editing the line, it should be looking like the below image –
Once the system gets to boot in a single mode, we needed to run the below command to confirm and rest of the root password.
Mounting the Root Partition in Read/Write Mode
Run the below command to confirm that –
# mount | grep root rootfs on / type rootfs (rw) /dev/mapper/centos_centos--linux--1-root on /sysroot type xfs (ro,relatime,attr2,inode64,noquota) :/#
To mount the root partition with Read/Write flag, we can use the below command –
# mount -o remount,rw /
To confirm that the file system is mounted to read / write mode, run the below command –
# mount | grep root rootfs on / type rootfs (rw,realtime) /dev/mapper/centos_centos--linux--1-root on /sysroot type xfs (ro,relatime,attr2,inode64,noquota) :/#
Changing the Root Password
Now, we can proceed to the actual password recovery. Run the below command –
# passwd New password: Retype new password:
SELinux Relabeling
This step regarding SELinux enables the Linux systems to relabel the SELinux to login with our new root password. Run the below command to ensure that the SELinux conetxt so that the entire system is rellabeled after the system reboot.
# touch /.autorelabel
Rebooting the System
Run the below command to reboot the system on RHEL
# exec /sbin/init
After successful execution of the above command, we can now able to reset the password for RHEL / CentOS 7.x like this. We can restore the last root password on CentOS /RHEL 7.x Linux systems.
- Related Questions & Answers
- How to reset or change the MySQL root password?
- Reset Kali Linux Password
- How can we change MySQL user password by using the SET PASSWORD statement?
- Resolve error 1045 (28000) access denied for user 'root'@'localhost' (using password: YES)?
- How can we change MySQL user password by using the ALTER USER statement?
- Resetting a Root Password in Linux without External Media
- How to change the password in MongoDB for existing user?
- How to change the local user account password using PowerShell?
- How can I restore the MySQL root user full privileges?
- Running Docker Container as a Non Root User
- Create a new user with password in MySQL 8?
- How do I change a MongoDB user's password?
- Apply the Group Accumulator Operator $first on the system variable $$ROOT to return reference to the root document?
- How can we change MySQL user password by using UPDATE statement?
- Set special characters for password while creating a new MySQL user?