Reset root password on Linux, FreeBSD, Solaris (x86)

Posted on Mon 27 February 2006 by Pavlo Khmel

Linux
Reset root password on Linux (RHEL/CentOS).
Grub or Lilo should be without password or you should know that password.
In GRUB menu press "a" to go in edit mode and write after "... rhgb quit" single or s:

cashkernel=auto rhgb quit single

If SeLinux is enabled (RHEL6):

setenforce 0

Now you can reset root password:

passwd root

If you forgot password for GRUB/LILO, you should use bootable/recovery CD/DVD, to edit /etc/shadow. In /etc/shadow you should remove all characters between two colons at the begining "::", in line with "root". Then you can login as root without password.

FreeBSD

In boot menu choose 4 to boot in single mode, mount root and other partitions:

mount -u /
mount -a
passwd root

Solaris (x86)

Boot with Sun Solaris Operating System CD, launch a single user mode (No Password).
Select yes to mount the root file system (/dev/dsk/c0t0d0s0 here) on /a. (mount /dev/dsk/c0t0d0s0 /a)
Remove the encrypted password for root:

vi /a/etc/shadow
cd /
umount /a
init s

Now you can set root password in single-user mode.

passwd root
reboot