Configure Git and GitHub Using SSH

Generate an SSH key, add it to GitHub, and authenticate without typing a password every time you push.

beginner10 minmacos · windows · linuxUpdated August 2026
#git#github#ssh#authentication#developer-setup

Requirements

Choose your platform

0/6 steps · 0%
01

Check for an existing SSH key

Before generating a new key, check whether you already have one. Reusing an existing key is fine — you don't need a separate key per project.

bash
$ ls -al ~/.ssh

What to look for

id_ed25519
id_ed25519.pub

Note

If you see id_ed25519 and id_ed25519.pub, skip to Step 3. If the folder doesn't exist or is empty, continue to Step 2.

02

Generate a new SSH key

This creates a new Ed25519 key pair, which is faster and more secure than the older RSA format.

bash
$ ssh-keygen -t ed25519 -C "{{EMAIL}}"

You'll be asked where to save the key and whether to set a passphrase. Pressing Enter at each prompt accepts the defaults, which is fine for most setups.

Tip

A passphrase adds a second layer of protection if your laptop is ever lost or stolen. It's optional but recommended.

03

Add the key to the SSH agent

bash
$ eval "$(ssh-agent -s)"

Expected output

Agent pid 12345

macOS Sonoma and later store the key in the login Keychain automatically, so it survives restarts.

bash
$ ssh-add --apple-use-keychain ~/.ssh/id_ed25519
04

Copy the public key

You'll paste this into GitHub in the next step. This command copies it straight to your clipboard — nothing is printed to the terminal.

bash
$ pbcopy < ~/.ssh/id_ed25519.pub
05

Add the key to GitHub

In GitHub, go to Settings → SSH and GPG keys → New SSH key. Paste the key you copied, give it a recognizable title such as "MacBook Pro", and save it.

Important

Paste the entire key, including the ssh-ed25519 prefix and the email comment at the end.

06

Test the connection

bash
$ ssh -T git@github.com

Expected result

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

Success

That message means authentication worked. It's normal — and expected — that GitHub refuses to give you a shell.

Troubleshooting

GitHub couldn't match any key it has on file with the one your machine offered. This usually means the key was never added to GitHub, the agent isn't holding it, or you're connecting with a different account than you think.

bash
$ ssh-add -l

This lists keys currently loaded in the agent. If it says "The agent has no identities", re-run ssh-add ~/.ssh/id_ed25519 from the steps above.

bash
$ ssh -vT git@github.com

The -v flag shows verbose output so you can see exactly which key was offered and why it was rejected.