Configure SSH for git on Windows
Creating a new key-pair
I am using a Windows-11 Professional os.
OpenSSH client is included by default in Windows 11.
This is how I'll create a kwypair:
- Try to see if the .ssh directory exists, and there are any previous keys there:
1dir ~/.ssh
- If the directory is not there, it will be created when you create your key-pair:
(change to your own email - but this is a comment)
1ssh-keygen -t ed25519 -C "your_email@example.com"
- Here's a complete example of me creating a new keypair and leave the default name as is is (it will save me further configuration step)
1PS C:\Users\yuval>
2PS C:\Users\yuval> ssh-keygen -t ed25519 -C "yuval.shaul@gmail.com"
3Generating public/private ed25519 key pair.
4Enter file in which to save the key (C:\Users\yuval/.ssh/id_ed25519):
5Enter passphrase (empty for no passphrase):
6Enter same passphrase again:
7Your identification has been saved in C:\Users\yuval/.ssh/id_ed25519.
8Your public key has been saved in C:\Users\yuval/.ssh/id_ed25519.pub.
9The key fingerprint is:
10SHA256:jtz14HPiOQXBTlIBjIPVvD0OJ8z9FWTVxBRqSZIiPew yuval.shaul@gmail.com
11The key's randomart image is:
12+--[ED25519 256]--+
13| o.=++oo.oo**|
14| . o.==+.o.+ o|
15| +oBo. + . |
16| *EB . . |
17| S=o+ . |
18| . + o.oo |
19| o o +.o |
20| ..= |
21| o. |
22+----[SHA256]-----+
23PS C:\Users\yuval>
24
25PS C:\Users\yuval> ls $env:USERPROFILE\.ssh
26
27 Directory: C:\Users\yuval\.ssh
28
29Mode LastWriteTime Length Name
30---- ------------- ------ ----
31d---- 09/10/2023 15:41 __MACOSX
32-a--- 27/03/2025 16:53 0 config
33-a--- 28/03/2025 7:47 411 id_ed25519
34-a--- 28/03/2025 7:47 104 id_ed25519.pub
35-a--- 27/03/2025 16:49 22180 known_hosts
36-a--- 14/12/2024 19:59 1678 yuvKP.pem
37
38PS C:\Users\yuval>
The ssh-agent service
- Let's check if the service (that is required to handle the usage of our private key) is running:
1Get-Service ssh-agent | Select-Object Name, Status
- If it is not running, you can start it, and make sure it will start automatically next time:
1Start-Service ssh-agent
2Set-Service -Name ssh-agent -StartupType Automatic
- Now let's add the new private key (my_new_key in my case) to the ssh-agent:
1ssh-add $env:USERPROFILE\.ssh\id_ed25519
- Here's an example of me listing keys that are alreay added to the agent, then adding the new key (and list again):
1PS C:\Users\yuval> ssh-add -l
2256 SHA256:+MPYBkd8ZHXeY+wQANUyz3+FClZvHH4ip1IK9SWaQhU yuval.shaul@gmail.com (ED25519)
34096 SHA256:2Hj7cfrgDKTHVhyU+cSkf7cY4N9Qqj7XwYQFqvmKujM yuval.shaul@gmail.com (RSA)
42048 SHA256:Pv+1qXgOl5qH4D+8K8O3TxOASjQl2RMEnB/NQZtYGdo .\.ssh\yuvKP.pem (RSA)
5PS C:\Users\yuval>
6PS C:\Users\yuval> ssh-add $env:USERPROFILE\.ssh\id_ed25519
7Identity added: C:\Users\yuval\.ssh\id_ed25519 (yuval.shaul@gmail.com)
8PS C:\Users\yuval>
9PS C:\Users\yuval> ssh-add -l
10256 SHA256:+MPYBkd8ZHXeY+wQANUyz3+FClZvHH4ip1IK9SWaQhU yuval.shaul@gmail.com (ED25519)
114096 SHA256:2Hj7cfrgDKTHVhyU+cSkf7cY4N9Qqj7XwYQFqvmKujM yuval.shaul@gmail.com (RSA)
12256 SHA256:jtz14HPiOQXBTlIBjIPVvD0OJ8z9FWTVxBRqSZIiPew yuval.shaul@gmail.com (ED25519)
132048 SHA256:Pv+1qXgOl5qH4D+8K8O3TxOASjQl2RMEnB/NQZtYGdo .\.ssh\yuvKP.pem (RSA)
14PS C:\Users\yuval>
Add the public key to github
- First, display the public key in your powershell:
(change to your public file name)
1type $env:USERPROFILE\.ssh\id_ed25519.pub
- Copy the exact string (use your mouse)
- Add to github:
- login to github
- go to your account settings (not a repository settings)
- Select SSH and GPG keys
- Click on New SSH Key
- Give the new key a title (my new windows key in my case)
- Paste the public key in the key pane
- Hit Add SSH key at the bottom
Set permissions for the private key file
Well, the Windows OpenSSH client is more tolerant than the Linux one, so we should ne OK with the default permissions that were created for the private key file
Try to use it
- If you already have a repository in github, you may want to get the SSH url, that may look like this:
git@github.com:YuvalShaul/ds19.git - Try cloning it:
1git clone git@github.com:YuvalShaul/ds19.git
Good Luck!