How does GitHub handle SSH authentication?
Why Interviewers Ask This
Mid-level Git & GitHub roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.
Answer
SSH authentication lets you interact with GitHub without typing username/password for every push/pull. Setup: (1) Generate SSH key pair: ssh-keygen -t ed25519 -C "your@email.com" — creates ~/.ssh/id_ed25519 (private key, NEVER share) and ~/.ssh/id_ed25519.pub (public key); (2) Add public key to GitHub: Settings → SSH and GPG keys → New SSH key → paste contents of ~/.ssh/id_ed25519.pub; (3) Add private key to SSH agent: eval "$(ssh-agent -s)"; ssh-add ~/.ssh/id_ed25519; (4) Test connection: ssh -T git@github.com — should print "Hi username! You've successfully authenticated."; (5) Use SSH URLs: git clone git@github.com:user/repo.git or change existing remote: git remote set-url origin git@github.com:user/repo.git. Multiple GitHub accounts: configure ~/.ssh/config with different Host entries using different keys. SSH vs HTTPS: SSH is more convenient (no token re-entry), better for developers. HTTPS with personal access tokens is preferred in CI/CD environments. GitHub also supports Fine-grained personal access tokens for repository-specific permissions.
Pro Tip
This topic has Git & GitHub-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.