1. 程式人生 > >git Permission denied (publickey). fatal: Could not read from remote repository.

git Permission denied (publickey). fatal: Could not read from remote repository.

問題描述:

最近剛剛學爬蟲,從學長的git上clone到伺服器的時候 出現的這個問題,問題不大吧,估計以後還會遇到。

問題很簡單,就是沒有祕鑰,顯然github不知道你是誰,然後禁止你拉取程式碼。

原理:本地生成祕鑰,然後新增到GitHub裡面 DONE

解決方法:

1.本地生成祕鑰:

ssh-keygen -t rsa -C "username" // username = 你的git使用者名稱

 

然後一路 enter 下來,可能會遇到  overwrite 的問題,如果有遇到 請大家 根據情況自行選擇 y/n

成功後 會顯示

 

// 上面有兩行內容關注下,這裡面 紅色內容即為你的本地的儲存祕鑰的地方,一會要去這個地方檢視祕鑰
Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa):

2.找到剛剛生成的祕鑰:

cat /root/.ssh/id_rsa.pub

然後複製你的全部內容

3.到GitHub上新增 SSH key

Github新增SSH key的介面 : https://github.com/settings/profile

然後新增進去,並且給自己的祕鑰起一個title 然後就OK啦!

 

 然後就去愉快的  git clone 吧!