Assume we are on a server, and we would like to clone a repsitory from Github.
Once we hit git clone git@github.com: repository name, an error was prompted:
Permission denied (publickey). fatal: Could not read from remote repository.
Why is that? Because we haven't added our SSH key to the github account.
To resolve this issue,
first, turn on the ssh-agent;
eval "$(ssh-agent -s)"
Then, verify that there is a private key generated and loaded into SSH, by command:
ssh-add -l
However, we found nothing in there.
GitHub says, if it does not generate anything, you should either generate a new SSH key, or use an existing SSH key, and associate it with GitHub.
So, we go and check if there is already an SSH key available, we use the command:
ls -al ~/.ssh
There it is. We found a key pair named id_rsa.pub and id_rsa.
We add our SSH private key to the ssh-agent, with command:
ssh-add ~/.ssh/id_rsa
Finally, we reach the last step, that is, to add the SSH key to GitHub account.
0) Copy the SSH key to your clipboard, which is
~/.ssh/id_rsa.pub
1) Go to Settings of your GitHub account,
2) Click SSH and GPG keys,
3) Click New SSH key or Add SSH key,
4) Add description to the title;
5) Paste the key into the "Key" field.
We are done.
Reference:
https://help.github.com/
转载于:https://blog.51cto.com/11190017/1956601