It is recommended to avoid using root account frequently and this does cause trouble when admins suddenly would like to connect to a box under root account. One of the best ways to recover a forgotten root password is to use another account that has sudo privilege and can reset password for root. I am using my own account ‘nick’ in the below example:
Step 1:
Log on as ‘root’ and then create ‘nick’ account with strong password
useradd nick
passwd nick
Step 2:
Open visuo by running the below command
visudo
And then like you are using VIM, add one line at the bottom of the file
nick ALL=(ALL) ALL
Step 3:
You can log off ‘root’ and log on as ‘nick’ now and type
sudo su -
Then you become ‘root’ immediately and by using
passwd
you can easily re-set password for ‘root’.
All above 3 steps are well tested on CentOS. Hopefully this can be helpful.
Leave a Reply