Wednesday, October 21, 2009

Recovering Linux root password

Many people have been getting in touch with me to recover the Linux Admin passwords of their systems. This is mainly because they have forgotten their Admin passwords (unused for long time surprisingly!!!) or the Admin Personnel has gone on leave or just disappeared!!!

The simple procedure explained below will hopefully sort out all your woes!!

First of all, you will require a Linux live CD (like the Ubuntu Live CD or my favourite 'Knoppix' CD. (download it free from here!!!). You can also use the convinient  bootable Linux USB pendrives too.

A long list of available (for free!!) Linux Live CD can be found here!!

"A live CD or live DVD is a CD or DVD containing a bootable computer operating system. Live CDs are unique in that they have the ability to run a complete, modern operating system on a computer lacking mutable secondary storage, such as a hard disk drive. Live USB flash drives are similar to live CDs, but often have the added functionality of automatically and transparently writing changes back to their bootable medium. The term "live" derives from the fact that these CDs each contain a complete, functioning and operational operating system on the distribution medium. While a live CD typically does not alter the operating system or files already installed on a computer's hard drive, many live CDs include mechanisms and utilities for altering the host computer's hard drive, including permanent installation. This is important for the system management aspect of live CDs, such as removing viruses, drive imaging, and system recovery." - from wikipedia

You will recreate a user that has administrative permissions on your server as mentioned below.
  1. Boot from a rescue CD such as a Knoppix Live CD or bootable pen-drive. It doesn't really matter what you use, as long as you can boot Linux and get access to a shell prompt. Make sure to mount the /dev and /proc directories and establish a chroot environment that points to your server's root directory. 
  2. You are now root on your server's file system. Use the passwd command to reset the password for the user root. From now on, you have re-established access to the root account.
  3. Reboot your server without the Knoppix CD and verify that you can log in as root, using the password that you've just set.
  4. Recreate an administrative user account that is not root. If for example the name of this user account is Gunz, use useradd -m gunz. To use sudo to execute commands as root, you must make sure that the user account is a member of the group adm. To make a user with the name gunz member of the group adm, use usermod -G adm gunz.
  5. Use passwd gunz to give the user you've just created a password. You have now re-established a user account that can be used to perform administration tasks on your server.
Of course, to fix this problem you need physical access to your server and something (Linux Live CD!!) that boots a Linux shell and allows you to mount your server's file systems.

No comments:

Post a Comment