FreeBSD Reset or Recover Root Password

by Vivek Gite on December 6, 2006 · 16 comments

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.

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.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 15 comments… read them below or add one }

1 tamayekiyan March 16, 2007

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

Reply

2 nixcraft March 16, 2007

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.

Reply

3 tamayekiyan March 17, 2007

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.

Reply

4 Artak September 8, 2010

I’ve had the same problem, but when tried

/sbin/mount -u /

it worked!

Reply

5 andrei November 12, 2007

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

help pls!!!

Reply

6 PAVIlIOnX March 24, 2008

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!!!!!

Reply

7 bleuken July 6, 2008

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).

Reply

8 MihaKot June 4, 2009

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

Reply

9 Kupai September 8, 2009

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

Reply

10 Vivek Gite September 9, 2009

Password protect FreeBSD boot loader

Reply

11 Odkhuu March 12, 2010

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

Reply

12 Anonymous June 3, 2010

Helped me. Thank you.

Reply

13 woronti June 25, 2010

Thanks for the post. It saved me alot of headache

Reply

14 jay1 March 14, 2011

Thanks a lot

Reply

15 Paulo April 21, 2011

Thanks, it worked ;-)

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 9 + 10 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: