Resetting root password in Centos 7


INTRODUCTION

  Resetting root password in earlier versions of Centos / RHEL is bit simple by going into single user mode. But is Centos 7 there is no single user mode. For resetting password it involves several steps and need to relable selinux context's. But I will tell you easy way to reset root password in Centos 7 without need to relable selinux context.

Procedure

1) Start the system and on the grub2  boot screen press e to edit .

2)  Find the line starting with linux16 or linuxefi on UEFI system. Go to end of the line by pressing      end button.

3)  At the end of line enter text  as shown in bellow screen shot.


rd.break will interrupt the boot process before control is passed from initramfs to systemd.

4) Here, you will not get any option of press b to boot. You have to press ctrl+x to boot the system.

5) Once, system boot you will get shell prompt. The file system will be mounted on /sysroot/ in read only mode you will not allow to change password if filesystem is in read only mode so we will mount file system in read-write mode.


switch_root:~]# mount -o remount,rw /sysroot
6)  After mounting file system in read-write mode. Change the file systems root as follow:

switch_root:~]# chroot /sysroot/
After changing file systems root you are free to make changes as required. There are other ways to but it requires relabeling of selinux context which is time  consuming. So I use this simple way to resetting password.




Comments