Programming & Coding How-TosTechnology

How to Set Up SSH Keys for GitHub on Windows 11

Admin
How to Set Up SSH Keys for GitHub on Windows 11

If you use GitHub on Windows 11, setting up SSH keys is one of the best small upgrades you can make. After a one-time setup, you can clone, pull, and push without typing your username or password again and again.

SSH keys also offer strong security, because your private key never leaves your computer. GitHub only stores the matching public key, which is safe to share.

This step-by-step guide uses Git Bash, which comes with Git for Windows. Follow the steps in order, and you will be connected in about ten minutes.

Quick Answer

To set up SSH keys for GitHub on Windows 11, open Git Bash and run ssh-keygen -t ed25519 -C "your_email@example.com" to create a key pair. Then start the agent with eval "$(ssh-agent -s)", add your key with ssh-add ~/.ssh/id_ed25519, copy the public key with cat ~/.ssh/id_ed25519.pub, and paste it into GitHub under Settings, SSH and GPG keys.

What Are SSH Keys and Why Use Them?

An SSH key pair is made of two related files. Together, they let GitHub confirm that the computer connecting is really yours, without sending a password over the internet.

  • Private key: A secret file that stays on your computer, for example id_ed25519. Never share it with anyone.
  • Public key: A shareable file ending in .pub, for example id_ed25519.pub. This is the one you add to GitHub.

When you push, GitHub sends a challenge that only your private key can answer correctly. Your public key verifies the answer, and GitHub lets you in.

If Git is not installed on your PC yet, start with our complete guide to installing Git on Windows 11 and come back here when Git Bash is ready to use.

What You Need Before You Start

  1. A Windows 11 computer with Git for Windows installed, which includes Git Bash.
  2. A GitHub account, and access to the email address linked to that account.
  3. About ten quiet minutes, so you can copy the key carefully without rushing.
  4. Optional but recommended: a strong passphrase idea for your private key, which you will type during creation.

You do not need administrator rights for these steps. Everything happens inside your own user folder, in a hidden folder named .ssh.

Step 1: Check for Existing SSH Keys

  1. Open Git Bash from the Start menu.
  2. Run ls -al ~/.ssh to list the contents of your SSH folder.
  3. Look for files named id_ed25519.pub or id_rsa.pub.
  4. If you see one and you know it is yours, you can skip to adding that public key to GitHub. If the folder is empty or missing, continue to the next step.

If the folder does not exist, that is fine. The next step will create it.

Step 2: Generate a New SSH Key Pair

GitHub recommends the Ed25519 key type for new keys. It is modern, fast, and considered very secure.

  1. In Git Bash, run ssh-keygen -t ed25519 -C "your_email@example.com", replacing the email with the email you use for GitHub.
  2. When Git asks where to save the key, press Enter to accept the default location, which is /c/Users/you/.ssh/id_ed25519.
  3. When asked for a passphrase, type a strong one and press Enter. Type it again to confirm. Your typing will not appear on screen, which is normal.
  4. Git shows a confirmation with a key fingerprint and a random image. That means your key pair was created.

If your system is very old and does not support Ed25519, use ssh-keygen -t rsa -b 4096 -C "your_email@example.com" instead. For Windows 11 with current Git, Ed25519 will work.

The email in the command is only a label to help you recognise the key later. It does not affect security, but using your GitHub email keeps things tidy. GitHub details this process in the official GitHub guide to generating a new SSH key.

Step 3: Start the SSH Agent and Add Your Key

The SSH agent is a small background program that holds your private key for your session. It means you type your passphrase once, not on every Git command.

  1. In Git Bash, run eval "$(ssh-agent -s)" to start the agent. It will print a process number, which is a good sign.
  2. Run ssh-add ~/.ssh/id_ed25519 to add your private key to the agent.
  3. Enter your passphrase when asked. If you did not set one, the key is added immediately.
  4. Optionally run ssh-add -l to list the keys the agent is holding and confirm yours is there.

On Windows, the agent started in Git Bash lasts for that session, so repeat this step in a new session if needed.

Step 4: Copy Your Public Key

