Skip to main content

SSH Hardening

Updated Mar 11, 2022 ·

SSH Access Control

Control who can connect and how they authenticate.

PracticeKey PointsExample / Config
Limit SSH AccessOnly allow users who require admin access/etc/ssh/sshd_configAllowUsers user1 user2
Disable root loginUse sudo with non-root accounts/etc/ssh/sshd_configPermitRootLogin no
IP whitelistingRestrict SSH access to specific IPsFirewall rules or Kubernetes Network Policies
Use bastion hostsRoute external access through a jump serverN/A

Authentication and Keys

Ensure secure login methods and key management.

PracticeKey PointsExample / Config
Use SSH keysPrefer public-key auth over passwordsssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
Disable password authPrevent password logins/etc/ssh/sshd_configPasswordAuthentication no
Key managementSecure private keys; use strong keysssh-keygen -t ed25519
Rotate keys regularlyEspecially for admin accountsN/A
Two-factor authenticationAdd extra verification layerGoogle Authenticator or Duo integration

SSH Configuration Hardening

Improve security through SSH server settings by editing /etc/ssh/sshd_config.

PracticeKey PointsExample / Config
Change default portAvoid port 22 to reduce attacksPort 2222
Use strong encryptionDisable weak algorithmsCiphers aes256-gcm@openssh.com
SSH bannerDisplay login policy messagesBanner /etc/issue
Logging and auditingMonitor access and review logsLogLevel VERBOSE

Additional: Implementing idle timeout.

## /etc/ssh/sshd_config
ClientAliveInterval 300
ClientAliveCountMax 0

Container and Host Security

Protect underlying systems and container environments.

PracticeKey PointsExample / Config
Avoid SSH in containersUse native tools insteadkubectl exec
Host hardeningKeep nodes updated, minimal installs, disable unused servicesN/A
Regular security auditsTest access controls and configsN/A
Use security toolsImplement tools like Fail2Ban or OSSEC for intrusion detectionN/A