π Homepage
β¬ οΈ Previous: π Understanding Repositories (Local vs Remote)
SSH (Secure Shell) keys are a secure way to authenticate with GitHub and other Git-based platforms without using your username and password each time you interact with your repositories. In this guide, weβll walk through how to generate SSH keys, add them to GitHub, and verify your setup.
SSH provides a secure channel for communication between your computer and GitHub. Instead of sending your credentials in plaintext (which is insecure), SSH uses cryptographic keys for authentication.
Benefits of SSH:
Open your terminal and run the following command to generate a new SSH key:
ssh-keygen -t ed25519 -C "your_email@example.com"
Explanation:
ssh-keygen
: Command to generate the key.
-t ed25519
: Specifies the key type. ed25519 is modern, secure, and faster than the older rsa type.
-C "your_email@example.com"
: A label/comment to help identify the key (usually your email).
ssh-keygen
?If you run:
ssh-keygen
By default:
ed25519
.π Recommendation: Always use ed25519
unless you need RSA for legacy systems
cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE... your_email@example.com
Go to GitHub β Settings β SSH and GPG keys β New SSH key.
Paste the key, give it a name (e.g., My Laptop), and save.
After adding your key, test the connection:
ssh -T git@github.com
Expected output:
Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.
If you see this, youβre all set! π
Clone a repo via SSH:
git clone git@github.com:your-username/your-repo.git
Push changes:
git add .
git commit -m "Set up SSH"
git push origin main
You wonβt be prompted for a password!
Setting up SSH keys is a one-time task that saves time and enhances security in your development workflow. Itβs especially useful if:
β‘οΈUp Next: π Connecting local repo to GitHub using SSH & Push to origin