github ssh failed

[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.

 

樓主下載git閒置了一段時間,某天心血來潮突然想也寫一個項目,就打算用git來管理代碼。

當樓主在github上建好倉庫以後,就準備開始clone,當樓主去找/Users/***/.ssh/id_rsa.pub發現沒有(cd ~/.ssh這裏可以先簡單的檢測下,沒有就重新生成),

然後就百度了一下,用ssh-keygen -t rsa -C “你的郵箱”這個命令直接生成,之後在/Users/***/.ssh/目錄下就生成了兩個文件,

到這裏的時候,樓主以爲就可以搞定了,然後就開始去clone,

直接複製/Users/***/.ssh/id_rsa.pub的內容,然後在github的SSH and GPG keys新建了一個,填上title粘貼上內容,然後回到終端git clone “你的地址”

結果就報了這個

Cloning into 'xxxx'...
[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.

然後樓主各種百度,發現解決這個問題的辦法,就是複製/Users/***/.ssh/id_rsa.pub的內容到github上新建的keys上啊,爲什麼就不行呢?

 

各種百度,各種查,真的是一萬個草泥馬啊。。。。。

於是樓主就決定開始重頭再來,把剛纔生成的/Users/***/.ssh/*,全部刪除掉,

第一步,先驗證一下用戶名郵箱,git config --global --list,樓主之前就放了一個錯誤,沒有驗證就直接複製內容去粘貼了,一般第一次安裝都是沒有的。

第二步,git config --global user.name "yourname",git config --global user.email [email protected] 設置全局用戶名和郵箱,

第三步,ssh-keygen -t rsa -C "這裏換上你的郵箱",生成祕鑰,

接着以爲這次總算可以OK了,然後又複製了一遍之前的操作,接着去clone,

 

啃爹啊,結果還是報

 

Cloning into 'xxxx'...
[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.

 

心碎有沒有,樓主感覺自己都快奔潰了,到底是爲什麼呢?

心裏一直反覆的說要鎮定要鎮定,然後又是各種百度,最後終於在一位老哥的博客上找到答案了尼瑪的太啃爹了

這裏提供一下地址https://blog.csdn.net/chaoyueziji123/article/details/54669555

首先測試一下

ssh [email protected]
Warning: Permanently added the RSA host key for IP address '13.250.000.000' to the list of known hosts.
PTY allocation request failed on channel 0
Hi ******! You've successfully authenticated, but GitHub does not provide shell access.

結果是這樣的,大概意思就是這個IP地址RSA主機密鑰永久的添加到了你的主機列表中,您已經成功地進行了身份驗證,但GITHUB不提供shell訪問。

解決辦法:

1.ssh -v [email protected]

測試ssh連接是否成功,我的現實如下,跟老哥的不太一樣,可以連起來看

 

OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to github.com port 22.
debug1: Connection established.
debug1: identity file /Users/faye/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/faye/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6
debug1: Remote protocol version 2.0, remote software version libssh_0.7.0
debug1: no match: libssh_0.7.0
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/faye/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:7ym7jzOz5gT7p8h1Xw4f8a7Jq/0a4yjcyWMRO1BVyL0 /Users/faye/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([13.229.188.59]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Sending environment.
debug1: Sending env LANG = zh_CN.UTF-8
debug1: Sending env LC_CTYPE = zh_CN.UTF-8
PTY allocation request failed on channel 0
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi ! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Connection to github.com closed.
Transferred: sent 3020, received 1788 bytes, in 0.8 seconds
Bytes per second: sent 3684.0, received 2181.1
debug1: Exit status 1

然後下面兩步就關鍵了,

先使用 ssh-agent -s


SSH_AUTH_SOCK=/var/folders/c6/_lb54v1d4v14_0j4_nt_1vj00000gp/T//ssh-B57Gx7MencHN/agent.32676; export SSH_AUTH_SOCK;
SSH_AGENT_PID=32677; export SSH_AGENT_PID;
echo Agent pid 32677;

 

再使用 ssh-add ~/.ssh/id_rsa

Identity added: /Users/faye/.ssh/id_rsa (/Users/faye/.ssh/id_rsa)

 

最後測試 ssh -T [email protected]

 

Hi nitt! You've successfully authenticated, but GitHub does not provide shell access.

當顯示這一句的時候,就萬事大吉了,接着就可以愉快的去clone了,

 

Cloning into '*****'...
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
 

到這裏樓主想說,git這個東西還是很值得去研究的,但是樓主比較懶散,一般只會搞明白怎麼去使用就好了

所以以樓主的經驗就是一步一步搞

第一步,git config --global --list 驗證郵箱

第二步,git config --global user.name "yourname",git config --global user.email [email protected] 設置全局用戶名和郵箱,

第三步,ssh-keygen -t rsa -C "這裏換上你的郵箱",生成祕鑰,

第四步,到git倉庫,添加祕鑰,

第五部,ssh -T [email protected] 測試一下通不通,不通就是ssh-agent -s  ssh-add ~/.ssh/id_rsa 操作這兩步

最後clone,藥到病除!!!!

 

 

 

執行ssh-add ~/.ssh/rsa

 報標題上的錯誤

先執行  eval `ssh-agent`  (是~鍵上的那個`) 再執行 ssh-add ~/.ssh/rsa成功

ssh-add -l 就有新加的rsa了

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章