How do you set up SSH key authentication?

Why Interviewers Ask This

This question targets practical, hands-on experience with Linux / Shell Scripting. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.

Answer

SSH key authentication uses asymmetric cryptography to authenticate without passwords. Steps: (1) Generate a key pair on the client: ssh-keygen -t ed25519 -C "your_email" (or RSA: -t rsa -b 4096). This creates ~/.ssh/id_ed25519 (private) and ~/.ssh/id_ed25519.pub (public). (2) Copy the public key to the server: ssh-copy-id user@server (or manually append to ~/.ssh/authorized_keys on the server). (3) Ensure server permissions: ~/.ssh must be 700, authorized_keys must be 600. (4) Optionally disable password auth in /etc/ssh/sshd_config: set PasswordAuthentication no. Use ssh-agent and ssh-add to avoid entering the passphrase repeatedly.

Pro Tip

This topic has Linux / Shell Scripting-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.