When I want to push to github with this command
git push origin master
I got this
Permission denied (publickey).
fatal: The rem
Here is a step-by-step guide that I used to get this to work.
Platform: Windows 7
Install msysgit from http://msysgit.github.io/
During installation, accept all of the default options, except when the 'Select Components' option appears. When this appears, select 'Git Bash Here' option. Although this isn't necessary, it adds a nice context menu when working in Windows Explorer that I found to be very helpful.
Once msysgit is installed Git Bash will also be installed. Open Git Bash in one of 2 ways:
In Git Bash's command window, enter this:
$ ssh-keygen -t rsa
When asked to enter a file name, just accept the default. Choose a strong passphrase when prompted, and your public key should now be saved. Your screen should look like this:
Go open the public key file in Notepad. The file should reside here:
C:\Users\{username}\.ssh\id_rsa.pub
Copy all of the content in the file to your clipboard, then go to GitHub's SSH settings page:
https://github.com/settings/ssh
Choose 'Add SSH key', enter a useful 'Title' and paste the content into the 'Key' textarea.
To simplify your life, you can use the SSH agent to save your passphrase so that you don't need to remember it. To do so, type this into Git Bash:
$ eval `ssh-agent -s`
$ ssh-add ~/.ssh/id_rsa
You'll be prompted to enter your passsphrase. If everything succeeds, your identity will have been added. Note: this passphrase will be forgotten as soon as you close your shell. I'm not sure how to make this persist across sessions, but maybe someone can help?
To test that everything works, enter this into Git Bash:
$ ssh -T git@github.com
You should see a 'success' meesage.
Sources:
https://help.github.com/articles/generating-ssh-keys/
https://help.github.com/articles/working-with-ssh-key-passphrases/
explanation on why eval `ssh-agent -s` should be used instead of just ssh-agent -s
https://stackoverflow.com/a/17848593/188740