Reset your passwords on OpenBSD

If you forgot your root password for OpenBSD, you can easily reset it if you have access to the serial console.

First, you'll want to get access to the serial console. If your virtual machine is using OpenBSD's VMM as the hypervisor, this can be accessed using ssh:

$ ssh username@example.com

Replace username with your real username, and example.com with your hypervisor's hostname (host.ircnow.org, host.lecturify.net, host.bsdforall.org, etc).

Once you get ssh access, you'll need to shut down your existing virtual machine:

$ vmctl stop vm-name

Replace vm-name with your virtual machine name (it's usually the same as your username).

$ vmctl start -c vmname

If you see the following error message:

vmctl: start vm command failed: Operation already in progress

This means your virtual machine has not finished shutting down. Wait a minute or two, then retype the command vmctl start -c vmname again.

You should see the following:

CD-ROM: E0
Loading /6.9/AMD64/CDBOOT
probing: pc0 com0 mem[638K 1022M a20=on] 
disk: hd0+* cd0
>> OpenBSD/amd64 CDBOOT 3.53
boot>  

Immediately, without any delay, type:

boot> boot -s

At any time, if you need to escape the serial console (perhaps because you were unable to stop OpenBSD from automatically booting), type ~~.

Select sh as your shell, then:

# fsck -p / && mount -urw /
# fsck -p / && mount -rw /usr
# fsck -p / && mount -rw /var
# fsck -p / && mount -rw /tmp
# passwd root
# passwd username

Replace username with your real username.

Then, reboot:

# reboot

Recommended Reading

https://www.openbsd.org/faq/faq8.html#LostPW