What is the difference between SSH key authentication and password authentication?
Password authentication: User provides a password. Vulnerable to brute-force attacks, password spraying, and phishing. Should be disabled for SSH in production.
SSH Key authentication: The client proves ownership of a private key without ever transmitting it. The server holds the public key in ~/.ssh/authorized_keys. Private key never leaves the client.
# Generate key pair
ssh-keygen -t ed25519 -C "anmol@devopsinterview.com"
# Copy public key to server
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server
# Disable password auth in /etc/ssh/sshd_config
PasswordAuthentication no
Use ed25519 keys — they are faster and more secure than RSA 2048.