Configuring SSH Authentication for GitHub

Issue Faced

  1. GitHub removed password authentication for HTTPS in August 2021.
  2. SSH authentication was not set up for GitHub.
  3. Attempted to use id_rsa, but it was linked to a different email.
  4. The newly generated SSH key (github_id_ed25519) was not saved in ~/.ssh/.

Solution: Setting Up SSH Authentication for GitHub

Step 1: Generate a New SSH Key for GitHub

ssh-keygen -t ed25519 -C "mohomadrinas00@gmail.com"

Step 2: Move the SSH Key to the Correct Directory

If the key is missing from ~/.ssh/, move it manually:

mv github_id_ed25519* ~/.ssh/

Verify it exists:

ls -al ~/.ssh

Step 3: Start SSH Agent and Add the New Key

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

Verify that the key is added:

ssh-add -l

Expected output:

256 SHA256:BPhKMXxFF94wo3VJW2UbjsuxwDpFuI4DtDAns4cVIoc mohomadrinas00@gmail.com (ED25519)

Step 4: Configure SSH for GitHub

Edit (or create) the SSH configuration file:

nano ~/.ssh/config

Add the following lines:

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

Save the file (Ctrl + X, then Y, then Enter).


Step 5: Add SSH Key to GitHub

Retrieve the public key:

cat ~/.ssh/github_id_ed25519.pub

Step 6: Test SSH Connection

ssh -T git@github.com

If successful, you should see:

Hi git_id! You've successfully authenticated...

Step 7: Update Git Remote (If Needed)

If you previously cloned the repository using HTTPS, update the remote URL to SSH:

git remote set-url origin git@github.com:git_id/learning-journal.git

Verify the change:

git remote -v

Step 8: Push Changes Without Password

Now, you can push changes without entering a password:

git push -u origin main

Written by A.M. Rinas