之前使用git進(jìn)行push或者clone操作的時候出現(xiàn)如下錯誤:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
原因:電腦公鑰(publickey)未添加至github,所以無法識別。 因而需要獲取本地電腦公鑰,然后登錄github賬號,添加公鑰至github就OK了。
設(shè)置Git的user name和email
git config --global user.name "yourname"
git config --global user.email "youremail"
生成SSH密鑰
查看是否已經(jīng)有了ssh密鑰:cd ~/.ssh
如果沒有密鑰則不會有此文件夾,有則備份刪除
生存密鑰:
ssh-keygen -t rsa -C “youremail”
按3個回車,密碼為空。
Your identification has been saved in /home/tekkub/.ssh/id_rsa.Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.The key fingerprint is:
………………
最后得到了兩個文件:id_rsa和id_rsa.pub
在github上添加ssh密鑰,這要添加的是“id_rsa.pub”里面的公鑰。打開github在設(shè)置中添加密鑰

按照指令操作會進(jìn)入vim編輯模式,上邊的序列碼即為公鑰,復(fù)制序列碼,包含(ssh-rsa等標(biāo)識)。不同操作系統(tǒng)和電腦可能公鑰路徑不一樣,以實際情況為準(zhǔn).
登錄github后,進(jìn)入個人設(shè)置settings--->ssh and gpg keys-->new ssh key 添加即可。title自行命名

add ssh key成功后,github就可以識別你的機(jī)器,允許你從github拉取代碼了。