Skip to content
Linux SSH Hardening: Keys, Permissions & Access Control — A Complete Defense-in-Depth Guide
Operations 45 min read

Linux SSH Hardening: Keys, Permissions & Access Control — A Complete Defense-in-Depth Guide

This comprehensive guide walks through hardening Linux SSH with a defense-in-depth approach: generating Ed25519/RSA keys, disabling password login, restricting users and IPs, configuring sshd_config with strong ciphers, setting up sudo, firewalls (iptables/firewalld/cloud security groups), fail2ban, audit logging, key rotation, 2FA with Google Authenticator, and jump-host/bastion patterns — all with exact commands, config snippets, verification steps, and rollback procedures.

Raymond Ops
Raymond Ops
Raymond Ops

Problem Background

SSH is the most common remote management protocol for Linux servers and the primary target for attackers. Weak passwords, brute-force attacks, and unauthorized access are frequent. This guide applies to ops engineers, sysadmins, security engineers, and DevOps engineers configuring bastion hosts. SSH security characteristics: default config is insecure, it's a primary attack target, requires multi-layer defense, and must balance security with usability.

Applicable Scenarios

New server initialization

Production environment hardening

Compliance-driven SSH configuration

Bastion/jump-host setup

Multi-user SSH permission management

Brute-force prevention

Audit and log management

Not suitable for: desktop Linux (lower security needs), dev/test environments (can relax restrictions), containers (running SSH inside containers is discouraged; use docker exec or kubectl exec instead).

Core Knowledge Points

SSH Authentication Methods

Password auth : simple but vulnerable to brute-force, leakage, hard to manage.

Key auth : high security, resistant to cracking, supports automation; key management is complex, initial setup tedious.

2FA : highest security; complex config, depends on third-party tools.

SSH Key Types

RSA : 2048/4096 bits, high security (4096), moderate performance, best compatibility.

ECDSA : 256/384/521 bits, high security, good performance, good compatibility.

Ed25519 : fixed 256 bits, highest security, best performance, requires OpenSSH 6.5+.

Recommendation: Ed25519 or RSA 4096.

SSH Config Files

Server: /etc/ssh/sshd_config, /etc/ssh/ssh_host_*_key Client: ~/.ssh/config (user), /etc/ssh/ssh_config (system), ~/.ssh/authorized_keys,

~/.ssh/known_hosts

SSH Attack Vectors & Defenses

Brute-force : dictionary/common passwords → disable password login, use fail2ban, limit attempts.

Man-in-the-middle : spoof server, steal creds → verify host fingerprints, use certificate auth.

Key leakage : key files stolen → encrypt keys, control permissions, rotate regularly.

Port scanning : scan port 22 → change default port, firewall restrictions.

Overall Hardening Strategy: Defense in Depth

Network layer protection
  ↓
Authentication hardening
  ↓
Authorization control
  ↓
Audit logging
  ↓
Continuous monitoring

Modify defaults (port, protocol version)

Disable password login, enable key auth

Restrict login users and source IPs

Configure key permissions and management

Enable 2FA (optional)

Configure firewall and fail2ban

Configure logging and audit

Regular checks and updates

Practical Steps

Step 1: Backup Existing Config

Purpose: ensure quick rollback.

# Backup SSH server config
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup_$(date +%Y%m%d_%H%M%S)

# Backup SSH client config
cp /etc/ssh/ssh_config /etc/ssh/ssh_config.backup_$(date +%Y%m%d_%H%M%S)

# Backup user SSH config
cp ~/.ssh/config ~/.ssh/config.backup_$(date +%Y%m%d_%H%M%S)

# Backup authorized_keys
cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.backup_$(date +%Y%m%d_%H%M%S)

