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
        • Create the Account
        • Configure doas
        • Generate an SSH Key
        • Install the Public Key
        • Test the Complete Administrative Path
        • Change SSH Authentication Policy
        • Recovery Record

        Create an Administrator Account with doas and SSH Keys

        Synopsis #

        Routine administration should use a regular account and doas(1) , not a persistent root login. This guide creates an administrator, installs an SSH public key, validates privilege escalation, and preserves a recovery path until the replacement access method has been tested.

        Complete this procedure from the local console or a provider console. Keep the existing root session open throughout the final access tests.

        Create the Account #

        The installer can create a regular account and place it in the wheel group. If no suitable account exists, run adduser(8) as root:

        Run in the root shell:

        adduser
        

        Select wheel when the prompts ask for additional groups. The account’s login group remains the primary group selected elsewhere in the dialog.

        For an existing account, inspect its current primary and supplementary groups before using usermod(8) :

        Run in the root shell:

        id admin
        

        The usermod -G option appends supplementary memberships. Use -S only when intentionally replacing the complete supplementary-group list. To add wheel while retaining existing memberships:

        Run in the root shell:

        usermod -G wheel admin
        

        Replace admin with the actual account name, then verify the complete result with id(1) :

        Run in the root shell:

        id admin
        

        Configure doas #

        The doas.conf(5) file does not exist on every installation. A minimal policy for administrators in wheel is:

        permit persist :wheel
        

        Create or edit /etc/doas.conf without discarding any existing policy. Rules are evaluated in order, so review the complete file when adding the wheel rule. Keep the file owned by root and validate it:

        Run in the root shell:

        test -e /etc/doas.conf || install -o root -g wheel -m 600 /dev/null /etc/doas.conf
          # Create the file only when it does not already exist
        vi /etc/doas.conf
          # Add the rule without discarding existing policy
        chown root:wheel /etc/doas.conf
          # Preserve administrative ownership
        chmod 600 /etc/doas.conf
          # Restrict the policy file
        doas -C /etc/doas.conf
          # Check the policy syntax
        

        The persist option caches successful authentication for a limited time. Remove it when every privileged command should require authentication. Avoid nopass for a general administrator rule.

        Generate an SSH Key #

        Generate the key on the client system from which administration will occur. Create an Ed25519 key with ssh-keygen(1) :

        ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519
        

        Protect the private key with a passphrase. Transfer only the .pub file.

        Install the Public Key #

        While password authentication still works, append the public key through ssh(1) :

        ssh admin@server.example.com 'umask 077; mkdir -p .ssh; cat >> .ssh/authorized_keys' < ~/.ssh/id_ed25519.pub
        

        On the server, derive the configured home directory rather than assuming its path. Verify and, if necessary, repair ownership and modes:

        Run in the root shell:

        admin_home=$(getent passwd admin | cut -d: -f6)
          # Read the account's configured home directory
        chown -R admin "$admin_home/.ssh"
          # Make the account own its SSH directory without assuming a group
        chmod 700 "$admin_home/.ssh"
          # Prevent access by other users
        chmod 600 "$admin_home/.ssh/authorized_keys"
          # Restrict the authorized-key file
        

        The home directory must not be writable by unrelated users.

        Test the Complete Administrative Path #

        Open a new client session and require public-key authentication with the intended key:

        ssh -o IdentitiesOnly=yes -o PreferredAuthentications=publickey \
            -o PasswordAuthentication=no -o KbdInteractiveAuthentication=no \
            -i ~/.ssh/id_ed25519 admin@server.example.com
        

        From that new session, verify identity and privilege escalation:

        id
          # Confirm the regular account and wheel membership
        doas id
          # Confirm that doas reaches effective user ID 0
        

        Do not close the console or original root session until both commands succeed.

        Change SSH Authentication Policy #

        Public-key access can now replace remote root and password login. Make those policy changes through sshd_config(5) , validate them with sshd(8) , and test another new session before ending the recovery session.

        The complete lockout-safe procedure is in Configure Secure Remote Access with OpenSSH .

        Recovery Record #

        Record:

        • how to reach the physical, serial, hypervisor, or provider console;
        • the administrator account name;
        • the public-key fingerprint;
        • where a protected backup or replacement credential is held;
        • how to restore password authentication temporarily if all keys are lost.

        An SSH key and a doas rule are access controls, not a substitute for recovery planning.

        Report a bug
        • Synopsis
        • Create the Account
        • Configure doas
        • Generate an SSH Key
        • Install the Public Key
        • Test the Complete Administrative Path
        • Change SSH Authentication Policy
        • Recovery Record