OpenBSD Handbook

    • Part I. Install & Configure
      • Introduction
      • Installing OpenBSD
      • The X Window System
      • Networking
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • Graphical Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Security
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • TFTP
        • Mail
          • Dovecot
          • smtpd
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Named
          • Unbound
          • NSD
        • Networking
          • OpenBGPD
          • rtadvd
          • DHCP
          • slaacd
        • Web
          • Apache
          • nginx
          • httpd
          • relayd
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • sshd
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ
        • Time
          • NTP
      • 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
      • Howto
        • Install Z shell (zsh)
        • Set Up WordPress
        • Build a Simple Router and Firewall
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • Package Search
      Audit OpenSSH
      • Synopsis
      • Overview
      • Install and Run ssh-audit
      • Harden Algorithm Policy in sshd_config
      • Validate and Apply the Configuration
      • Optional: Remove Small Diffie–Hellman Moduli
      • Optional: Rotate Host Keys
      • Client Compatibility Considerations
      • Verification

      Audit OpenSSH

      Synopsis #

      1. Install ssh-audit with pkg_add(1) .
      2. Run ssh-audit against the target to inventory supported algorithms.
      3. Constrain key exchange, host-key, and MAC algorithms in sshd_config(5) .
      4. Validate configuration with sshd(8) and restart via rcctl(8) .
      5. Re-run ssh-audit to confirm the intended policy.
      6. Optionally remove small Diffie–Hellman moduli per moduli(5) .
      7. Optionally rotate host keys with ssh-keygen(1) .

      Overview #

      This chapter describes how to assess and harden an OpenSSH server on OpenBSD using the ssh-audit utility. The workflow is to install and run ssh-audit, constrain algorithms in sshd_config(5) , validate the daemon with sshd(8) , restart via rcctl(8) , and optionally curate Diffie–Hellman moduli per moduli(5) and rotate host keys with ssh-keygen(1) .

      A key exchange algorithm (KEX) establishes shared secrets. A host-key algorithm authenticates the server identity. A message authentication code (MAC) authenticates message integrity. Restricting these sets reduces attack surface while maintaining required client compatibility.

      Install and Run ssh-audit #

      Install the package with pkg_add(1) and perform a local audit.

      # pkg_add ssh-audit
      $ ssh-audit localhost
      

      To audit a remote host, specify the target and optional port. IPv6 literals require brackets.

      $ ssh-audit example.org
      $ ssh-audit -p 2222 example.org
      $ ssh-audit -p 22 '[2001:db8::1]'
      

      The utility reports the server banner and the offered KEX, host keys, ciphers, and MACs, highlighting weak or deprecated choices.

      Harden Algorithm Policy in sshd_config #

      Edit /etc/ssh/sshd_config to permit a concise, modern subset of algorithms. The commands below append conservative settings suitable for a wide range of clients. Review and adjust to match the deployment’s compatibility requirements. See sshd_config(5) for directive semantics.

      Key exchange. Prefer Curve25519 and strong finite-field Diffie–Hellman groups. The hybrid sntrup761x25519-sha512@openssh.com may be included where supported by both server and clients.

      # sh -c 'printf "\n# Restrict key exchange\nKexAlgorithms \
      curve25519-sha256,curve25519-sha256@libssh.org,\
      diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,\
      diffie-hellman-group-exchange-sha256\n" >> /etc/ssh/sshd_config'
      

      MACs. Prefer encrypt-then-MAC variants and avoid SHA-1.

      # sh -c 'printf "# Restrict MACs\nMACs \
      umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,\
      hmac-sha2-512-etm@openssh.com\n" >> /etc/ssh/sshd_config'
      

      Host keys. Prefer Ed25519 and RSA with SHA-2 signatures.

      # sh -c 'printf "# Restrict HostKey algorithms\nHostKeyAlgorithms \
      ssh-ed25519,rsa-sha2-256,rsa-sha2-512\n" >> /etc/ssh/sshd_config'
      

      When reducing HostKeyAlgorithms, ensure that HostKey file paths in /etc/ssh/sshd_config reference only the retained key types. For example, omit ssh_host_ecdsa_key when ECDSA is disabled. See sshd_config(5) .

      Validate and Apply the Configuration #

      Test the daemon configuration and restart the service. Use sshd(8) with -t to validate settings and rcctl(8) to restart.

      # sshd -t
      # rcctl restart sshd
      

      Re-run the audit to confirm the intended algorithm set is offered.

      $ ssh-audit localhost
      

      Optional: Remove Small Diffie–Hellman Moduli #

      Group-exchange parameters reside in /etc/ssh/moduli. Filter out entries with size below 3071 bits to target at least approximately 128-bit strength. Refer to moduli(5) for field details.

      # awk '$5 >= 3071' /etc/ssh/moduli > /etc/ssh/moduli.safe
      # mv -f /etc/ssh/moduli.safe /etc/ssh/moduli
      # rcctl restart sshd
      

      Optional: Rotate Host Keys #

      When deprecating algorithms or strengthening parameters, rotate host keys. Back up existing keys, remove unwanted types, and generate Ed25519 and RSA (3072-bit) keys. Use ssh-keygen(1) .

      # cd /etc/ssh
      # install -d -m 0700 ./backup-keys && mv ssh_host_* ./backup-keys/
      # ssh-keygen -t ed25519 -N '' -f /etc/ssh/ssh_host_ed25519_key
      # ssh-keygen -t rsa -b 3072 -o -a 100 -N '' -f /etc/ssh/ssh_host_rsa_key
      

      Ensure that HostKey directives reference the new files:

      HostKey /etc/ssh/ssh_host_ed25519_key
      HostKey /etc/ssh/ssh_host_rsa_key
      

      Validate and restart:

      # sshd -t
      # rcctl restart sshd
      

      Client Compatibility Considerations #

      Tightening policies can break older clients that lack support for Curve25519 or RSA SHA-2 signatures. Where legacy access is unavoidable, conditional match blocks in sshd_config can scope exceptions, or a separate bastion with a relaxed policy can be provided. See sshd_config(5) and ssh(1) .

      Verification #

      Use ssh-audit to confirm removal of weak items such as SHA-1 MACs, small DH groups, or disabled host-key types. Monitor authentication and negotiation logs via the system’s syslog(3) facilities after deployment.

      Report a bug
      • Synopsis
      • Overview
      • Install and Run ssh-audit
      • Harden Algorithm Policy in sshd_config
      • Validate and Apply the Configuration
      • Optional: Remove Small Diffie–Hellman Moduli
      • Optional: Rotate Host Keys
      • Client Compatibility Considerations
      • Verification