Risk reminders : must backup before changes; keep at least one active SSH session (don't close current); test with new session before closing old.

Step 2: Generate SSH Key Pair

2.1 Generate Ed25519 (Recommended)

# On client (local machine)
ssh-keygen -t ed25519 -C "[email protected]"

# Specify key filename
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_server1 -C "server1_access"

# Set passphrase (recommended) — prompted during generation

Expected output shows key generation, fingerprint (SHA256), and saved paths.

2.2 Generate RSA 4096 (Compatibility)

ssh-keygen -t rsa -b 4096 -C "[email protected]"
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_server1 -C "server1_access"

2.3 View Generated Keys

# View private key (never share)
cat ~/.ssh/id_ed25519

# View public key (can share)
cat ~/.ssh/id_ed25519.pub

# View fingerprint
ssh-keygen -l -f ~/.ssh/id_ed25519.pub

# List all keys
ls -la ~/.ssh/

2.4 Set Key Permissions

# Private key must be 600 (owner read/write only)
chmod 600 ~/.ssh/id_ed25519

# Public key can be 644
chmod 644 ~/.ssh/id_ed25519.pub

# .ssh directory must be 700
chmod 700 ~/.ssh/

Logic: incorrect private key permissions → SSH refuses key; incorrect .ssh dir permissions → SSH ignores configs in that dir.

Step 3: Upload Public Key to Server

3.1 Using ssh-copy-id (Recommended)

ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server-ip
ssh-copy-id -i ~/.ssh/id_ed25519.pub -p 2222 user@server-ip
# If password login disabled, temporarily enable or use alternative upload

Expected output shows key installation progress and success message.

3.2 Manual Upload

# Method 1: scp
scp ~/.ssh/id_ed25519.pub user@server-ip:/tmp/
ssh user@server-ip
mkdir -p ~/.ssh
chmod 700 ~/.ssh
cat /tmp/id_ed25519.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
rm /tmp/id_ed25519.pub

# Method 2: copy-paste
cat ~/.ssh/id_ed25519.pub
# On server:
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... [email protected]" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

3.3 Verify Upload

cat ~/.ssh/authorized_keys
ssh -i ~/.ssh/id_ed25519 user@server-ip
# Success if login works without password prompt

Step 4: Configure SSH Server

4.1 Edit sshd_config

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
vim /etc/ssh/sshd_config

Recommended configuration (key sections):

# Basic
Port 22222                     # Change default port (optional but recommended)
AddressFamily inet             # IPv4 only (if IPv6 not needed)
ListenAddress 0.0.0.0          # Listen on all IPs (or specify)

# Protocol & algorithms
Protocol 2                     # SSH protocol v2 only
HostKey /etc/ssh/ssh_host_ed25519_key
HostKey /etc/ssh/ssh_host_rsa_key

# Strong ciphers only
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
MACs [email protected],[email protected],hmac-sha2-512,hmac-sha2-256
KexAlgorithms curve25519-sha256,[email protected],diffie-hellman-group-exchange-sha256

# Authentication
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no      # Disable password auth
PermitEmptyPasswords no
ChallengeResponseAuthentication no
UsePAM yes                     # For logging & session mgmt

# Login control
PermitRootLogin no             # Block root login
MaxAuthTries 3
MaxSessions 10
MaxStartups 10:30:60           # Concurrent connection limits

# Access control (whitelist)
AllowUsers deploy ops          # Only allow specific users
# AllowGroups sshusers         # Or specific groups
# DenyUsers baduser            # Deny specific users
# DenyGroups badgroup

# Session
ClientAliveInterval 300        # 5 min keepalive
ClientAliveCountMax 2
LoginGraceTime 60
TCPKeepAlive yes

# Forwarding & tunnels (disable unless needed)
X11Forwarding no
AllowTcpForwarding no
AllowStreamLocalForwarding no
GatewayPorts no
PermitTunnel no

# Other security
PermitUserEnvironment no
StrictModes yes                # Strict file permission checks
IgnoreRhosts yes
HostbasedAuthentication no
PrintMotd yes
PrintLastLog yes
Banner /etc/ssh/banner         # Pre-login warning (optional)

# Logging
SyslogFacility AUTH
LogLevel VERBOSE               # Detailed logs incl. key fingerprints

# Subsystem
Subsystem sftp /usr/libexec/openssh/sftp-server

Key config explanations :

Port : default 22 is heavily scanned; changing to non-standard (e.g., 22222) reduces noise; firewall must be updated accordingly.

PermitRootLogin no : force regular user + sudo; if root login required, use prohibit-password (key-only).

PasswordAuthentication no : disable password auth after key setup confirmed; ensures keys are configured first.

AllowUsers/AllowGroups : whitelist approach; prefer AllowUsers; use AllowGroups for many users.

ClientAliveInterval : sends keepalive packets to prevent firewall timeouts and detect dead connections.

LogLevel VERBOSE : logs key fingerprints; INFO for routine; DEBUG not for production.

4.2 Create Login Banner (Optional)

cat > /etc/ssh/banner << 'EOF'
###############################################################################
#                              WARNING                                        #
###############################################################################
# Unauthorized access to this system is forbidden and will be prosecuted by  #
# law. By accessing this system, you agree that your actions may be monitored#
# if unauthorized usage is suspected.                                        #
###############################################################################
EOF
# Enable in sshd_config: Banner /etc/ssh/banner

4.3 Check Config Syntax

sshd -t
# or
/usr/sbin/sshd -t
# No output = OK; errors show line numbers

4.4 Reload SSH Service

Risk : reload may drop current connection; keep a session open; test with new session.

# Reload (keeps existing connections, recommended)
systemctl reload sshd

# Restart (drops connections, not recommended)
systemctl restart sshd

systemctl status sshd
journalctl -u sshd -f

4.5 Test SSH Connection

Keep current session; open new terminal:

# Test key login
ssh -i ~/.ssh/id_ed25519 user@server-ip -p 22222

# Test password login (should be rejected)
ssh user@server-ip -p 22222

# Test root login (should be rejected)
ssh root@server-ip -p 22222

Expected: key login succeeds; password and root logins denied. If fails: don't close current session; check config; view logs with journalctl -u sshd -f; fix and retest; only close old session after success.

Step 5: Configure SSH Client

5.1 Edit ~/.ssh/config

vim ~/.ssh/config
chmod 600 ~/.ssh/config

Example config:

# Defaults
Host *
    Ciphers [email protected],[email protected],[email protected]
    MACs [email protected],[email protected]
    KexAlgorithms curve25519-sha256,[email protected]
    ServerAliveInterval 60
    ServerAliveCountMax 3
    TCPKeepAlive yes
    ControlMaster auto
    ControlPath ~/.ssh/sockets/%r@%h:%p
    ControlPersist 600
    Compression yes
    ForwardAgent no
    ForwardX11 no
    StrictHostKeyChecking ask
    HashKnownHosts yes

# Production servers
Host prod-web1
    HostName 192.168.1.101
    Port 22222
    User deploy
    IdentityFile ~/.ssh/id_ed25519_prod
    ForwardAgent no

Host prod-web2
    HostName 192.168.1.102
    Port 22222
    User deploy
    IdentityFile ~/.ssh/id_ed25519_prod

# Jump host
Host jump
    HostName 1.2.3.4
    Port 22222
    User jump_user
    IdentityFile ~/.ssh/id_ed25519_jump

# Via jump host to internal
Host internal-*
    ProxyJump jump
    User deploy
    IdentityFile ~/.ssh/id_ed25519_internal

Host internal-db1
    HostName 10.0.1.101
    Port 22

Host internal-db2
    HostName 10.0.1.102
    Port 22

# Dev env
Host dev-*
    User developer
    IdentityFile ~/.ssh/id_ed25519_dev
    ForwardAgent yes

Host dev-web1
    HostName 192.168.2.101

Config explanations :

ControlMaster/ControlPath/ControlPersist : connection multiplexing — multiple sessions share one connection; speeds up, reduces auth; ControlPersist 600 keeps master 600s after idle.

ServerAliveInterval/ServerAliveCountMax : client-side keepalive to prevent firewall drops; 60s interval, max 3 probes.

ProxyJump : jump-host access; cleaner than ProxyCommand; equivalent to ssh -J jump internal-db1.

ForwardAgent : forwards local SSH agent to remote; risk: remote can use your keys to access other hosts; enable only when needed, default off.

5.2 Using Config Aliases

ssh prod-web1
# Equivalent to: ssh -i ~/.ssh/id_ed25519_prod -p 22222 [email protected]

ssh internal-db1
# Equivalent to: ssh -J [email protected]:22222 [email protected]

5.3 Create Multiplexing Directory

mkdir -p ~/.ssh/sockets
chmod 700 ~/.ssh/sockets

Step 6: Configure sudo Permissions

6.1 Create Regular User

useradd -m -s /bin/bash deploy
passwd deploy
# Or with specific UID/GID
useradd -m -s /bin/bash -u 1001 -g 1001 deploy

6.2 Configure sudoers

visudo
# Or separate file
vim /etc/sudoers.d/deploy

Examples:

# deploy runs all commands without password
deploy ALL=(ALL) NOPASSWD: ALL

# deploy runs specific commands without password
deploy ALL=(ALL) NOPASSWD: /usr/bin/systemctl, /usr/bin/docker

# ops group runs all without password
%ops ALL=(ALL) NOPASSWD: ALL

# Require password
deploy ALL=(ALL) ALL

Notes : NOPASSWD = no password prompt; ALL=(ALL) ALL = any user, any command; specific commands restrict scope; %ops = group.

Risk : NOPASSWD: ALL high risk — only for automation; production should require password or limit commands.

6.3 Test sudo

su - deploy
sudo whoami          # Should output: root
sudo -l              # List privileges
sudo systemctl status sshd

Step 7: Configure Firewall

7.1 iptables

iptables -F
iptables -X

# Default policies
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

# Loopback
iptables -A INPUT -i lo -j ACCEPT

# Established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow specific IPs to SSH (adjust port)
iptables -A INPUT -p tcp -s 1.2.3.4 --dport 22222 -j ACCEPT
iptables -A INPUT -p tcp -s 5.6.7.0/24 --dport 22222 -j ACCEPT

# Drop other SSH
iptables -A INPUT -p tcp --dport 22222 -j DROP

# Other services
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

# Save
iptables-save > /etc/iptables/rules.v4
# CentOS/RHEL: service iptables save

Risk : keep current SSH session; test in staging first.

7.2 firewalld

firewall-cmd --list-all
firewall-cmd --permanent --remove-service=ssh
firewall-cmd --permanent --add-port=22222/tcp
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="1.2.3.4" port port="22222" protocol="tcp" accept'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="5.6.7.0/24" port port="22222" protocol="tcp" accept'
firewall-cmd --reload
firewall-cmd --list-all

7.3 Cloud Security Groups (Preferred for Cloud VMs)

Alibaba Cloud, Tencent Cloud, AWS Security Groups, Azure NSGs. Example inbound rules:

Protocol  Port    Source          Action
TCP       22222   1.2.3.4/32      Allow
TCP       22222   5.6.7.0/24      Allow
TCP       80      0.0.0.0/0       Allow
TCP       443     0.0.0.0/0       Allow
ALL       ALL     Others          Deny

Step 8: Configure fail2ban

8.1 Install

# CentOS/RHEL
yum install -y epel-release
yum install -y fail2ban

# Ubuntu/Debian
apt install -y fail2ban

systemctl start fail2ban
systemctl enable fail2ban

8.2 Configure

cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
vim /etc/fail2ban/jail.local

Example jail.local:

[DEFAULT]
ignoreip = 127.0.0.1/8 ::1 1.2.3.4
bantime = 3600          # 1 hour
findtime = 600          # 10 min window
maxretry = 3            # 3 failures → ban
destemail = [email protected]
sendername = Fail2Ban
mta = sendmail
action = %(action_mwl)s

[sshd]
enabled = true
port = 22222
filter = sshd
logpath = /var/log/secure   # CentOS/RHEL
# logpath = /var/log/auth.log  # Ubuntu/Debian
maxretry = 3
bantime = 3600
findtime = 600

Params : bantime (ban duration), findtime (detection window), maxretry (failure threshold), logpath (log file).

8.3 Start & Check

systemctl restart fail2ban
systemctl status fail2ban
fail2ban-client status sshd

Expected output shows filter/actions with zero failed/banned initially.

8.4 Test

# Fail password 3 times
ssh user@server-ip -p 22222

# Check ban status
fail2ban-client status sshd

# Manual unban
fail2ban-client set sshd unbanip 1.2.3.4

# Manual ban
fail2ban-client set sshd banip 1.2.3.4

Step 9: Logging & Audit

9.1 SSH Logs

Default locations: CentOS/RHEL /var/log/secure; Ubuntu/Debian /var/log/auth.log.

grep sshd /var/log/secure
 grep "Accepted" /var/log/secure
 grep "Failed" /var/log/secure
 grep "user deploy" /var/log/secure
 grep "1.2.3.4" /var/log/secure
 tail -f /var/log/secure | grep sshd

9.2 Command Audit via script

Add to user's .bashrc or .bash_profile:

if [ -z "$SCRIPT_LOG" ]; then
  export SCRIPT_LOG=1
  logdir=/var/log/user_commands
  mkdir -p $logdir
  logfile=$logdir/$(whoami)_$(date +%Y%m%d_%H%M%S).log
  script -q -a -f $logfile
  exit
fi

Risks : disk usage, sensitive data in logs, log dir needs root perms so users can't delete.

9.3 auditd

# Install
yum install -y audit      # CentOS/RHEL
apt install -y auditd     # Ubuntu/Debian

systemctl start auditd
systemctl enable auditd

# Watch SSH files
auditctl -w /etc/ssh/sshd_config -p wa -k sshd_config
auditctl -w /etc/ssh/ssh_host_rsa_key -p wa -k ssh_host_key
auditctl -w /home/ -p wa -k home_directory

# View rules
auditctl -l

# Search logs
ausearch -k sshd_config
ausearch -k ssh_host_key

# Report
aureport --summary

Step 10: Key Management & Rotation

10.1 Rotate Keys

ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_new -C "new_key"
ssh-copy-id -i ~/.ssh/id_ed25519_new.pub user@server-ip
ssh -i ~/.ssh/id_ed25519_new user@server-ip
# After verification, remove old key from server's authorized_keys
vim ~/.ssh/authorized_keys
mv ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.old
mv ~/.ssh/id_ed25519_new ~/.ssh/id_ed25519

10.2 Revoke Leaked Keys

vim ~/.ssh/authorized_keys  # Delete compromised public key line
ssh-keygen -R hostname      # Remove host fingerprint from known_hosts

10.3 Backup Keys (Encrypted)

tar -czf ssh_keys_backup.tar.gz ~/.ssh/
gpg -c ssh_keys_backup.tar.gz
rm ssh_keys_backup.tar.gz
# Store offline / in password manager

Step 11: Enable 2FA (Optional)

11.1 Install Google Authenticator

# CentOS/RHEL
yum install -y google-authenticator

# Ubuntu/Debian
apt install -y libpam-google-authenticator

11.2 Configure per User

google-authenticator
# Prompts:
# Time-based tokens? y
# Scan QR / enter secret in phone app
# Update ~/.google_authenticator? y
# Disallow token reuse? y
# Increase time window? n
# Enable rate-limiting? y

11.3 PAM Config

# Edit /etc/pam.d/sshd, add at top:
auth required pam_google_authenticator.so

11.4 SSH Config for 2FA

# /etc/ssh/sshd_config
ChallengeResponseAuthentication yes
AuthenticationMethods publickey,keyboard-interactive

11.5 Restart & Test

systemctl restart sshd
ssh user@server-ip
# Prompts: Verification code: (enter 6-digit from app)

Step 12: Jump Host / Bastion

12.1 Architecture

User → Jump Host → Internal Servers

Key points: restrict jump host users; jump→internal uses keys; log all operations; limit jump host perms (only SSH forwarding).

12.2 Jump Host sshd_config

AllowUsers jump_user1 jump_user2
ForceCommand /bin/false          # No shell, only port forwarding
# Or restricted menu:
ForceCommand /usr/local/bin/jump_menu.sh

AllowTcpForwarding yes
GatewayPorts no
LogLevel VERBOSE

12.3 Jump Menu Script

#!/bin/bash
logger -t JUMP "User $USER logged in from $SSH_CLIENT"
cat << EOF
=== Jump Server Menu ===
1) Connect to prod-web1
2) Connect to prod-web2
3) Connect to prod-db1
4) Exit
========================
EOF
read -p "Select option: " option
case $option in
  1) ssh [email protected] ;;
  2) ssh [email protected] ;;
  3) ssh [email protected] ;;
  4) exit 0 ;;
  *) echo "Invalid option"; exit 1 ;;
