SSH: key login, hardening sshd_config
Sign in to read this lesson
SSH is the main door into a server, and every internet-facing server sees dozens of password attempts a second. In this lesson we learn to replace passwords with keys, block root logins, change sshd_config safely, move the SSH port together with SELinux and firewalld, and make daily work easier with ~/.ssh/config.
What you will learn
- A key pair:
ssh-keygen -t ed25519;ssh-copy-id ops1@srv-db01copies the public key to the server (~/.ssh/authorized_keys). - Permissions:
~/.ssh—700,authorized_keys—600, the private key —600; with wrong permissions sshd rejects the key. - Hardening:
PermitRootLogin no,PasswordAuthentication no(after the key works),MaxAuthTries 3,AllowGroups wheel sshusers. - Write settings to
/etc/ssh/sshd_config.d/*.conf, check withsshd -t,systemctl reload sshd; do not close your open session. - Changing the port:
Port 2222+semanage port -a -t ssh_port_t -p tcp 2222+firewall-cmd --add-port=2222/tcp.
The lesson has 5 key points, an explanation and 5 questions. It opens with a package.