OpenBSD SSH Hardening - Beginner Guide

Contents
OpenBSD SSH Hardening - Beginner Guide
Why SSH Hardening Matters
Step 1: Disable Root Login
Step 2: Disable Password Authentication
Step 3: Limit Login Attempts
Step 4: Change the Default Port (Optional)
Step 5: Configure Firewall for SSH
Step 6: Test Your Configuration
Common Mistakes to Avoid

OpenBSD SSH Hardening - Beginner Guide

Securing your SSH connection is critical. Here's how to protect your OpenBSD server.

Why SSH Hardening Matters

SSH is the primary way to remotely manage your server. If not properly secured, attackers could:
- Guess your password
- Gain unauthorized access
- Take control of your server

Step 1: Disable Root Login

This is the most important security step.

Edit the configuration:
vi /etc/sshd_config

Find this line: #PermitRootLogin yes
Change to: PermitRootLogin no

Why: Prevents hackers from trying to guess the root password.

Important: Make sure you have another user with administrative privileges before disabling root login, or you could lock yourself out!

Step 2: Disable Password Authentication

After you've set up SSH keys (see Lesson 12), disable password-based login.

In /etc/sshd_config, find and change:
#PasswordAuthentication yes → PasswordAuthentication no

This forces everyone to use SSH keys:
- Keys are much harder to guess than passwords
- Even if someone knows your password, they can't SSH in without your key file
- You can add a passphrase to your key for extra security

Step 3: Limit Login Attempts

Prevent automated password guessing attacks.

In /etc/sshd_config, add or modify:
MaxAuthTries 3 - allows maximum 3 login attempts
LoginGraceTime 60 - gives 60 seconds to complete login

Example configuration section:

# Authentication:
LoginGraceTime 60
PermitRootLogin no
StrictModes yes
MaxAuthTries 3

Step 4: Change the Default Port (Optional)

The default SSH port is 22. Changing it can reduce automated attacks.

In /etc/sshd_config, find and change:
#Port 22 → Port 2222 (or any port above 1024)

Note: This provides "security by obscurity" - it won't stop determined attackers, but it reduces log noise from automated bots scanning port 22.

If you change the port: Don't forget to specify the port when connecting:
ssh -p 2222 user@your-server-ip

Step 5: Configure Firewall for SSH

OpenBSD's PF firewall can restrict who can attempt SSH connections.

In /etc/pf.conf, add:
pass in on egress proto tcp from any to any port 22

To restrict by IP address:
pass in on egress proto tcp from 192.168.1.0/24 to any port 22

This means: Only computers on your home network (192.168.1.0/24) can try to SSH into your server. Others will be blocked.

Step 6: Test Your Configuration

Test SSH after each change: Try connecting from another computer.

Check configuration syntax:
sshd -t - checks for configuration errors

Reload SSH after changes:
rcctl restart sshd

Common Mistakes to Avoid

Mistake 1: Disabling root login AND password auth before setting up keys.
Result: Locked out of your own server!
Fix: Always test SSH keys first, then disable passwords.

Mistake 2: Opening port 22 to the whole internet without firewall rules.Result: Constant attack attempts!
Fix: Use PF to restrict SSH access to trusted IPs only.

Mistake 3: Using weak passwords.
Fix: Use SSH keys with passphrases, or strong 16+ character passwords.

Advanced SSH topics? Proceed to Lesson 29: SSH Hardening.

Next: OpenBSD Package Management - Beginner Guide

Article author: Arthur Isaev

Related articles
UNIX
OpenBSD
OpenBSD course
Architecture Compatibility
Prepare Installation Media
BIOS Installation
UEFI Installation
Disk Partitioning
Base System Installation
Configure Network
Disable Firewall Temporarily
OpenSSH Server
Update System
Security Basics
Frequently Asked Questions
Virtualization Overview
Docker Containers
Kubernetes
PF NAT Configuration
PF Suppression
IPsec VPN
WireGuard VPN
Advanced Cron
Systemd Compatibility
PF Firewall Introduction
Shells
Environment Variables
Sudoers Configuration
/etc/fstab
Group Management
Password Security
Issue and Banner
PAM Configuration
TCP Wrappers
Intrusion Detection
PF Advanced Rules
Log Analysis
Advanced Backup
Kernel Update
Certificate Management
Access Control Lists (ACLs)
User Security Settings
Vulnerability Management
Security Audit Tools
Security Parameter Tuning
SSH Key Authentication
sudo vs doas
Users and Groups
PostgreSQL Introduction
Services Management
Web Server Overview
Install Apache Web Server
Install Nginx Web Server
Database Setup
Install PHP
Firewall Configuration
SSL/TLS Certificate
Firewall Configuration
Install PHP
Install PHP
Advanced SSL/TLS Configuration
User Management Advanced
PF Logging and Monitoring
Custom Kernel compilation
Advanced doas Configuration
Resource Limits
DHCP Server
Mail Server
SSH Hardening
System Logging
Disk Encryption
Window Managers
Text Editors
Package Management
Cron Jobs
System Monitoring
PF Firewall Advanced
SSH Configuration
Services Management
PHP and Web Stack
Advanced User Management
Swap and Memory
Kernel Parameters
Boot Process
Mounting Filesystems
UFS Filesystem
Softraid
Disk Management
DNS Configuration
Hosts File
Network Statistics
Routing
Network Bridging
System Upgrade
Backup Strategies
Log Rotation
GCC Compiler
Make Build System
Debugging
System Call Tracing
FIPS 140-2
Audit System
Security Compliance
Virtual Machines
LXC Containers
HTTP API
Advanced Monitoring
SELinux (Ported)
Course Conclusion
OpenBSD Architecture - Beginner Guide
OpenBSD Installation Media - Beginner Guide
OpenBSD Disk Partitioning - Beginner Guide
OpenBSD System Updates - Beginner Guide
OpenBSD PF Firewall - Beginner Guide
OpenBSD SSH Configuration - Beginner Guide
OpenBSD User Management - Beginner Guide
OpenBSD Web Server - Beginner Guide
OpenBSD PostgreSQL Database - Beginner Guide
OpenBSD PF Logging and Monitoring - Beginner Guide
OpenBSD SSH Hardening - Beginner Guide
OpenBSD Package Management - Beginner Guide
OpenBSD Firewall Configuration - Beginner Guide
OpenBSD Backup Strategies - Beginner Guide
OpenBSD GCC Compiler - Beginner Guide
OpenBSD Virtual Machines - Beginner Guide
OpenBSD Course Conclusion - Beginner Guide
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: