Create a new repository, or reuse an existing one.
Generate a new SSH key:
ssh-keygen -t rsa -C "[email protected]"
Copy the contents of the file ~/.ssh/id_rsa.pub
to your SSH keys in your GitHub account settings (https://github.com/settings/keys).
Test SSH key:
$ ssh -T [email protected]
Hi developius! You've successfully authenticated, but GitHub does not provide shell access.
Change directory into the local clone of your repository (if you're not already there) and run:
git remote set-url origin [email protected]:username/your-repository.git
Now try editing a file (try the README) and then do:
$ git commit -am "Update README.md"
$ git push
You should not be asked for a username or password. If it works, your SSH key is correctly configured.
Ref: https://newbedev.com/how-to-run-ssh-add-on-windows
OpenSSH is available as part of Windows 10 which makes using SSH from cmd/powershell much easier in my opinion. It also doesn't rely on having git installed, unlike my previous solution.
-
Open Manage optional features from the start menu and make sure you have
OpenSSH Client
in the list. If not, you should be able to add it. -
Open Services from the start Menu
-
Scroll down to
OpenSSH Authentication Agent
> right click > properties -
Change the Startup type from Disabled to any of the other 3 options. I have mine set to Automatic (Delayed Start)
-
Open cmd and type where ssh to confirm that the top listed path is in System32. Mine is installed at
C:\Windows\System32\OpenSSH\ssh.exe.
If it's not in the list you may need to close and reopen cmd. -
Optional step/troubleshooting: If you use git, you should set the
GIT_SSH
environment variable to the output of where ssh which you ran before (e.gC:\Windows\System32\OpenSSH\ssh.exe
). This is to stop inconsistencies between the version of ssh you're using (and your keys are added/generated with) and the version that git uses internally. This should prevent issues that are similar to this
Some nice things about this solution:
- You won't need to start the ssh-agent every time you restart your computer
- Identities that you've added (using ssh-add) will get automatically added after restarts. (It works for me, but you might possibly need a config file in your c:\Users\User.ssh folder)
- You don't need git!
- You can register any rsa private key to the agent. The other solution will only pick up a key named id_rsa
Create a new repository, or reuse an existing one.
Generate a new SSH key:
ssh-keygen -t rsa -C "[email protected]" -f $env:UserProfile/.ssh/id_rsa
Copy the contents of the file ~/.ssh/id_rsa.pub
to your SSH keys in your GitHub account settings (https://github.com/settings/keys).
Test SSH key:
PS> ssh -i ~/.ssh/id_rsa -T [email protected]
Hi mildronize! You've successfully authenticated, but GitHub does not provide shell access.
Change directory into the local clone of your repository (if you're not already there) and run:
git remote set-url origin [email protected]:username/your-repository.git
Now try editing a file (try the README) and then do:
$ git commit -am "Update README.md"
$ git push
You should not be asked for a username or password. If it works, your SSH key is correctly configured.
https://gist.github.com/danieldogeanu/16c61e9b80345c5837b9e5045a701c99