FreeBSD Reset or Recover Root Password

With FreeBSD version 5.4 and above the booting procedure is slightly changed. The older version of FreeBSD uses the boot -s option at Ok prompt. However, with FreeBSD version FreeBSD 5.4+ you don’t have to type any commands. Here is the procedure to boot FreeBSD into a single user mode to reset root password.

In this tip I will explain how to boot FreeBSD into a single user mode to reset root password.

ADVERTISEMENTS

Procedure: Reset FreeBSD root user password

Step # 1: Start FreeBSD server/workstation.

Step # 2: Press Enter key at boot loader.

At Welcome to FreeBSD! boot menu press spacebar key to pause default booting

Type number 4 key (type 4 number) to boot into single user mode

(click to enlarge)

Next you will see the following prompt from system:
When prompted Enter full pathname of shell or RETURN for /bin/sh:

Press Enter key to boot into a single user mode. Next, you will be immediately dropped into a single user mode without a root password.

You need to remount / (root) file system in read and write mode with mount command, type the following commands:
# mount -u /
# mount -a

Setup a new password with the passwd command for root user:
# passwd

Next type exit command to boot FreeBSD into multi-user mode environment:
# exit
OR You can just reboot the system:
# sync;sync
# reboot

For more information see man pages of passwd and mount commands.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
22 comments… add one
  • tamayekiyan Mar 16, 2007 @ 9:47

    Dear Vivik:

    I can execute this instruction with version 6 but doesn’t work with lower versions.

    Is there any site that you can provide.

    Thanks,
    Tamayekiyan

  • 🐧 nixCraft Mar 16, 2007 @ 19:17

    FreeBSD 4.x/5.x

    Allow FreeBSD to boot system and mount file system
    mount -u /

    if /usr is on separate partition, mount /usr too:
    mount /usr

    Now change password
    passwd root
    sync;sync

    Hit CTRL+D.

    Note that if the console was set as insecure in
    /etc/ttys file. If so you will need to boot from a CD / floppy into fixit mode. Next mount your hard-disk read-write to continue the repair.

  • tamayekiyan Mar 17, 2007 @ 3:20

    Dear nixcraft:

    I booted with freebsd 6.1 cd and proceed to sysinstall. I selected FIXIT and I got a root prompt at vty4.

    I have done the above instruction, after typing a command in the root # prompt; the system says: command not found.

    then I typed mount -u / – still i got command not found error. If i type ls, it will display command not found as well. If I type pwd – system say / (currently in the root directory).

    Am able to cd change directory to /usr and other subdirectory with no problems but mounting such device/directory – I have no luck at all.

    looking forward for your advises.

    Tamayekiyan.

    • Artak Sep 8, 2010 @ 10:56

      I’ve had the same problem, but when tried

      /sbin/mount -u /

      it worked!

  • andrei Nov 12, 2007 @ 20:55

    i followed the stept and it’s telling me that /usr was not properly dismounted

    help pls!!!

  • PAVIlIOnX Mar 24, 2008 @ 21:44

    i was follow all steps, but when i put in console the command “passwd” or “passwd root”, return me
    passwd: unknown user root.

    Please!!! help me!!!!!

  • bleuken Jul 6, 2008 @ 16:52

    Thanks for this post! I’m glad that I can use this to my problem on FreeBSD. I really forgot my password and I need to access the root (it’s the only user for the server and I need to fix it).

  • MihaKot Jun 4, 2009 @ 9:16

    Hi.
    When i boot in single mode
    he ask me password for root or press ^D to go multi user.
    Can help?

  • Kupai Sep 8, 2009 @ 19:17

    How can I protect myself against others who want to get root privileges this way?

  • Odkhuu Mar 12, 2010 @ 1:47

    Dont change password
    error:
    pwd_mkdb: warning, unknown root shell

  • Anonymous Jun 3, 2010 @ 7:43

    Helped me. Thank you.

  • woronti Jun 25, 2010 @ 7:18

    Thanks for the post. It saved me alot of headache

  • jay1 Mar 14, 2011 @ 10:53

    Thanks a lot

  • Paulo Apr 21, 2011 @ 20:48

    Thanks, it worked 😉

  • Deb May 13, 2012 @ 3:49

    It worked like a champ! Thank you !

    Now, I am facing with another issue.
    This freebsd6.0 VM is not taking DHCP address automatically.
    Any cool trick from any one ? Thanks

  • Didzis May 29, 2012 @ 11:12

    Thanks a lot
    Helped me.

  • SHANE Jul 20, 2012 @ 4:12

    I am runnyg freebsd 8.2 on VM. i cant remember my login name. I do have root acces but only readable not writeable. I havent used this machine since november. i am also a newbie at this as well. any advice would be gladly appreciated. thanks in advance.

  • Chrome Aug 28, 2012 @ 7:04

    It works! Thank you so much! :X
    But…. when i boot the option 4th, i had to write “fsck -y”

  • RRR Sep 7, 2012 @ 0:08

    I got an error

    passwd : pam_chauthtok(): error in service module

    Please help

    • jim Sep 17, 2012 @ 17:35

      make sure you have mounted read/write. If the file system is not clean you nead to run fsck prior to running the mount -a command. I got the same error as a result of bad mount (ie read only mount)

      • mori Aug 14, 2014 @ 6:54

        hi
        many thanks jim for your hint about run the fck

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.