Now copy the exact text of your public key. Be careful to copy the .pub file, never the private key.

  1. Run cat ~/.ssh/id_ed25519.pub in Git Bash to display the public key.
  2. Select the whole output with your mouse. It starts with ssh-ed25519 and ends with your email label.
  3. Copy it with a right-click and Copy, or by pressing Enter on the selection in Git Bash, depending on your terminal settings.
  4. Alternatively, on Windows you can run clip < ~/.ssh/id_ed25519.pub to copy it straight to your clipboard.

Do not add extra spaces or line breaks when you paste it later. One changed character will make the key fail, and GitHub cannot tell you which character is wrong.

Step 5: Add the Public Key to GitHub

  1. Open GitHub in your browser and sign in.
  2. Click your profile picture, then open Settings.
  3. In the left sidebar, open SSH and GPG keys.
  4. Click the New SSH key button.
  5. Give the key a clear title such as “Windows 11 Laptop”.
  6. Keep the key type as Authentication Key, paste your public key into the Key field, and click Add SSH key.
  7. Confirm with your GitHub password if GitHub asks for it.

You should now see your key listed on GitHub. The official GitHub guide to adding a new SSH key to your account shows screenshots for each screen.

Step 6: Test Your SSH Connection

Always test the connection before you change your projects.

  1. Back in Git Bash, run ssh -T git@github.com.
  2. The first time, Git asks if you want to continue connecting. Type yes and press Enter. This saves GitHub’s host fingerprint on your computer.
  3. If everything works, GitHub replies with a message like “Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.”
  4. If you see “Permission denied (publickey)”, re-check that the agent is running, the key is added, and the public key on GitHub matches exactly.

Step 7: Use SSH with Your Repositories

Make sure your projects use SSH addresses. Old HTTPS clones will keep asking for tokens until you update them.

For a New Clone

  1. On the repository page on GitHub, click the Code button.
  2. Select the SSH tab and copy the address, which looks like git@github.com:username/repository.git.
  3. In Git Bash, run git clone git@github.com:username/repository.git.

For an Existing Repository

  1. Open Git Bash inside your existing project folder.
  2. Check the current address with git remote -v.
  3. Change it with git remote set-url origin git@github.com:username/repository.git, using your real address.
  4. Run git push to confirm the push works without a password prompt.

Common Mistakes to Avoid

  • Sharing your private key: Never send, upload, or paste the id_ed25519 file without .pub. Only the public key goes to GitHub.
  • Copying the key with extra spaces: The pasted key must be one exact block of text. Extra spaces or missing characters cause a “permission denied” error.
  • Forgetting to start the agent: If ssh-add says it cannot connect to the agent, run the eval command from Step 3 first.
  • Adding the key to the wrong GitHub account: If you have work and personal accounts, confirm you are signed in to the right one before adding the key.
  • Still using HTTPS remotes: SSH keys only help when the remote address is the SSH format. Update old projects with git remote set-url.
  • Losing your passphrase: A forgotten passphrase cannot be recovered. Create a new key pair instead, and save the new passphrase in a password manager.

Conclusion

Setting up SSH keys for GitHub on Windows 11 is a short, one-time job: generate an Ed25519 key, add it to the SSH agent, paste the public key into GitHub, and test the connection. After that, your daily pushes become fast and password-free.

Keep your private key safe on your computer, use a passphrase you store securely, and update old repositories to SSH addresses. Your future self will thank you every time a push just works.

Frequently Asked Questions

Do I need to create a new SSH key for every repository?

No. One key pair identifies your computer to your whole GitHub account. You add the public key once, and you can use it for every repository your account can access.

What should I do if I forget my SSH key passphrase?

The passphrase cannot be recovered or reset. Generate a fresh key pair, add the new public key to GitHub, and remove the old key from your GitHub settings.

Is it safe to share my public key?

Yes. The public key is designed to be shared and stored on servers like GitHub. The private key is the secret part, and that file should never leave your computer.

Why does ssh -T git@github.com say permission denied?

The usual causes are that the agent is not running, your key was not added with ssh-add, or the public key pasted into GitHub does not match. Repeat Steps 3 to 5 carefully and test again.

Can I use the same SSH key on two computers?

It is better practice to create a separate key pair on each computer. That way, if one computer is lost, you can remove only that key from GitHub and keep working on the other machine.

Admin

Passionate about the intersection of style and storytelling. I simplify fashion trends and industry news into easy-to-follow advice, helping you stay stylish and informed in the fast-paced world of fashion.

Leave a Reply

Your email address will not be published. Required fields are marked *