I recently set up a project on cloud9 (c9.io). When you set up a project on cloud9, there is a .ssh directory with both public keys and private keys. I assume these are generated when you set up your account.
After creating a git repository, I set the origin to an empty repository on GitHub and attempted to push it upstream. As expected I didn't have the permissions.
I copied the contents of my public key and added it to GitHub. At that point I was able to push to GitHub.
I'm curious as to why GitHub only needs the public key. What happens behind the scenes when I attempted to push? What is the role of the private key?
解决方案
A private key, as its name indicates, is private. It's yours and yours only. You should never give a private key to anyone.
Your private key allows you to sign a message. You then send the message with its signature, and anyone having your public key can verify that the signature matches with the message. That's the principle of public key cryptography. So Github only needs your public key to check that you're the one you claim to be.