1. 程式人生 > >GitHub Clone專案時出現的問題(Permission denied (publickey))

GitHub Clone專案時出現的問題(Permission denied (publickey))

GitHub Clone專案時出現的問題

在使用git在本地clone遠端Github上的專案時

root$ git clone [email protected]:XXXXX/XXXXX.git
...
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

上面的問題是說Github中無法感知到你本地的SSH KEY。此時你需要在本地生成一個ssh key。然後在你的gitHub的setting中儲存起來。

下面是本地生產ssh key的過程:下列郵箱地址最好寫成你的git config user.email,輸入完命令之後,回車三次會出現生成的ssh key的路徑 /Users/hubinnn/.ssh/id_rsa.pub。注意:在Mac的終端下、在按回車的時候,可能會出現輸入你的管理員密碼的情況,不用慌張,安靜輸入~

root$ ssh-keygen -t rsa -C "[email protected]" 
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/hubin/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/hubinnn/.ssh/id_rsa.
Your public key has been saved in /Users/hubinnn/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:y1PcLwhQPoX4N35Dl4RdQT0EN7dsadasdasdE62Jz13fXE 
[email protected]
The key's randomart image is: +---[RSA 2048]----+ | ....+ ++OE| | .o..+ * +.O| | ..o = * **| | ..oo.+ X *| | Sooo.. = | | . +..o. .| | + ..... | | . . | | | +----[SHA256]-----+

然後使用命令vim /Users/hubinnn/.ssh/id_rsa.pub

開啟你的ssh key,然後複製到你的GitHub中的SSH KEY

如下圖: 開啟GitHub的設定頁 進入到SSH KEYS,然後NEW SSH KEY 在這裡插入圖片描述

在GitHub上添加了自己的SSH KEY。然後再執行一次; root$ git clone [email protected]:XXXXX/XXXXX.git