Git & GitHub
/Intermediate
SSH Keys
Definition
An access credential in the SSH protocol. Its function is similar to that of user names and passwords, but the keys are primarily used for automated processes and secure computer-to-computer connections.
Explain Like I'm New
A digital ID card for your computer. Instead of typing your username and password every time you `git push`, you generate a cryptographic key pair (a public key and a private key). You give GitHub your public key. Now, GitHub recognizes your laptop instantly and securely.
Real World Example
Generating an `id_rsa` key on your Mac, pasting the `.pub` file into your GitHub settings, and never typing a password again.
Common Use Cases
- •Passwordless authentication
- •Secure data transfer
Terminal Output
bash / terminal
# 1. Generate a new SSH key on your computer
$ ssh-keygen -t ed25519 -C "your_email@example.com"
# 2. View your public key and copy it to your clipboard
$ cat ~/.ssh/id_ed25519.pub
# 3. Go to GitHub -> Settings -> SSH and GPG keys -> New SSH key. Paste it.
# 4. Test the connection!
$ ssh -T git@github.com
# Output: Hi Username! You've successfully authenticated...
Interview Questions
basic
- Which key do you upload to GitHub: the public key or the private key?
intermediate
- Why did GitHub remove password authentication for Git commands in 2021?