git

🏠 Homepage

⬅️ Previous: πŸ“‚ Understanding Repositories (Local vs Remote)

8. πŸ” Setting up SSH Keys

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

Why SSH is Important

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:

Generating SSH keys Pair on Local Machine

Open your terminal and run the following command to generate a new SSH key:

ssh-keygen -t ed25519 -C "your_email@example.com"

Explanation:

What if I just run ssh-keygen?

If you run:

ssh-keygen

By default:

πŸ“ Recommendation: Always use ed25519 unless you need RSA for legacy systems

Add SSH Public Key to GitHub

  1. Locate your public key:
    cat ~/.ssh/id_ed25519.pub
    
  2. Copy the output, which looks like this:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE... your_email@example.com
  1. Go to GitHub β†’ Settings β†’ SSH and GPG keys β†’ New SSH key.

  2. Paste the key, give it a name (e.g., My Laptop), and save.

Verifying SSH Connection to GitHub

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! πŸŽ‰

Example: Using SSH with Git

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!

Final Thoughts

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