Network security

GitHub SSH Key: How to Generate, Add and Test One

A GitHub SSH key replaces passwords for Git operations with a key pair you control. Here is the full setup, step by step, for Mac, Windows and Linux.

Cysoro Security TeamPublished · 8 min read
ssh-ed25519 NETWORK SECURITY GitHubSSH key Generate it, add it, test it.
Quick answer

A GitHub SSH key is a pair of cryptographic keys that authenticates you to GitHub without a password. You generate an Ed25519 key pair with ssh-keygen, add the private key to your SSH agent, paste the public key into GitHub under Settings, SSH and GPG keys, and test it with ssh -T [email protected].

Key takeaways

  • Use Ed25519 for new keys; use RSA with 4096 bits only on legacy systems that do not support Ed25519.
  • Your private key never leaves your computer — only the public key goes to GitHub.
  • A passphrase plus the SSH agent gives you security without typing the passphrase on every push.

Typing a password every time you push code is slow, and storing a password in plain text is risky. A GitHub SSH key fixes both: your computer proves who you are with a key pair, and GitHub never sees your private key.

What is a GitHub SSH key?

A GitHub SSH key is a pair of cryptographic keys used to authenticate you to GitHub over SSH. The public key goes on GitHub; the private key stays on your computer and is never shared.

When you clone, push or pull over SSH, GitHub sends a challenge that only your private key can answer. If the answer matches the public key on your account, you are in — no password, no token to paste, and no credential stored in your repository.

SSH keys are not the same as personal access tokens. A token is a password-like string you can revoke and scope; a key is tied to one machine. Many developers use SSH for daily Git work and keep tokens for scripts and automation. If you already use an authenticator app for two-factor authentication, see our guide to the best OTP app for the second factor that protects the account itself.

How does SSH authentication work?

SSH uses asymmetric cryptography: a public key that anyone can see, and a private key that only you hold. GitHub stores your public key and uses it to verify a signature made by your private key.

How a GitHub SSH key works 1 Generate a pair public plus private key, on your machine 2 Upload public key to GitHub settings; private key stays put 3 GitHub challenges you a message only the private key can answer 4 You are in push, pull and clone without a password Never share the private key. Anyone with it can act as you on GitHub.
SSH authentication: the private key never leaves your computer. Illustration by Cysoro.

GitHub dropped support for older, insecure key types on March 15, 2022. DSA keys can no longer be added, and RSA keys generated after November 2, 2021 must use a SHA-2 signature algorithm. That is one more reason to start fresh with Ed25519.

Ed25519 vs RSA: which key type should you use?

Use Ed25519 for every new GitHub SSH key. It is the modern default GitHub recommends, it is faster to generate and use, and its public keys are short. RSA remains supported for legacy systems that do not support Ed25519.

Key typeCommandWhen to use itNotes
Ed25519ssh-keygen -t ed25519Default for all new keysFast, short keys, recommended by GitHub
RSA 4096ssh-keygen -t rsa -b 4096Legacy systems without Ed25519Longer keys, slower, still secure at 4096 bits
Ed25519-SKssh-keygen -t ed25519-skHardware security keyKey lives on a FIDO2 security key
ECDSA-SKssh-keygen -t ecdsa-skHardware key without Ed25519Fallback for older security keys
DSANot supportedNeverGitHub no longer accepts new DSA keys

If you are unsure whether your system supports Ed25519, try it first. Almost every current Mac, Windows and Linux system does. Only fall back to RSA if the command fails with an unknown key type error.

How do I check for existing SSH keys?

Before you generate a new key, check whether you already have one. Reusing an existing key is fine; generating a second key with the same name will overwrite the first.

Open a terminal and list the .ssh folder in your home directory with ls -al ~/.ssh. Look for files such as id_ed25519.pub or id_rsa.pub. The .pub file is the public key; the file without that ending is the private key.

If you find a public key, you can display it with cat ~/.ssh/id_ed25519.pub and compare it with the keys listed in your GitHub settings. If it is already there, you do not need a new key — just make sure the private key is loaded into the SSH agent. GitHub documents the full flow in its guide to adding a new SSH key to your GitHub account.

How do I generate a GitHub SSH key?

