Samir Parikh · Blog · Git

Originally published on 13 May 2022

I recently encountered some issues with the login shell on one of my FreeBSD machines. Somehow, an upgrade apparently broke the Bash shell that I had assigned to the account. Unfortnately, as this was my only root account, I had no way to login.

In order to fix the issue, I power-cycled the virtual machine and then activated the web-based console, selecting the option to boot into “Single User Mode”. Booting into a machine in this mode is useful when you have make repairs to a broken system but does require some extra precaution as the FreeBSD Handbook states:

This mode is typically used to repair a system that will not boot or to reset the root password when it is not known. While in single user mode, networking and other virtual consoles are not available. However, full root access to the system is available, and by default, the root password is not needed.

By default, the root filesystem is read-only when you boot into Single User mode:

Enter full pathname of shell or RETURN for /bin/sh:
root@:/ # mount
zroot/ROOT/default on / (zfs, local. noatime, read-only, nfsv4acls)
devfs on /dev (devfs)

You can change the read/write status of a mounted filesystem using the mount(8) command:

root@:/ # mount -u /

root@:/ # mount
zroot/ROOT/default on / (zfs, local. noatime, nfsv4acls)
devfs on /dev (devfs)

Now we can change the account’s shell back to the default shell, /bin/sh:

root@:/ # chsh -s /bin/sh username

Finally, you can exit the shell to allow the system to continue with the normal boot process:

root@:/ # exit

Apparently it’s a good idea to never change the default shell of your root account, a lesson I have now readily learned!