๐Ÿ” Setup SSH for Git (No More Username & Password Every Time)


๐Ÿšจ Problem

When you run:

git pull

Git asks every time:

  • Username ๐Ÿ˜ฉ
  • Password / Token ๐Ÿ˜ฉ

This is annoying and slows you down.


โœ… Solution: Use SSH Instead of HTTPS

SSH lets you connect to Git without entering credentials every time.


๐Ÿงฉ Step 1: Check if SSH Key Already Exists

Run:

ls ~/.ssh

If you see files like:

  • id_rsa
  • id_rsa.pub

๐Ÿ‘‰ You already have an SSH key (skip to Step 3)


๐Ÿ”‘ Step 2: Generate SSH Key

Run:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Press Enter for all prompts.

๐Ÿ‘‰ This creates:

  • Private key (keep safe ๐Ÿ”’)
  • Public key (we will upload)

๐Ÿ”‘ ssh-keygen Command (Short)

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

๐Ÿง  Meaning

  • ssh-keygen โ†’ create SSH key
  • -t rsa โ†’ key type
  • -b 4096 โ†’ strong security
  • -C โ†’ email label

๐ŸŽฏ Output

Creates:

  • Private key ๐Ÿ”’
  • Public key ๐Ÿ”‘

๐Ÿ‘‰ Used for GitHub login without password


๐Ÿ“‹ Step 3: Copy SSH Public Key

Run:

cat ~/.ssh/id_rsa.pub

Copy the output.

๐Ÿ” Sample of key
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMyZ5kK8sJf8J7xK3lD9abcXYZ1234567890 your_email@example.com
๐Ÿง  Structure Explained
  • ssh-rsa โ†’ Key type (can also be ed25519)
  • AAAAB3... โ†’ Actual key (long encoded string)
  • email โ†’ Your email (label, optional)

๐ŸŒ Step 4: Add SSH Key to GitHub

  1. Go to: https://github.com/settings/keys
  2. Click New SSH Key
  3. Paste your key
  4. Click Add SSH Key

๐Ÿ”— Step 5: Change Repo URL to SSH

Check current remote:

git remote -v

If it shows HTTPS like:

https://github.com/user/repo.git

Change it to SSH:

git remote set-url origin git@github.com:user/repo.git

๐Ÿงช Step 6: Test SSH Connection

Run:

ssh -T git@github.com

You should see:

Hi username! You've successfully authenticated...

๐Ÿš€ Done!

Now try:

git pull

โœ… No username โœ… No password โœ… Super fast


๐ŸŽฏ Final Summary

  • HTTPS โ†’ asks login every time โŒ
  • SSH โ†’ login once, works forever โœ…
  • SSH = Faster + Secure ๐Ÿ”

๐Ÿ’ก Pro Tip

If you use multiple accounts, you can configure multiple SSH keys using:

~/.ssh/config