How to change Linux root password temporarily
If you are logged in as root and you don’t know the root password then you can follow the steps. You can easy to change your root password.
Step 1. Back-up your current shadow file.
[ROOT@dollar1hosts ~]# CP /ETC/SHADOW /ETC/SHADOWBKUP
Step 2. Change the current root password
[ROOT@dollar1hosts ~]# PASSWD ROOT
CHANGING PASSWORD FOR USER ROOT.
NEW UNIX PASSWORD:
BAD PASSWORD: IT IS BASED ON A DICTIONARY WORD
RETYPE NEW UNIX PASSWORD:
PASSWD: ALL AUTHENTICATION TOKENS UPDATED SUCCESSFULLY.
Step 3. Switch to a local user to test whether ‘your’ root password is working or not.
[ROOT@dollar1hosts ~]# SU – LOCALUSER
[LOCALUSER@dollar1hosts ~]$ SU – ROOT
Yes, you are now logged in as root with ‘your’ password.
Step 4. Restore the previous root password
[ROOT@dollar1hosts ~]# MV /ETC/SHADOWBKUP /ETC/SHADOW
MV: OVERWRITE `/ETC/SHADOW’? Y
This trick is meant for students and kindly do not misuse.