Using SSH with git and Github in Windows
Is handy to use SSH while connecting to git, for better security and the advantage of not having to type passwords at every remote operations.
Here the instruction on how to set it up for Windows:
Generate the ssh key
- using the command prompt, go to
%Git folder%\bin
(usuallyC:\Program Files (x86)\Git\bin
orC:\Program Files\Git\bin
) - generate the key pair using
ssh-keygen
, leave the key name as default
Upload the key to github
- Go to
%USERPROFILE%\.ssh
- open the file
id_ssh.pub
and copy the content - go to your account in github, and under the SSH Keys tab, enter a new key. Paste your public key and give it a friendly name
Set up ssh for git
- Copy the path of the
ssh.exe
executable under your\bin
folder - Create a new environment variable called
GIT_SSH
and set it to the path of thessh.exe
Clone
- Now just clone your repository using the SSH link, rather than the http(s) ones.
- If everything was setup correctly you shouldn’t be requested a username or password.
- The first time you clone, SSH will ask you to confirm the ssh fingerprint of the remote server
Tip
Other git hosts have support for SSH. If you use Stash for example, just copy and paste your id_ssh.pub content into a new SSH key under your account preferences.