esac

12.4 Client ProxyJump Config

Host jump
    HostName jump.example.com
    Port 22222
    User jump_user
    IdentityFile ~/.ssh/id_ed25519_jump

Host prod-web1
    HostName 10.0.1.101
    User deploy
    Port 22
    ProxyJump jump
    IdentityFile ~/.ssh/id_ed25519_prod

Connect: ssh prod-web1 (equivalent to ssh -J [email protected]:22222 [email protected]).

Common Commands

SSH Key Management

ssh-keygen -t ed25519 -C "[email protected]"
ssh-keygen -t rsa -b 4096 -C "[email protected]"
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server-ip
ssh-keygen -l -f ~/.ssh/id_ed25519.pub
ssh-keygen -p -f ~/.ssh/id_ed25519
ssh -v user@server-ip

SSH Service Management

sshd -t
systemctl reload sshd
systemctl restart sshd
systemctl status sshd
journalctl -u sshd -f
tail -f /var/log/secure

fail2ban Management

fail2ban-client status
fail2ban-client status sshd
fail2ban-client set sshd unbanip 1.2.3.4
fail2ban-client set sshd banip 1.2.3.4
fail2ban-client reload

Log Analysis

grep "Accepted" /var/log/secure
grep "Failed" /var/log/secure
grep "Failed password" /var/log/secure | awk '{print $(NF-3)}' | sort | uniq -c | sort -rn
w
who
last
lastlog

