Maximum Security Configuration: Single Packet Authorization (SPA) with OpenBSD Authpf for SSH
Protecting SSH ports from remote attacks is critical for VPS security. This guide details configuring Single Packet Authorization (SPA) with OpenBSD Authpf to secure SSH access. SPA...
Protecting SSH ports from remote attacks is critical for VPS security. This guide details configuring Single Packet Authorization (SPA) with OpenBSD Authpf to secure SSH access. SPA requires a valid, encrypted packet before opening the SSH port, significantly reducing exposure to brute-force attacks, port scanning, and other remote threats. The configuration leverages OpenBSD's built-in pf firewall and the Authpf extension to enforce this security model. While DPTCloud provides robust network defense with a 99.98% SLA Network Security & 99.98% SLA Infrastructure at DPTCloud, securing the host-level firewall remains essential. This guide covers setup, verification, and troubleshooting to achieve maximum SSH security.
Introduction to Single Packet Authorization (SPA) and Authpf
Single Packet Authorization (SPA) is a network security technique that allows a server to open a port only after receiving a specific, authenticated packet. This packet, often sent from a client, contains encrypted credentials and a timestamp, acting as a digital key. OpenBSD Authpf is a module for the pf packet filter that processes these SPA packets and dynamically adjusts firewall rules. The primary benefit is that the SSH port remains hidden from network scans. Attackers cannot detect the SSH service until a valid SPA packet is sent, effectively making the service invisible to automated scanners.
SPA operates as a "digital key": only when the correct packet is received does the server open the SSH port. This method drastically reduces the attack surface, as the port is not open until after successful authentication. Authpf integrates seamlessly with OpenBSD's pf firewall, allowing administrators to define rules that trigger the opening of ports based on SPA packet validation.
Prerequisites and Initial Configuration
To implement SPA with Authpf on OpenBSD, the following prerequisites are required:
- An OpenBSD system (version 6.9 or later)
- Console or SSH access to the server (before the SSH port is secured)
- Authpf package installed (available in the OpenBSD package system)
- A secret key for encrypting SPA packets
First, install the Authpf package using the OpenBSD package manager:
# Install Authpf
pkg_add authpf
Next, configure Authpf by editing the configuration file /etc/authpf.conf. This file defines the rules for SPA. For example, the following configuration allows SSH access after a valid SPA packet is received:
# /etc/authpf.conf
# Define a rule for SSH
authpf {
# SPA packet format: <secret> <timestamp> <src_ip>
# Example: "mysecretkey 1700000000 192.168.1.100"
rule {
action = "allow"
protocol = "tcp"
port = 22
source = "any"
destination = "any"
# Match the secret key
match = "mysecretkey"
# TTL for the packet (seconds)
ttl = 60
# Timeout for the session (seconds)
timeout = 600
}
}
Authentication and Verification
To send an SPA packet, use a client tool like authpf-client or a simple script. For testing purposes, the netcat command can be used to send the packet (note: this method is not secure for production use):
# Send an SPA packet to the server (replace IP and secret key)
echo "mysecretkey 1700000000 192.168.1.100" | nc -u <server_ip> 2000
To verify that the Authpf rule is active and the session is established, use the following command:
# Check the Authpf status
authpfctl status
This command displays the current authenticated sessions and their remaining time. If no sessions are listed, check the Authpf log file located at /var/log/authpf.log for error messages.
Troubleshooting and Maintenance
If SSH access is not established after configuring Authpf, verify the following:
- Authpf Log: Check
/var/log/authpf.logto see if the SPA packet is being rejected. - Packet Format: Ensure the SPA packet follows the correct format:
secret_key timestamp client_ip. - Time Synchronization: The timestamp in the packet must be within 60 seconds of the server's time; otherwise, the packet will be rejected.
- Firewall Status: Verify that the
pffirewall is running and that the Authpf rules are loaded.
For maintenance, you can expire old or expired sessions using the following command:
# Expire expired sessions
authpfctl expire
References
For more information on Authpf and SPA, consult the official OpenBSD documentation:
For additional VPS security solutions, refer to guides on self-hosting a WireGuard VPN server or centralized secrets and password management with OpenBao and Vaultwarden.
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
