Configure Git and GitHub Using SSH
Generate an SSH key, add it to GitHub, and authenticate without typing a password every time you push.
Requirements
- Git installed. Follow our guide →
- A GitHub account
- Access to a terminal
Choose your platform
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.
$ ls -al ~/.sshWhat 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.
Generate a new SSH key
This creates a new Ed25519 key pair, which is faster and more secure than the older RSA format.
$ 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.
Add the key to the SSH agent
$ 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.
$ ssh-add --apple-use-keychain ~/.ssh/id_ed25519Copy 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.
$ pbcopy < ~/.ssh/id_ed25519.pubAdd 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.
Test the connection
$ ssh -T git@github.comExpected 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.
$ ssh-add -lThis 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.
$ ssh -vT git@github.comThe -v flag shows verbose output so you can see exactly which key was offered and why it was rejected.