How to set up Github SSH key on MacOS / Linux

Published on Jul 17, 2025

# git
# github
# linux
# macos

1. Check for existing keys

ls -al ~/.ssh

if this is empty proceed with step 2, if not

2. Generate new SSH keys

If you don’t have an ssh-key yet, you need to generate one:

ssh-keygen -t ed25519 -C "you@your.email"

You will be prompted with a few options:

  • where to save: ~/.ssh/id_ed25519 is fine ⇒ enter
  • passphrase none ⇒ enter
  • repeat passphrase ⇒ enter

so now we have 2 files ~/.ssh/id_ed25519[.pub]

3. Add / Conf

either add:

ssh-add ~/.ssh/id_ed25519

or use ssh config: (~/.ssh/config):

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

4. Tell GH pubkey

Next we need to tell Github our public key. we can copy it by:

cat ~/.ssh/id_ed25519.pub

It will look something like:

ssh-ed25519 AAAA……zzzzzz you@your.email

To tell it go to: github.com → profile (top right) → settings → Access/SSH and GPG Keys

  • new SSH Key
  • Title: device name
  • Key type: Authentication
  • Key: the copied key including username@…

Verification with Passkey is required

5. Authenticate

ssh -T git@github.com

You should see something like “Hi [user]! You’ve successfully authenticated”

✨poof, you’re done

6. If you are prompted for a username/password

If you are trying to clone a repo after this setup, you might have the issue of being prompted a username and password.

This problem may be resolved using the ssh url instead of https so:

https://github.com/username/private-repo becomes

git@github.com:username/private-repo.git