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
        • Privilege escalation
        • Packages
        • Base updates and release upgrades
        • Services (rc)
        • Networking
          • Inspect and temporary changes
          • Persistent examples
          • Useful network diagnostics
        • Firewall (PF)
          • Quick operations
          • Minimal allow-out ruleset
        • Web and SSH daemons
        • Users and groups
        • Filesystems and storage
        • Time and ntpd
        • Logging and rotation
        • System information and diagnostics
        • OpenSSH client basics
        • Handy paths

        OpenBSD Cheatsheet

        This cheatsheet summarizes common OpenBSD administration tasks with concise commands. Commands omit shell prompts and use explicit doas where privileges are required. Use doas(1) to escalate privileges and configure it via doas.conf(5) .

        Privilege escalation #

        For first-time setup, use the root-shell procedure in Create an Administrative Account . Preserve and review any existing policy before changing it.

        To cache authentication for members of wheel, use this rule in /etc/doas.conf:

        permit persist :wheel
        

        Test:

        doas id  # run a simple command via doas
        

        Packages #

        Package tools: pkg_add(1) , pkg_delete(1) , pkg_info(1) , overview in packages(7) .

        doas pkg_add htop            # install package
        doas pkg_delete htop         # remove package
        pkg_info | less              # list installed packages
        doas pkg_add -Uu             # upgrade all packages for current release
        

        Package mirrors are configured with installurl(5) .

        Base updates and release upgrades #

        Base security/bug patches: syspatch(8) . Release upgrades: sysupgrade(8) .

        doas syspatch -c  # list pending base patches
        doas syspatch     # apply base patches (reboot if asked)
        
        doas sysupgrade   # fetch and upgrade to next release
        doas pkg_add -Uu  # upgrade packages after release upgrade
        

        Services (rc) #

        Service management: rcctl(8) . System startup: rc(8) , rc.conf(8) .

        doas rcctl check sshd      # show status
        doas rcctl start sshd       # start now
        doas rcctl stop sshd        # stop now
        doas rcctl reload sshd      # reload config
        doas rcctl enable sshd      # enable at boot
        doas rcctl disable sshd     # disable at boot
        doas rcctl ls on            # list enabled services
        doas rcctl get sshd flags   # show daemon flags
        doas rcctl set sshd flags "-v"  # set daemon flags persistently
        

        Networking #

        Interfaces: ifconfig(8) . Persistent config files: hostname.if(5) , myname(5) , mygate(5) , resolv.conf(5) . Apply with netstart(8) .

        Inspect and temporary changes #

        ifconfig -A                 # all interfaces
        doas ifconfig em0 inet 10.0.0.10 netmask 255.255.255.0  # temp IPv4
        doas ifconfig em0 inet6 2001:db8::10 prefixlen 64    # temp IPv6
        doas sh /etc/netstart em0   # re-load a single interface
        doas sh /etc/netstart       # re-load all from files
        

        Persistent examples #

        /etc/hostname.em0 (choose one of the following forms):

        inet autoconf
        
        inet 192.0.2.10 255.255.255.0
        
        inet6 2001:db8:6000:1::10 64
        

        Hostname, default gateway, and resolvers:

        # /etc/myname
        host.example.com
        
        # /etc/mygate
        192.0.2.1
        2001:db8:6000:1::1
        
        # /etc/resolv.conf
        nameserver 192.0.2.53
        lookup file bind
        

        Useful network diagnostics #

        ping -n 1.1.1.1            # ICMP test (no DNS)
        traceroute -n 1.1.1.1      # path without DNS
        netstat -rn                # routing table
        route show                 # routing sockets view
        doas tcpdump -ni em0 port 53    # capture DNS on em0
        

        Firewall (PF) #

        Packet filter tools: pfctl(8) . Configuration: pf.conf(5) .

        Quick operations #

        doas pfctl -sr           # show rules
        doas pfctl -sr           # show NAT
        doas pfctl -si           # show stats
        doas pfctl -e            # enable PF
        doas pfctl -d            # disable PF
        doas pfctl -f /etc/pf.conf  # reload ruleset
        

        Minimal allow-out ruleset #

        # /etc/pf.conf
        set block-policy drop
        set skip on lo
        
        block all
        pass out inet proto { tcp udp icmp } from (egress) to any modulate state
        pass out inet6 proto { tcp udp icmp6 } from (egress) to any modulate state
        

        Activate:

        doas pfctl -f /etc/pf.conf
        doas pfctl -e
        

        Web and SSH daemons #

        HTTP server: httpd(8) with httpd.conf(5) . Secure shell: sshd(8) , sshd_config(5) .

        doas rcctl enable httpd
        doas rcctl start httpd
        doas rcctl enable sshd
        doas rcctl start sshd
        

        Users and groups #

        User and group management: useradd(8) , usermod(8) , userdel(8) , groupadd(8) , passwd(1) , chsh(1).

        doas useradd -m -G wheel -s /bin/ksh alice  # add admin user
        doas passwd alice                            # set password
        doas usermod -G wheel,staff alice            # adjust groups
        doas userdel -r bob                          # remove user and home
        chsh -s /bin/ksh                             # change login shell (self)
        

        Filesystems and storage #

        Filesystems: fstab(5) , mount(8) , umount(8) , df(1) . Disk setup: fdisk(8) (MBR/GPT), disklabel(8) .

        df -h                          # usage
        mount                          # mounted filesystems
        doas mount /home               # mount by fstab entry
        doas umount /home              # unmount
        dmesg | egrep '^sd|^wd|^cd'    # list disks as seen at boot
        doas disklabel -E sd0          # edit OpenBSD disklabel
        

        Time and ntpd #

        Network time: ntpd(8) . Configuration: ntpd.conf(5) .

        doas rcctl enable ntpd
        doas rcctl start ntpd
        rcctl check ntpd
        

        Logging and rotation #

        Syslog: syslogd(8) , configuration via syslog.conf(5) . Rotation: newsyslog(8) .

        doas tail -f /var/log/messages       # main system log
        doas tail -f /var/log/daemon         # daemon log
        doas newsyslog -n                    # show what would rotate
        doas newsyslog                       # rotate now
        

        System information and diagnostics #

        dmesg | less               # kernel messages and hardware probe
        sysctl kern.version        # kernel version
        sysctl hw.model hw.ncpu    # hardware info
        top                        # interactive process/CPU view
        vmstat 1                   # system counters
        systat iostat              # per-device I/O (curses)
        systat ifstat              # per-interface traffic (curses)
        ps auxww | less            # process list
        pgrep httpd; pkill httpd   # find/terminate processes
        

        OpenSSH client basics #

        Client: ssh(1) , keys via ssh-keygen(1) , config via ssh_config(5) .

        ssh -o StrictHostKeyChecking=accept-new user@host
        ssh-keygen -t ed25519 -C "me@host"     # generate key
        ssh-copy-id user@host                  # if installed; else append ~/.ssh/id_ed25519.pub on server
        

        Handy paths #

        /etc/rc.conf.local   # local daemon flags and enables
        /etc/installurl      # package/upgrade mirror
        /var/db/pkg/         # installed package metadata
        /var/log/            # system logs
        /etc/pf.conf         # PF ruleset
        /etc/hostname.*      # per-interface network config
        

        For deeper coverage, consult the referenced manual pages in each section.

        Report a bug
        • Privilege escalation
        • Packages
        • Base updates and release upgrades
        • Services (rc)
        • Networking
          • Inspect and temporary changes
          • Persistent examples
          • Useful network diagnostics
        • Firewall (PF)
          • Quick operations
          • Minimal allow-out ruleset
        • Web and SSH daemons
        • Users and groups
        • Filesystems and storage
        • Time and ntpd
        • Logging and rotation
        • System information and diagnostics
        • OpenSSH client basics
        • Handy paths