Wednesday, May 31, 2017

CentOS: Reset Root Password in CentOS 7




There are times that you want to copy a VM and paste it to your machine. The problem is you don't know the root password of the VM. Resetting CentOS root password is easy, like all other Operating System. But you need to have a physical access to the server not remotely access to server. Because when you access the server remotely, you will not able to see the boot message screen which is crucial in resetting the server. In this tutorial, I'm using Virtualbox to access my CentOS, and you can also try this if you installed it on your PC/server directly. Be aware that I'm using CentOS verision 7 in this tutorial, CentOS version 6 below have different approach in resseting root password. 

1. Restart the CentOS Server Or Start the CentOS server . If you are using VirtualBox click on Machine-> Reset Host. If you are using your PC, you can start it by pressing the start button in your physical machine (CPU).



2. As soon as the boot starts, press 'e'. Be aware of the boot message, you need to see this message below in order to get into the next step. Be alert in this step because if you failed to press 'e', it will eventually leads to login screen which is not our purpose. So If you faild to press 'e', you need to start the machine again.


3. Find the word  ro and replace it with rw init=/sysroot/bin/sh. You need to scroll down a little bit to find the word ro and after that, you can replace it by backspace and replace it with rw init=/sysroot/bin/sh. Take note that there is only one ro word in message, so there is no duplicate in it. 

find ro
replace with rw init=/sysroot/bin/sh
4. Press Control + X to redirect to single user mode and add this line below. In this step, you are now outside the boot message. You are now going to change the root password my using the command below. 

chroot /sysroot
passwd


5. Finally, you can now use your new root password by restarting the system. You can restart the system by using command reboot or poweroff and start the OS again or halt and start the OS. If you are not using virtualbox, you can restart the system by pressing the restart button on your CPU. After you restart, you can now use your new password. Feel free to ask questions if you have problem with the steps that I mentioned here. 

reboot

No comments:

Post a Comment