Risk Warnings

High-Risk Operations

Disable password auth : if key not configured/lost → lockout. Pre-check: key tested, keep session, rollback plan.

Change SSH port : firewall out of sync → lockout. Pre-check: firewall rules ready, keep session.

Block root login : regular user lacks sudo → no admin access. Pre-check: sudo works for user.

Firewall changes : wrong rules → lockout. Pre-check: keep session, test in staging.

Common Pitfalls

Closing current session after disabling password — keep session, test new, then close.

Private key perms set to 644 — must be 600 or SSH refuses.

Running SSH in containers — violates container philosophy; use docker exec / kubectl exec.

All users with NOPASSWD: ALL — high risk; production should require password or limit commands.

Using systemctl restart sshd instead of reload — restart drops connections; reload keeps them.

Verification

Key login works without password prompt.

Password login rejected with Permission denied (publickey).

Root login rejected.

Firewall: allowed IPs connect; others timeout/rejected.

fail2ban: 3 failed attempts → IP appears in banned list.

Rollback Procedures

SSH Config

cp /etc/ssh/sshd_config.backup /etc/ssh/sshd_config
sshd -t
systemctl reload sshd

Firewall

# iptables
iptables-restore < /etc/iptables/rules.v4.backup

# firewalld
firewall-cmd --reload

