bsdzone BSDZone - FreeBSD help, how-to guides, and articles.

  [ Home ]   [ Current News ]   [ Howto Archive ]   [ Books ]   [ Search ]   [ Links ]   [ Contact ]  [ About ]  


Lost root password?
General Admin - 19 Nov 04

So you lost your root password?

Tested on FreeBSD 4.10
If you do not have physical access to the box you are SOL.
Reboot your machine. (Ouch)
When it asks you to press enter to boot into the kernel, press the spacebar.
Enter boot -s at the prompt.
When it asks you for a shell /bin/sh just press enter.
# fsck -y (Optional but a good idea considering you just pulled the plug on your machine)
# mount -a
# /usr/bin/passwd root

Enter your new password and reboot.
# reboot


2 Responses to “Lost root password?”

  1. Derek Johnstone Says:

    How I recovered a lost root password in FreeBSD

    This was on a CyberGuard LX firewall, running version 4.2 BSD

    Luckily I did know one user name and it had no password.
    cgadmin

    Using the boot CD, pick option 4 for single use mode
    going through the country and keyboard

    going to the repair mode with CDROM/DVD option off the install menu,
    using the “live” CDROM filesystem gave me a root prompt Fixit#

    now mounting the hard drive, in my case /dev/ad0s3a

    mount /dev/ad0s3a /mnt

    now edit the master password file

    vi /mnt/etc/master.passwd

    on the root line, delete all characters between the first two :: to remove the root password altogether.
    hence ending up with
    root::0:0::00:Charlie &:/root:/bin/csh or something similar

    save the file

    now change permissions, but look at them first, make a note so you can put them back to the correct setting later
    chmod 777 /mnt/etc
    chmod 666 /mnt/etc/master.passwd

    reboot

    remove the CD and reboot the original system.
    For some reason my older FreeBSD version 4.3 filesystem did not like being mounted onto a FreeBSD 6.1 install CD
    Hence on reboot it made me do a manual fsck
    Then another reboot

    Now login as a user, cgadmin in my case
    get a prompt and run

    pwd_mkdb /etc/master.passwd

    This rebuilds the secure password database

    Now get another getty - say Alt-F4 and login as root
    Amazing!!!!

    Reboot if you like, set yourself a new root password and write it down this time
    I prefer a label on the bottom of the box, because if you have got this access, you can crack the password.

    Now don’t forget to set the file security back to where it was
    chmod 755 /etc
    chmod 600 /etc/master.passwd

    Hope you enjoyed the day.

    Derek

  2. Marcello Says:

    Thanks very much! It works also on freebsd 5! ;-)

Leave a Reply