OpenBSD Handbook

    Theme
    • Part I. Install & Configure
      • Introduction to OpenBSD
      • Installing OpenBSD
      • The X Window System
      • Networking on OpenBSD
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • OpenBSD Desktop Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
      • Security
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • Pure-FTPd
          • TFTP
        • Mail
          • OpenSMTPD Mail Server
          • Dovecot IMAP and POP3 Server
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Unbound DNS Resolver
          • NSD Authoritative DNS Server
          • BIND DNS Server
        • Networking
          • OpenBGPD
          • rad
          • DHCP on OpenBSD
          • slaacd
        • Web
          • Apache HTTP Server
          • nginx Web Server
          • OpenBSD httpd Web Server
          • relayd Reverse Proxy
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • OpenSSH Server
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ Message Broker
        • Time
          • NTP Time Synchronization
        • Load Balancing
          • Build Redundant Load-Balanced Gateways
          • Load Balance Services with NAT or DSR
          • Build an HA HTTPS Load Balancer
      • PF
        • pfctl cheat sheet
        • PF Anchors
        • PF Filter Rules
        • PF Forwarding
        • PF Lists and Macros
        • PF Load Balancing
        • PF Logging
        • PF NAT
        • PF Options
        • PF Policies
        • PF Shortcuts
        • PF Tables
      • Advanced Networking
        • High Availability and State Replication
        • Multi-WAN and Policy-Based Routing
        • VPN and Cryptographic Tunneling
        • Classic and Lightweight Tunnels
        • IPv6 at Scale
        • QoS and Traffic Shaping
        • MPLS and Label Distribution
        • Network Services at Scale
        • Virtualization and Host Networking
        • Large-Scale L2 and L3 Design
        • Telemetry, Logging, and Flow Export
        • Hardening and Operational Safety
        • Reference Architectures
        • Troubleshooting Playbooks
      • Serial Communication
    • Part V. Miscellaneous
      • Virtualization Cheat Sheet
      • OpenBSD Cheatsheet
      • How-to Guides
        • Installation and First Boot
          • Complete the First 30 Minutes After Installation
          • Check Hardware Compatibility Before Installing
          • Bootstrap Wi-Fi Firmware Without Ethernet
          • Run OpenBSD as a Virtual Machine Guest
          • Install OpenBSD on a VPS or Cloud Server
          • Install OpenBSD with Full-Disk Encryption
          • Dual-Boot OpenBSD on a UEFI System
          • Automate OpenBSD Installation with Autoinstall and PXE
        • Desktops and Laptops
          • Set Up OpenBSD as a Laptop or Workstation
          • Configure Laptop Power Management
          • Troubleshoot Web Browsers on OpenBSD
          • Use Plan 9 Tools on OpenBSD
          • Build a Minimal Desktop with suckless Tools
          • Install Z shell (zsh)
        • Networking and Remote Access
          • Create an Administrator Account with doas and SSH Keys
          • Configure Secure Remote Access with OpenSSH
          • Use FIDO Security Keys with OpenSSH
          • Configure Wi-Fi Roaming and Wired Failover
          • Troubleshoot PF, NAT, and Routing
          • Route Multiple VLANs with PF
          • Configure a Road-Warrior WireGuard VPN
          • Route IPv6 Networks without NAT
          • Test OpenBGPD with Two Providers
          • Unlock an Internal Service with an SSH Key
          • Build a Simple Router and Firewall
        • Servers and Services
          • Set Up WordPress on OpenBSD
          • Build a Mail Server with OpenSMTPD, Dovecot, and Rspamd
        • Security, Maintenance and Recovery
          • Establish a Conservative Security Baseline
          • Recover Access and Reset the Root Password
          • Collect OpenBSD Diagnostic Evidence
          • Troubleshoot Package Installation and Update Failures
          • Schedule Recurring Maintenance
          • Monitor an OpenBSD System
          • Back Up and Restore an OpenBSD System
          • Configure softraid RAID1
          • Recover an OpenBSD System That Does Not Boot
        • Building, Automation and Virtual Machines
          • Manage OpenBSD with Ansible
          • Build Third-Party Software from Ports
          • Build OpenBSD from Source
          • Plan a Docker Workload Migration to OpenBSD
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • OpenBSD FAQ
    • OpenBSD Architectures
      • OpenBSD Package Search
        • Synopsis
        • Prepare the Console
        • Boot Single-User Mode
        • Check and Mount Filesystems
        • Reset and Verify the Password
        • Resume Normal Operation
        • After Recovery

        Recover Access and Reset the Root Password

        Synopsis #

        An administrator with authorized console access can reset the root password from single-user mode. The procedure boots a minimal root shell, checks and mounts the installed filesystems read-write, runs passwd(1) , and resumes multiuser operation.

        Use this procedure only on systems under the administrator’s control. Protect console access: it can allow changes to the root account. Encrypted root storage still requires its passphrase or keydisk before single-user mode can reach the installed system.

        Prepare the Console #

        Use a local keyboard and display, a serial console, a hypervisor console, or an authenticated provider console. Record any current error before restarting.

        If the system still has a working administrative session, correct the account or SSH configuration from that session instead of rebooting.

        Boot Single-User Mode #

        On amd64 and i386, interrupt the normal boot countdown at the boot(8) prompt and start the kernel with -s:

        boot> boot -s
        

        The console sequence differs on other architectures. Use the relevant boot_<arch>(8) manual page and INSTALL.<arch> document.

        If the console is marked secure in /etc/ttys, accept the default shell when prompted. Otherwise, single-user entry requires the root password; use verified recovery media and the boot recovery procedure when that password is unavailable. The root filesystem is initially mounted read-only.

        Check and Mount Filesystems #

        Run fsck(8) in preen mode, then remount the root filesystem read-write with mount(8) :

        Run in the root shell:

        fsck -p / && mount -uw /
          # Remount root read-write
        

        The passwd program and its libraries are normally under /usr, so /usr must also be available. If /usr is a separate filesystem:

        Run in the root shell:

        fsck -p /usr && mount /usr
          # Mount it according to /etc/fstab
        

        Do not assume a fixed partition name. fstab(5) defines the installed layout.

        If fsck -p reports an error that requires manual repair, stop and investigate the filesystem and disk condition. Do not substitute fsck -y without understanding the reported damage.

        Reset and Verify the Password #

        Change the root password:

        Run in the root shell:

        passwd root
        

        Inspect the account record with getent(1) :

        Run in the root shell:

        getent passwd root
        

        The account should have user ID 0, its expected home directory, and an appropriate login shell. Do not edit /etc/master.passwd directly. Use vipw(8) if an account-record repair is also required.

        Resume Normal Operation #

        Reboot normally after the password change so the normal startup filesystem checks run. Exiting a single-user shell continues with rc fastboot, which skips those checks; use that path only after checking all required filesystems:

        Run in the root shell:

        reboot
        

        After login, verify the root password from the console and test the normal administrator account with doas. If remote access failed, validate the SSH configuration before reloading it:

        Run in the root shell:

        sshd -t
          # Check server configuration syntax
        rcctl check sshd
          # Confirm the daemon is running
        

        After Recovery #

        Determine why access was lost. Common causes include an expired or removed key, incorrect home-directory permissions, an invalid doas.conf, an SSH policy change, or a password-management error.

        Preserve a tested non-root administrator account and an independent console path. For encrypted systems, store the disk-unlock recovery material separately from the machine. See Create an Administrator Account with doas and SSH Keys and Configure Secure Remote Access with OpenSSH .

        Report a bug
        • Synopsis
        • Prepare the Console
        • Boot Single-User Mode
        • Check and Mount Filesystems
        • Reset and Verify the Password
        • Resume Normal Operation
        • After Recovery