Recovering From A Lost root Password

Told you to write it down, didn’t I? But if your security nerves cringed at the idea, I don’t blame you. There is a way to recover if you’ve flatly lost it.

You’re going to need one of the emergency systems discussed on the previous page. Have one, and boot to it.

Mount the main system’s filesystem, or at least the root of the filesystem ( / ). Open, in your preferred text editor, the /<your_mount_point>/etc/shadow file (if you’re using shadow passwords) or, in some cases, the /<your_mount_point>/etc/passwd file (if you’re using NIS, for instance). Now you have to find the line holding root’s password:

root:$1$lkjh08jern0<long hash value>…

Note that this line is colon-delimited fields; you want the second field. It usually begins with $1$.

Delete this field. Be careful; leave the colons on either side. Now root can log in with no password. Yes, this is scary.

Disconnect the workstation from the network! Reboot to the workstation’s main file system (not your rescue CD or partition or what have you). Log in as root with a blank password. Change this password immediately.