The real hardening happens in /etc/ssh/sshd_config.
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup.$(date +%F)sudo nano /etc/ssh/sshd_configProduction Configuration
# Network SettingsPort 2222AddressFamily inetListenAddress 0.0.0.0
# AuthenticationPermitRootLogin noPubkeyAuthentication yesPasswordAuthentication noPermitEmptyPasswords noChallengeResponseAuthentication noUsePAM yes
# Key Types (ED25519 preferred)PubkeyAcceptedKeyTypes ssh-ed25519,rsa-sha2-512,rsa-sha2-256
# Limit user accessAllowUsers deployer sysadmin# AllowGroups ssh-users
# Session SettingsMaxAuthTries 3MaxSessions 2LoginGraceTime 30ClientAliveInterval 300ClientAliveCountMax 2
# Disable Dangerous FeaturesX11Forwarding noPermitUserEnvironment noAllowAgentForwarding noAllowTcpForwarding noPermitTunnel no
# LoggingSyslogFacility AUTHLogLevel VERBOSE
# Modern Cryptography (2025)KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.orgCiphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.comMACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com
# SecurityHostbasedAuthentication noIgnoreRhosts yesValidate and Restart
sudo sshd -tsudo systemctl restart sshdsudo systemctl status sshdDanger
Keep your current session open. Open a new terminal and test the connection before closing the original.
Update Firewall
# UFW (Ubuntu/Debian)sudo ufw allow 2222/tcpsudo ufw delete allow 22/tcpsudo ufw reload
# firewalld (RHEL/CentOS)sudo firewall-cmd --permanent --add-port=2222/tcpsudo firewall-cmd --permanent --remove-service=sshsudo firewall-cmd --reloadNext Steps
Proceed to the Two-Factor Authentication guide.