Tuesday, 4 December 2018

Linux tutorial | How to reset root password in centos


In this tutorial, I am going to show you how you can easily change the root password and add new users in centos 7.

Part 1:  Change root password


1.1 Once you are in the grub menu, you will have to enter into the edit option by pressing 'e'.


1.2 You will have to find the 'ro' near the line 'Linux 16' and change it to 'rw init=/sysroot/bin/sh'





1.3 Press 'control + x' to enter into single user mode.




1.4 Now you can access the system using this command :
chroot /sysroot

1.5 Reset the root password:
$  passwd root

Choose any password.

1.6 Exit chroot
$  exit

1.7 Reboot your system
$  reboot

Now you are good to go with the new password.


Part 2:  Add a new user in the single user mode without root access.


You need the follow the above steps until step 5.

2.1 Create a new user account using 'useradd', replace <username> with the name you want.
$  useradd <username>

2.2 Use the 'passwd' to set a password for the new user
$  passwd <username>

2.3  Now you can add the new user to the wheel group to get root privileges using 'usermod'
$  usermod -aG wheel <username>

2.4 Then reboot the system
$  reboot

Conclusion

That`s all. You have successfully reset root password and create a new sudo user on a CentOS system.

Feel free to leave a comment if you have any questions.

Linux tutorial | How to reset root password in centos

In this tutorial, I am going to show you how you can easily change the root password and add new users in centos 7. Part 1:  Change ro...