How to set up the SSH Keys for Github on your new Mac

MacGit
November 27, 2023

So, you've hit a snag with GitHub and your new Mac, huh? No worries, I've got your back! We'll sort out this SSH key mess in a jiffy. Let's roll!

Step 1: Peek at Your SSH Keys

First things first, let's see if you've got any SSH keys lying around. Fire up your Terminal and type:

ls -al ~/.ssh

This is like peeking into your secret SSH vault. If you see files like id_rsa.pub or id_ed25519.pub, you're golden. If not, no sweat, we'll make a new one.

Step 2: Crafting Your SSH Key

No key? No problem. Let's forge a new one. Think of this like crafting a digital ID badge. Run this:

ssh-keygen -t ed25519 -C "[email protected]"

Replace "[email protected]" with your email. This ties your key to your identity. Just hit Enter to all prompts, and bam, new key!

Step 3: Teach Your SSH Agent New Tricks

Your SSH Agent is like a digital butler holding your keys. We need to make sure it knows about your new key. Do this:

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

Now your SSH Agent is in the know.

Step 4: Show GitHub Your Fancy New Key

Next, we need to tell GitHub about this shiny new key. Copy it to your clipboard with:

pbcopy < ~/.ssh/id_ed25519.pub

Then, jump over to GitHub.com in your browser. Go to Settings > find SSH and GPG keys, and hit New SSH key. Paste your key there and give it a name that makes sense.

Step 5: Test Drive Your SSH Connection

Almost there! Let's make sure GitHub recognizes you:

ssh -T [email protected]

If you see a welcome message with your username, you're all set!

Step 6: Make Sure Git Uses SSH

Last bit - let's ensure Git talks to GitHub using SSH. In your repo's directory, run:

git remote set-url origin [email protected]:username/repo.git

Replace username/repo.git with your GitHub details.

And there you have it! Give it a go, and you should be pushing to GitHub like a pro.