To add an SSH key to GitHub, copy your public key (the .pub file), then go to Settings > SSH and GPG keys > New SSH key on GitHub.com, paste it, and click Add SSH key. Test it with ssh -T [email protected].
This article assumes you already have a key pair. If you don't, generate an Ed25519 SSH key first. The examples below use the default file name id_ed25519.pub; substitute yours if it differs.
Step 1: Copy your public key
Use the file that ends in .pub. GitHub's documentation gives these commands:
| Where | Command |
|---|---|
| macOS | pbcopy < ~/.ssh/id_ed25519.pub |
| Windows (Command Prompt or Git Bash) | clip < ~/.ssh/id_ed25519.pub |
| Windows (PowerShell) | cat ~/.ssh/id_ed25519.pub | clip |
| Linux | cat ~/.ssh/id_ed25519.pub, then select and copy the output |
If a command fails, open the .ssh folder in your home directory, open the .pub file in a text editor, and copy its contents. The key is one line, starting with ssh-ed25519 for an Ed25519 key. Don't add extra newlines or spaces when you paste it.
Step 2: Add it on GitHub.com
- Click your profile picture in the upper-right corner, then click Settings.
- In the Access section of the sidebar, click SSH and GPG keys.
- Click New SSH key (or Add SSH key).
- In Title, enter a label that tells you which machine this is, such as "Personal laptop".
- Choose the key Type: Authentication to push and pull over SSH, or Signing to verify signed commits.
- Paste the public key into the Key field.
- Click Add SSH key. If GitHub asks you to confirm your access, do so.
To use one key for both authentication and signing, add it twice, once with each type.
Add the key with the GitHub CLI instead
If you use the GitHub CLI, you can skip the web page. Sign in first, then add the key:
gh auth login
gh ssh-key add ~/.ssh/id_ed25519.pub --title "personal laptop"
The default type is authentication. For a signing key, add --type signing. For an authentication key the CLI may ask for additional token scopes; follow the instructions it prints.
Step 3: Test the connection
ssh -T [email protected]
Use git as the user name, not your GitHub user name. On Windows, run it in Git Bash or PowerShell. The first time, SSH shows a host-key warning like this:
The authenticity of host 'github.com (IP ADDRESS)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
Are you sure you want to continue connecting (yes/no)?
Compare the fingerprint with the list GitHub publishes in its documentation before you type yes. The one above is the Ed25519 fingerprint shown in GitHub's testing guide as of November 2026; check the official list rather than trusting a copy. If your key has a passphrase and isn't loaded in an agent, you are asked for it.
A successful test prints:
Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
The command then exits with code 1. That is expected, not an error. Check that the user name in the greeting is yours.
Step 4: Switch existing repositories from HTTPS to SSH
A repository you cloned over HTTPS keeps using HTTPS. To switch it, run this inside the project folder:
git remote -v
git remote set-url origin [email protected]:OWNER/REPOSITORY.git
git remote -v
The SSH URL format is [email protected]:OWNER/REPOSITORY.git, where OWNER is the account or organization name. After the change, git remote -v shows (example output):
origin [email protected]:OWNER/REPOSITORY.git (fetch)
origin [email protected]:OWNER/REPOSITORY.git (push)
New clones use the SSH address from the Code button's SSH tab, or you can type the URL yourself: git clone [email protected]:OWNER/REPOSITORY.git.
If you get "Permission denied (publickey)"
This means GitHub rejected your connection. GitHub's troubleshooting page lists these checks, in order:
- Don't use
sudowith Git. Keys created withoutsudoaren't used bysudo git .... - Use the
gituser.ssh -T [email protected]fails with this error.ssh -T [email protected]is correct. If a remote URL contains your GitHub user name in front of the@, change it withgit remote set-urlas shown above. - Check that a key is loaded. Run
eval "$(ssh-agent -s)"to start an agent, thenssh-add -l -E sha256to list loaded keys. If the list is empty, add yours withssh-add ~/.ssh/id_ed25519. Default key names such asid_rsaare normally picked up automatically; a non-default file name needsssh-addor-i. - See which key SSH offers.
ssh -vT [email protected]prints the connection details. It should show a connection togithub.comon port 22. Lines saying "Trying private key" with no file mean no key was found. For a non-default file, usessh -i ~/.ssh/KEY-FILE -vT [email protected]. - Confirm the key is on your account. Take the fingerprint from
ssh-add -l -E sha256and compare it with the keys listed under Settings > SSH and GPG keys. If the key isn't there, add it. If you see a key you don't recognise, delete it and contact GitHub Support.
On some Linux distributions the test prints "Agent admitted failure to sign" instead. GitHub has a separate troubleshooting page for that error.
Notes on key types and organizations
- DSA keys (
ssh-dss) are no longer supported, and you can't add new ones to a personal account. - RSA keys generated after November 2, 2021 must use a SHA-2 signature algorithm, so some older clients may need upgrading.
- If your organization uses single sign-on, you may need to authorize the key for SSO before it works with the organization's repositories.
For a quick way to compare key fingerprints, ssh-keygen -l -f ~/.ssh/id_ed25519.pub prints the fingerprint of a public key file.
Frequently asked questions
- Do I paste the .pub file or the private key into GitHub?
- Paste the public key, the file ending in .pub, such as ~/.ssh/id_ed25519.pub. The private key (the same name without .pub) must never leave your computer. GitHub's Key field expects a single line that starts with the key type, for example ssh-ed25519.
- What is the difference between an Authentication key and a Signing key?
- On the New SSH key page you choose a Type. An Authentication key lets you push and pull over SSH. A Signing key is used to verify signed commits. To use one key for both, add it twice, once with each type.
- Why does ssh -T [email protected] say GitHub does not provide shell access?
- That message means it worked. GitHub authenticated your key and then closed the connection because it does not offer a login shell. The command exits with code 1, which is expected. Check that the username in the greeting is your own.
- Do I need to authorize the key for SSO?
- If your organization uses single sign-on, you may need to authorize the key for SSO before it can access that organization's repositories. GitHub documents this in a separate page, Authorizing an SSH key for use with single sign-on.
- Can I add an SSH key from the command line?
- Yes, with the GitHub CLI. After gh auth login, run gh ssh-key add ~/.ssh/id_ed25519.pub --title "personal laptop". Add --type signing for a signing key. For an authentication key, the CLI may ask you to grant additional scopes.