Linux 101: How to Recovery Forgotten Root’s Password

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


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


you can easily re-set password for ‘root’.

All above 3 steps are well tested on CentOS. Hopefully this can be helpful.


About Nick Xu

Not a DBA anymore
This entry was posted in Linux and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s