Skip to content

Latest commit

 

History

History
131 lines (80 loc) · 2.92 KB

File metadata and controls

131 lines (80 loc) · 2.92 KB

🔐 GitHub Authentication with SSH

This guide walks you through setting up SSH-based authentication for GitHub, enabling secure, passwordless Git operations from your local machine.


✅ Why Use SSH?

  • No need to enter username/password every time
  • Stronger security with public/private key cryptography
  • Recommended by GitHub for daily development

1️⃣ Generate an SSH Key Pair

An SSH key pair consists of two files:

  • Private key: Stored securely on your machine (~/.ssh/id_ed25519).
    👉 Never share this file.
  • Public key: Can be safely shared (~/.ssh/id_ed25519.pub).
    👉 This is what you upload to GitHub.

These keys work together to prove your identity without needing to send passwords.


🔧 Command to Generate a New Key:

ssh-keygen -t ed25519 -C "your_email@example.com"
Option Description
-t ed25519 Tells SSH to use the Ed25519 algorithm (fast + secure)
-C "your_email" A label to help identify your key (e.g., your GitHub email)

🖥️ When prompted:

Enter file in which to save the key (/home/youruser/.ssh/id_ed25519):

Just press Enter to save it to the default location.

Enter passphrase (empty for no passphrase):

Optional, but recommended. Adds extra protection to your key.You’ll only need to enter this once per session (if usingssh-agent).

✅ Result:

If successful, you’ll have:

~/.ssh/id_ed25519        # Your private key (KEEP THIS SAFE)
~/.ssh/id_ed25519.pub    # Your public key (Upload this to GitHub)

Now you're ready to add the public key to your GitHub account.

🔄 (Optional) Add Your SSH Key to the SSH Agent

If you set a passphrase for your SSH key, you can add it to the SSH agent to avoid typing the passphrase every time.

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

💡 Tip: Use ssh-add -l to verify the key is added.

2️⃣ Add Your Public Key to GitHub

Copy your public key:

cat ~/.ssh/id_ed25519.pub

Go to GitHub → Settings → SSH and GPG keys → New SSH key

Paste the key, name it (e.g. "My Laptop"), and save.

3️⃣ Use SSH for GitHub Repository Access

When cloning a repo, use the SSH URL:

git clone git@github.com:yourusername/yourrepo.git

Or, change an existing repo's remote:

git remote set-url origin git@github.com:yourusername/yourrepo.git

4️⃣ Test the SSH Connection

ssh -T git@github.com

Expected output:

Hi yourusername! You've successfully authenticated, but GitHub does not provide shell access.

🛠 Optional: SSH Config File

To manage multiple GitHub accounts or custom keys, create ~/.ssh/config:

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519