SSH gives remote shell access, so it deserves care. The main steps are key authentication, no direct root password login, and a short list of who may log in.
Set up a key first
On your own computer:
$ ssh-keygen -t ed25519
$ ssh-copy-id [email protected]
$ ssh [email protected]Set a passphrase when asked. The private key stays on your computer; only the .pub file goes to the server, into ~/.ssh/authorized_keys. On first connection, compare the host key fingerprint with one obtained by a trusted route before answering yes.
Tighten the server
Server settings are in /etc/ssh/sshd_config and often in files under /etc/ssh/sshd_config.d/.
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
AllowUsers maria samAllowUsers blocks everyone not listed, so check names carefully. Older releases use ChallengeResponseAuthentication for the keyboard setting.
For most keywords, sshd uses the first value it reads. A file included near the top can therefore override a later line. Check the effective values:
$ sudo sshd -T | grep -E 'permitrootlogin|passwordauthentication'
permitrootlogin no
passwordauthentication noWithout a connection specification, this may not show what applies inside Match blocks.
Apply safely
$ sudo sshd -t
$ sudo systemctl reload sshsshd -t prints nothing when the configuration is valid. The service is usually ssh on Debian and Ubuntu and sshd on Fedora and RHEL.
Keep your current session open. In a second terminal, log in again with your key. Only close the first session when that works. Have console access as a fallback.
Keep watching
Review authorized_keys files and remove old keys. Limit the SSH port to trusted sources where you can. Changing the port number reduces noisy log entries but is not real protection. Failed logins appear in journalctl -u ssh or -u sshd.
Try it
Generate a key on a test machine and view the public half with cat ~/.ssh/id_ed25519.pub. Do not overwrite a key you already use. Then try the SSH lab.
Check your understanding
SSH Access
All 3 sections · no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.