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
      • 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
        • Complete the First 30 Minutes After Installation
        • Check Hardware Compatibility Before Installing
        • Bootstrap Wi-Fi Firmware Without Ethernet
        • Set Up OpenBSD as a Laptop or Workstation
        • Configure Laptop Power Management
        • Run OpenBSD as a Virtual Machine Guest
        • Install OpenBSD on a VPS or Cloud Server
        • Install OpenBSD with Full-Disk Encryption
        • Troubleshoot Web Browsers on OpenBSD
        • Create an Administrator Account with doas and SSH Keys
        • Establish a Conservative Security Baseline
        • Manage OpenBSD with Ansible
        • Recover Access and Reset the Root Password
        • Collect OpenBSD Diagnostic Evidence
        • Configure Secure Remote Access with OpenSSH
        • Set Up WordPress on OpenBSD
        • Build Third-Party Software from Ports
        • Use FIDO Security Keys with OpenSSH
        • Build OpenBSD from Source
        • Configure Wi-Fi Roaming and Wired Failover
        • Dual-Boot OpenBSD on a UEFI System
        • Troubleshoot PF, NAT, and Routing
        • Automate OpenBSD Installation with Autoinstall and PXE
        • Route Multiple VLANs with PF
        • Configure a Road-Warrior WireGuard VPN
        • Troubleshoot Package Installation and Update Failures
        • Route IPv6 Networks without NAT
        • Schedule Recurring Maintenance
        • Plan a Docker Workload Migration to OpenBSD
        • Build a Mail Server with OpenSMTPD, Dovecot, and Rspamd
        • Build a Simple Router and Firewall
        • Monitor an OpenBSD System
        • Back Up and Restore an OpenBSD System
        • Configure softraid RAID1
        • Recover an OpenBSD System That Does Not Boot
        • Install Z shell (zsh)
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • OpenBSD FAQ
    • OpenBSD Architectures
      • OpenBSD Package Search
        • Synopsis
        • Manage the Service
        • Validate Server Configuration
        • Configure Public-Key Authentication
        • Configure the Client
        • Transfer Files
        • Control Forwarding
        • Provide Restricted SFTP Access
        • Avoid Static Algorithm Lists
        • Diagnose Connections

        OpenSSH Server

        Synopsis #

        sshd(8) is the OpenSSH daemon in the OpenBSD base system. It provides encrypted remote shells, remote command execution, file transfer, and optional forwarding. The daemon reads sshd_config(5) from /etc/ssh/sshd_config.

        For first-time setup, create an administrator account . Configure Secure Remote Access with OpenSSH provides a lockout-safe procedure for replacing password access with keys. Audit OpenSSH explains algorithm policy, post-quantum key exchange, and ssh-audit findings. Use FIDO Security Keys with OpenSSH covers hardware-backed credentials. This page is a concise operational reference.

        Manage the Service #

        Inspect, enable, and start the daemon with rcctl(8) :

        doas rcctl check sshd
          # Report whether the service is running
        doas rcctl enable sshd
          # Enable the service at boot
        doas rcctl start sshd
          # Start it now when it is not already running
        

        The installer normally creates host keys. Generate only missing host keys with ssh-keygen(1) :

        doas ssh-keygen -A
        

        Display the server’s Ed25519 host-key fingerprint for verification through an independent channel:

        doas ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
        

        Validate Server Configuration #

        Validate configuration syntax and host-key files with sshd(8) before reloading the service with rcctl(8) :

        doas sshd -t
          # Produce no output when validation succeeds
        doas rcctl reload sshd
          # Apply the validated configuration without ending established sessions
        

        Many defaults are not active lines in /etc/ssh/sshd_config. Inspect the effective configuration with sshd -T:

        doas sshd -T | grep -Ei '^(port|permitrootlogin|passwordauthentication|kbdinteractiveauthentication|pubkeyauthentication) '
        

        Settings inside a Match block depend on connection attributes. Supply representative values with -C:

        doas sshd -T -C user=admin,addr=198.51.100.25,host=client.example.com
        

        This command evaluates matching only and does not create a connection. A Match block remains in effect until another Match directive or the end of the file. Place global directives before the first Match block. When more than one satisfied block specifies a keyword, the first obtained value is used.

        Configure Public-Key Authentication #

        Generate an Ed25519 key on the client with ssh-keygen(1) and protect the private key with a passphrase:

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

        While an existing authentication method still works, use ssh(1) to append the public key to the remote account:

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

        Test the intended key without allowing a password or keyboard-interactive fallback:

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

        Only after that test succeeds, an explicit key-only server policy can be placed before any Match block:

        PermitRootLogin no
        PasswordAuthentication no
        KbdInteractiveAuthentication no
        PubkeyAuthentication yes
        

        Keep an established administrative session and an independent console available while changing authentication. Run sshd(8) with -t, reload the service, and test another new session before closing the recovery session.

        Configure the Client #

        The client reads ssh_config(5) . A per-host stanza in ~/.ssh/config can record connection settings:

        Host prod
            HostName host.example.com
            User admin
            IdentityFile ~/.ssh/id_ed25519
            IdentitiesOnly yes
            ForwardAgent no
            ForwardX11 no
        

        Use ssh(1) to inspect the effective client configuration without opening a connection:

        ssh -G prod | grep -E '^(hostname|user|port|identityfile) '
        

        Verify a new server’s host-key fingerprint through an independent channel before accepting it. ssh-keyscan(1) retrieves keys but does not authenticate them.

        Transfer Files #

        Use sftp(1) for an interactive transfer session:

        sftp admin@host.example.com
        

        Use scp(1) for individual files or recursive directory copies:

        scp ./report.txt admin@host.example.com:/home/admin/
        scp -r ./reports admin@host.example.com:/home/admin/
        

        Uppercase -P selects a nondefault port. Lowercase -p preserves timestamps and mode bits.

        Control Forwarding #

        SSH can forward agents, TCP connections, Unix-domain sockets, X11 connections, and tunnel devices. Allow only the features the account needs. For an account that needs neither forwarding nor X11, a scoped restriction is:

        Match User admin
            DisableForwarding yes
            PermitTunnel no
        

        This block disables forwarding and tunnel creation. Allow only the features the account needs. Check the settings with sshd(8) using sshd -T -C, then test a new connection.

        Provide Restricted SFTP Access #

        The in-process SFTP server can support an account without an interactive shell. sshd_config(5) requires every component of the chroot pathname to be a root-owned directory that is not writable by group or others. One policy pattern is:

        Match Group sftponly
            ChrootDirectory /srv/sftp/%u
            ForceCommand internal-sftp
            DisableForwarding yes
            PermitTunnel no
        

        Create a root-owned chroot and a separate user-owned upload directory inside it. Validate the effective Match result before enabling the account. A chroot limits the visible filesystem but does not replace account, file-permission, and network policy.

        Avoid Static Algorithm Lists #

        Do not copy fixed cipher, MAC, key-exchange, signature, or host-key allowlists into the configuration without a documented interoperability requirement. Supported OpenSSH updates revise secure defaults and introduce new algorithms. A static list can retain obsolete choices or block future improvements.

        Audit OpenSSH is the detailed source for algorithm auditing and optional local policy. It explains why subtractive changes are safer than frozen replacement lists, how to verify post-quantum KEX, and when Diffie-Hellman moduli are relevant.

        Diagnose Connections #

        Review authentication events with tail(1) :

        doas tail -f /var/log/authlog
        

        Use ssh(1) verbose client logging for one controlled test:

        ssh -vvv admin@host.example.com
        

        If a connection fails, check the packet path, daemon listener, PF policy, effective server configuration, account state, and .ssh ownership in that order. Do not disable the firewall or remove the original recovery method as an initial diagnostic step.

        Report a bug
        • Synopsis
        • Manage the Service
        • Validate Server Configuration
        • Configure Public-Key Authentication
        • Configure the Client
        • Transfer Files
        • Control Forwarding
        • Provide Restricted SFTP Access
        • Avoid Static Algorithm Lists
        • Diagnose Connections