Recovering Root Password

Solution 1:

On most Linux systems from the console if you press CTRL-ALT-DEL the command shutdown -r now will be executed and cause a reboot of the system. If your init scripts are setup properly this should result in a safe restart. You could modify your inittab to make CTRL-ALT-DEL do whatever you want including switch into single user mode. Once your are rebooted you can use a livecd, boot to single user mode or whatever you like. You should test in advance if the root password is required to enter single user mode on your system. On some system it is not (Ubuntu/Debian when the root password is disabled) on others it is required.

If your system uses init then /etc/inittab

# What to do when CTRL-ALT-DEL is pressed.
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

For systems with upstart then check the file /etc/event.d/control-alt-delete

# control-alt-delete - emergency keypress handling
#
# This task is run whenever the Control-Alt-Delete key combination is
# pressed.  Usually used to shut down the machine.

start on control-alt-delete

exec /sbin/shutdown -r now "Control-Alt-Delete pressed"

Solution 2:

Some ideas to avoid being bored with lost root passwords :

  • Don't use the root account, but your sudo-enabled user account.
  • Manage your servers with Puppet. Only change your root passwords with Puppet. That way, even if you lose your root password(s), you just have to modify the password(s) in the Puppet manifests, and wait till your servers fetch it.
  • Configure your servers to allow authentication based on LDAP.