Generate the key with one command, then add a passphrase when prompted. The whole process takes under a minute.

  1. Open a terminal. On Windows, use Git Bash or Windows Terminal.
  2. Run ssh-keygen -t ed25519 -C "[email protected]", replacing the email with the address on your GitHub account. The email is only a label.
  3. Press Enter to accept the default file location, ~/.ssh/id_ed25519, unless you already have a key there. If you do, type a different file name.
  4. Type a secure passphrase when prompted, then type it again to confirm. A passphrase encrypts the private key on disk.
  5. On a legacy system without Ed25519, use ssh-keygen -t rsa -b 4096 -C "[email protected]" instead.

GitHub documents exactly this flow in its guide to generating a new SSH key and adding it to the ssh-agent. Use a strong passphrase — a phrase you can remember is better than a short, complex string. Generate one with our free password generator if you need a starting point, then memorize it.

How do I add the key to the SSH agent?

The SSH agent holds your private key in memory and remembers your passphrase, so you do not type it on every Git operation. Start the agent, then add the key.

On Mac and Linux, run eval "$(ssh-agent -s)" to start the agent, then ssh-add ~/.ssh/id_ed25519 to add your key. Type your passphrase once when prompted. On macOS, you can store the passphrase in the keychain with ssh-add --apple-use-keychain ~/.ssh/id_ed25519 and add AddKeysToAgent yes and UseKeychain yes to ~/.ssh/config under a Host github.com block.

On Windows PowerShell, start the agent service with Get-Service -Name ssh-agent | Set-Service -StartupType Manual followed by Start-Service ssh-agent, then run ssh-add c:/Users/YOU/.ssh/id_ed25519 in a terminal without elevated permissions. Verify the key is loaded with ssh-add -l, which should list its fingerprint.

How do I add the SSH key to GitHub?

Copy the public key, then paste it into GitHub settings. Copy only the .pub file — never the private key.

  1. Copy the public key to your clipboard. On Mac, run pbcopy < ~/.ssh/id_ed25519.pub. On Windows, run clip < ~/.ssh/id_ed25519.pub. On Linux, run cat ~/.ssh/id_ed25519.pub and copy the output by hand.
  2. On GitHub, click your profile picture, then click Settings.
  3. In the sidebar, click SSH and GPG keys.
  4. Click New SSH key or Add SSH key.
  5. Give the key a clear title, such as "MacBook Pro 2026" or "Work laptop".
  6. Choose Authentication key as the type, paste the public key, and click Add SSH key.
  7. Confirm access if GitHub prompts you.

You can also add a key from the command line with the GitHub CLI, once you have authenticated it: gh ssh-key add ~/.ssh/id_ed25519.pub --type authentication --title "personal laptop". The same key can be uploaded a second time as a signing key if you want to sign commits with it.

How do I test my GitHub SSH key?

Test the connection before you try to clone anything. Run ssh -T [email protected] in a terminal.

A working key returns a message such as "Hi username! You have successfully authenticated, but GitHub does not provide shell access." That is the expected result: GitHub accepts SSH for Git operations, not for an interactive shell. If you see a warning about the authenticity of the host the first time, check that the fingerprint matches GitHub's published host key, then type "yes" to continue.

Once the test passes, switch a repository to SSH with git remote set-url origin [email protected]:OWNER/REPO.git, replacing the owner and repository names. Then try git fetch to confirm pushes and pulls work without a password prompt.

Why is my GitHub SSH key not working?

Most SSH failures fall into a small set of causes. Work through them in order instead of generating a new key each time.

Fix SSH errors in order 1 Is the public key on GitHub?Settings, SSH and GPG keys — compare the fingerprint 2 Is the private key in the agent?run ssh-add -l — if it is empty, run ssh-add ~/.ssh/id_ed25519 3 Are you using the SSH remote?git remote -v should show [email protected], not https:// 4 Wrong key or permissions?ssh -vT [email protected] shows which key was tried; ~/.ssh must be 700 5 Still failing?check the key type — DSA is no longer accepted by GitHub
Five checks that fix most GitHub SSH errors. Illustration by Cysoro.
  • Permission denied (publickey): the public key is not on GitHub, the agent is empty, or Git is using a different key. Run ssh -vT [email protected] — the verbose output shows which key files were tried.
  • Permission denied (password): you are using an HTTPS remote. Switch it to SSH with git remote set-url.
  • Bad permissions on ~/.ssh: the folder should be readable only by you. On Mac and Linux, run chmod 700 ~/.ssh and chmod 600 ~/.ssh/id_ed25519.
  • Passphrase asked every time: the key is not in the agent. Run ssh-add again, or add the key to your ~/.ssh/config with AddKeysToAgent yes.
  • Works on one machine, not another: each machine needs its own key pair added to GitHub. A key copied between machines is a key you can no longer revoke per machine.