fail2ban

systemctl stop fail2ban
rm -f /var/lib/fail2ban/*
cp /etc/fail2ban/jail.local.backup /etc/fail2ban/jail.local
systemctl start fail2ban

Production Checklist

Pre-Operation

Backup configs

Keep active SSH session

Prepare rollback

Validate in test env

Notify teams

During Operation

Configure incrementally, test each change

Use systemctl reload, not restart Ready to rollback anytime

Document all actions

Post-Operation Verification

Test key login

Test password login (denied)

Test firewall rules

Test fail2ban

Review logs

Ongoing Maintenance

Rotate keys regularly

Review logs regularly

Update SSH version

Audit user permissions

Test backup restoration

Summary

SSH hardening is foundational to server security, requiring defense in depth:

Auth hardening : disable passwords, enable keys

Access control : restrict users/IPs, block root

Network protection : change port, firewall, fail2ban

Permission management : sudo, jump host

Audit logging : record all SSH activity, regular audits

Continuous maintenance : rotate keys, review configs

Critical configs: PasswordAuthentication no, PermitRootLogin no, PubkeyAuthentication yes, AllowUsers, Port (optional). Security is continuous — monitor, audit, improve; balance security and usability.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

OperationsLinuxSecuritySSHHardeningBastion-HostSSH-KeysFail2ban
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.