Lost Root Password

This was a post by Paul Brook to the mailing list when we discussed accessing system files on a Kubuntu box without root or su access.

For the record, this is how to (re)set a root password without using a live cd: Add


to your kernel commandline. If you're using grub then pressing "e" will allow you to temporarily edit a menu item. This should get you to a shell, bypassing all the init scripts, including the ones that ask for a password ;-) At this point you probably can't change anything because the root filesystem will still be mounted readonly. To fix this do:

 mount -o remount,rw /

If it's on a separate partition you probably also need to mount /usr: Most Ubuntu systems probably put everything on a single partition, so you can skip this. Technically /usr/bin isn't essential, it just has useful things like vim and passwd. Without it you may have to resort to editing files with sed.

 mount /usr

You should then be able to reset the root password, either by typing "passwd",or by hacking /etc/shadow.