Home / Localhost / Generate SSH key for GitHub

Generate an SSH key and add it to GitHub (ed25519)

Create an SSH key with ssh-keygen, load it into ssh-agent, copy the public key and add it to GitHub, with the Windows and macOS differences.

An SSH key is a pair of files: a private key that stays on your computer and a public key you give to GitHub. After you add it, git push and git pull work without typing a password each time. These are the commands GitHub documents.

What to do, step by step

  1. Create the key: ssh-keygen -t ed25519 -C "your_email@example.com", using your GitHub email.
  2. Press Enter to accept the default file location. If you already have keys, GitHub recommends a custom name so you do not overwrite them.
  3. Enter a passphrase and confirm it.
  4. Start the agent and add the key (commands below).
  5. Copy the public key (the file ending in .pub) and paste it in GitHub under Settings, then SSH and GPG keys, then New SSH key.
  6. Test with ssh -T git@github.com.

Commands you can copy

Create the key
ssh-keygen -t ed25519 -C "your_email@example.com"
Older systems without ed25519
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Start the agent (Linux, macOS)
eval "$(ssh-agent -s)"
Add the key
ssh-add ~/.ssh/id_ed25519
macOS: add with keychain
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
Copy public key, macOS
pbcopy < ~/.ssh/id_ed25519.pub
Copy public key, Windows
clip < ~/.ssh/id_ed25519.pub
Show it to copy by hand
cat ~/.ssh/id_ed25519.pub
Test the connection
ssh -T git@github.com

Windows, macOS and common problems

Windows: start the agent
GitHub says to run Get-Service -Name ssh-agent | Set-Service -StartupType Manual and then Start-Service ssh-agent in an elevated PowerShell, then ssh-add c:/Users/YOU/.ssh/id_ed25519 in a normal terminal. If Git for Windows still asks for your passphrase, GitHub suggests git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe".
macOS: keep the passphrase in the keychain
In ~/.ssh/config under Host github.com add AddKeysToAgent yes, UseKeychain yes and IdentityFile ~/.ssh/id_ed25519. If you see Bad configuration option: usekeychain, add IgnoreUnknown UseKeychain. Before macOS Monterey the flag was -K instead of --apple-use-keychain.
Copied the wrong file
Paste the .pub file only. The file without .pub is your private key and must never be shared.
Extra spaces break the key
GitHub says not to add newlines or whitespace when copying the key.
Permission denied (publickey)
The key is not added to GitHub, not loaded into the agent, or the wrong key is offered. Run ssh-add -l to see loaded keys, and see the SSH config generator for pinning a key to a host.
Two GitHub accounts
Give each key its own file name and map each to a host name. See SSH config for multiple GitHub accounts.
DSA keys
GitHub no longer accepts new DSA (ssh-dss) keys.

Questions about Generate SSH key for GitHub

Which file do I give to GitHub?
The public key, id_ed25519.pub. Never upload or send the private key, id_ed25519.
Do I need a passphrase?
GitHub's steps include one. It protects the key if someone copies the file. The agent lets you type it once per session.
Can I add the key from the command line?
Yes, with the GitHub CLI: gh auth login, then gh ssh-key add ~/.ssh/id_ed25519.pub --title "my laptop".
What is the difference between authentication and signing keys?
An authentication key is for SSH access to repositories. A signing key signs commits and tags. A key used for both has to be uploaded twice.

Updated 2026-10-24

Config generators for this

Related pages