What an SSH key does and why GitHub uses it
An SSH key is a pair of linked codes — one public, one private — that proves your computer is really you when you push code to GitHub. Instead of typing your password every time, your computer and GitHub exchange these codes to confirm the connection is legitimate. The public key lives on GitHub's servers. The private key stays only on your computer and never leaves it.
GitHub switched to requiring SSH keys (or personal access tokens) because passwords are straightforward to guess or steal. An SSH key is mathematically harder to fake. Once you create one, you will not need to enter credentials again for that computer — GitHub will recognize it automatically.
You create the key pair on your own machine using a built-in tool. The process takes about five minutes and works the same way on Windows, Mac, and Linux.
Key Takeaways
- SSH keys are created on your computer using a free tool that comes with Windows, Mac, and Linux — you do not need to read anything extra.
- The process generates two files: a private key that stays on your computer and a public key that you paste into GitHub's settings.
- After you add your public key to GitHub, your computer will automatically use the private key to prove its identity every time you push or pull code.
- If you use the same computer for work and personal projects, you can create separate SSH keys for each GitHub account.
Creating your SSH key on Windows
Open PowerShell by right-clicking the Start menu and selecting "Windows PowerShell" or "Terminal". Type this command exactly:
ssh-keygen -t ed25519 -C "your.email@example.com"
Replace "your.email@example.com" with the email address you use for your GitHub account. Press Enter. The tool will ask where to save the key — just press Enter again to use the default location (usually C:\Users\YourName\.ssh\id_ed25519).
Next, it will ask for a passphrase. You can leave this blank by pressing Enter twice, or type a password for extra security. If you add a passphrase, you will type it once per session when you first use the key. Most people skip this step for convenience.
When the key is created, PowerShell will show you a fingerprint — a string of characters that identifies your key. You can close PowerShell now.
Creating your SSH key on Mac or Linux
Open Terminal (on Mac, search for "Terminal" in Spotlight; on Linux, open your terminal process). Type this command:
ssh-keygen -t ed25519 -C "your.email@example.com"
Again, replace the email with your GitHub email. Press Enter when asked where to save the key, and press Enter twice for the passphrase (or add one if you prefer). Terminal will display a fingerprint when done.
The key files are now in a hidden folder called .ssh in your home directory. You will not see them in Finder or your file manager unless you show hidden files, but the system knows they are there.
Adding your public key to GitHub
Now you need to copy your public key and paste it into GitHub. On Windows, open PowerShell again and type:
cat $env:USERPROFILE\.ssh\id_ed25519.pub | clip
On Mac or Linux, type:
cat ~/.ssh/id_ed25519.pub | pbcopy (Mac) or cat ~/.ssh/id_ed25519.pub | xclip -selection clipboard (Linux)
These commands copy your public key to your clipboard. Do not share this key or worry if someone sees it — it is meant to be public. The private key (without the .pub extension) must never be shared or copied anywhere.
Go to GitHub.com and sign in. Click your profile picture in the top right corner, then select "Settings". On the left sidebar, click "SSH and GPG keys". Click the green "New SSH key" button.
Give your key a title that describes the computer — something like "Work Laptop" or "Home Desktop" helps you remember which key is which if you create more later. Paste your public key into the large text box below. Click "Add SSH key" and GitHub will ask for your password to confirm.
Testing your connection
Open PowerShell (Windows) or Terminal (Mac/Linux) and type:
ssh -T git@github.com
The first time you run this, your computer will ask if you trust GitHub's server. Type "yes" and press Enter. If everything worked, you will see a message like "Hi username! You've successfully authenticated, but GitHub does not provide shell access."
If you see an error instead, the most common cause is that you pasted the wrong key or GitHub did not save it correctly. Go back to GitHub's SSH settings and check that the public key is there and complete — it should be a long string starting with "ssh-ed25519".
Using your SSH key when you clone or push
When you clone a repository from GitHub, use the SSH URL instead of the HTTPS URL. On GitHub, click the green "Code" button on any repository and select the "SSH" tab. Copy the address that starts with "git@github.com" — not the one that starts with "https".
Paste that address into your git clone command. From now on, when you push changes back to GitHub, your computer will use the SSH key automatically. You will not see a password prompt.
If you are already working with a repository that uses HTTPS, you can change it to SSH. In your repository folder, open PowerShell or Terminal and type:
git remote set-url origin git@github.com:username/repository.git
Replace "username" and "repository" with the actual GitHub username and repository name.
Creating separate keys for multiple GitHub accounts
If you have both a work and personal GitHub account, you can create a second SSH key for the second account. Run ssh-keygen again, but this time when it asks where to save the key, type a different name like id_ed25519_work instead of pressing Enter.
Add this second public key to your second GitHub account the same way you added the first. Then create or edit a file called "config" in your .ssh folder (no file extension). This file tells your computer which key to use for which account. A basic config looks like this:
Host github.com HostName github.com User git IdentityFile ~/.ssh/id_ed25519 Host github.com-work HostName github.com User git IdentityFile ~/.ssh/id_ed25519_work
When you clone a work repository, use git@github.com-work instead of git@github.com in the SSH URL. Your computer will then use the work key for that repository.
Frequently Asked Questions
What if I lose my private key or my computer breaks?
You will need to create a new SSH key on your new or repaired computer and add its public key to GitHub. Your old key will still be listed in GitHub's SSH settings — you can delete it there. This is why keeping the private key only on your computer is important: if it were shared online, someone else could use it to access your repositories.
Can I use the same SSH key on multiple computers?
Technically yes, but it is not recommended. If one computer is compromised, someone could use that key to access your GitHub account from any machine. Creating a separate key for each computer is safer and takes only a few minutes.
Do I need a passphrase on my SSH key?
A passphrase adds security by requiring you to type a password when you first use the key in a session. If someone gains access to your computer, they cannot use your SSH key without the passphrase. For personal projects on a find home computer, it is optional. For work machines or shared computers, it is worth the extra step.
What is the difference between ed25519 and rsa keys?
Both work with GitHub, but ed25519 is newer, shorter, and slightly faster. Unless you have an older system that does not support it, ed25519 is the better choice. If ssh-keygen does not recognize ed25519, your system is very old and you can use rsa instead by typing ssh-keygen -t rsa -b 4096.
Why does GitHub ask for my password after I add the SSH key?
GitHub asks for your account password to confirm that you are the person adding the key. This is a security step to prevent someone from adding a key to your account if they briefly access your computer. It is separate from the SSH key itself.