Never paste a private key anywhereIf a private key ends up in a chat message, a ticket, a repository or an AI prompt, treat it as compromised: delete it from GitHub, generate a new pair, and update every machine that used it.

How do I keep a GitHub SSH key secure?

Use a passphrase, use one key per machine, and review your keys regularly. Those three habits cover most of the risk.

Give every key a descriptive title so you can tell them apart later. Once a year, open GitHub settings and delete keys for machines you no longer own. If a laptop is lost or stolen, delete its key from GitHub immediately — that revokes its access without affecting your other machines.

For higher-value accounts, consider a hardware security key. Generate an Ed25519-SK key with ssh-keygen -t ed25519-sk -C "[email protected]", touch the key when prompted, and add the resulting public key to GitHub. The private key never leaves the hardware. For shared or automated access, use deploy keys scoped to a single repository instead of a personal key that can reach everything you can.

SSH keys protect Git operations, not your GitHub account itself. Turn on two-factor authentication on the account, and keep your recovery codes somewhere safe. Our small business cybersecurity checklist covers that alongside backups and updates.

The bottom line

Generate an Ed25519 key with a passphrase, load it into the SSH agent, paste the public key into GitHub settings, and test it with ssh -T [email protected]. That is the whole setup, and it removes passwords from your daily Git work.

Use one key per machine, name each key clearly, and delete keys you no longer need. If you work with JSON Web Tokens in the apps you build, our guide to the best JWT library covers the libraries worth using in 2026.

Frequently asked questions

What is a GitHub SSH key?

It is a pair of cryptographic keys that proves your identity to GitHub. You keep the private key on your computer and upload the public key to GitHub. When you push or pull, GitHub checks that you hold the matching private key, so you do not need a password.

Where is my GitHub SSH key stored?

By default, your keys live in the .ssh folder in your home directory: ~/.ssh/id_ed25519 for the private key and ~/.ssh/id_ed25519.pub for the public key. The private key file must stay on your computer and must never be shared or uploaded.

Should I use Ed25519 or RSA for GitHub?

Use Ed25519 for new keys. GitHub recommends it, and it is faster and shorter than RSA. Use RSA with 4096 bits only if you are on a legacy system that does not support Ed25519.

How do I test my GitHub SSH key?

Run ssh -T [email protected] in a terminal. A working key returns a message such as Hi username! You have successfully authenticated. You may see a warning the first time about the host key; that is normal.

Why do I get Permission denied (publickey)?

That error usually means GitHub does not have the public key, the SSH agent does not hold the private key, or Git is using the wrong key. Check that the key is listed in GitHub settings, run ssh-add -l to see loaded keys, and test with ssh -T [email protected].

Can I use the same SSH key on two computers?

You can, but you should not. Generate a separate key pair on each computer and give each one a clear name in GitHub, such as work laptop or home desktop. That way you can revoke one computer without breaking the other.

Do I need a passphrase on my SSH key?

GitHub recommends one. A passphrase encrypts the private key on disk, so a stolen laptop does not immediately give an attacker your GitHub access. Add the key to the SSH agent so you only type the passphrase once per session.

What is the difference between an authentication key and a signing key?

An authentication key proves who you are when you push and pull. A signing key proves that a commit or tag really came from you. GitHub lets you upload the same key twice, once for each purpose, or use separate keys.

Sources

  1. GitHub Docs — Generating a new SSH key and adding it to the ssh-agent
  2. GitHub Docs — Adding a new SSH key to your GitHub account
  3. GitHub Docs — About SSH
  4. DEV Community — Unlock GitHub Like a Pro: The Definitive SSH Setup Guide for Ubuntu
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against GitHub's official SSH documentation for generating, adding and testing keys.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free