SSH & Key Authentication

Secure Shell (SSH)

CommandPurpose
ssh user@hostConnect
ssh -p 2222 user@hostCustom port
ssh-keygen -t ed25519Generate a key pair
ssh-copy-id user@hostInstall your public key
scp file user@host:/pathCopy over SSH
sftp user@hostInteractive file transfer

Key auth uses a private key (~/.ssh/id_ed25519, keep secret) and a public key (~/.ssh/id_ed25519.pub, goes in the server's ~/.ssh/authorized_keys).

Server hardening in /etc/ssh/sshd_config:

PermitRootLogin no
PasswordAuthentication no      # keys only
Port 2222

Apply with systemctl reload sshd.

Exam trap: ~/.ssh must be 700 and authorized_keys 600, or sshd refuses the key. Wrong permissions are the #1 cause of "key auth won't work".