【macOS】git問題:permission denied

現(xiàn)在使用git等很多,自己也嘗試了下,結(jié)果在安裝后執(zhí)行一下命令等時(shí)候總是報(bào)permission denied

ssh -T git@github.com

各種baidu終于搞定。

想要使用git必須先安裝git,可以自行baidu安裝并注冊(cè)github賬號(hào)。這里就不必多說(shuō)。

打開終端輸入以下命令查看是否存在.ssh文件夾

$cd ~/.ssh

如果存在會(huì)返回以下信息

Last login: Sat Jul1 17:45:48 on ttys000

pantieruideMacBook-Pro:~ pantierui$ cd ~/.ssh

pantieruideMacBook-Pro:.ssh pantierui$

如果不存在,可以使用mkdir創(chuàng)建一個(gè).ssh文件夾

通過(guò)以下命令默認(rèn)參數(shù)生成ssh的key

ssh-keygen -t rsa -C xxxxx@gmail.com(注冊(cè)github時(shí)的email)

回車后如下:

pantieruideMacBook-Pro:~ pantierui$ ssh-keygen -t rsa -C "pantierui@hotmail.com"

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/pantierui/.ssh/id_rsa): xxxxxxx(此處為key等名字)

Enter passphrase (empty for no passphrase):(此處為密碼,git驗(yàn)證時(shí)用)

Enter same passphrase again:(再次輸入密碼)

Your identification has been saved in pantierui.

Your public key has been saved in pantierui.pub.

The key fingerprint is:

SHA256:QlhWPjXi1AjbWFiMvalu+yFv4d2NfUj41mhWZkJ196c pantierui@hotmail.com

The key's randomart image is:

+---[RSA 2048]----+

|+O*oo|

|+oO+o..+|

|. + =o.+|

|.o.. o|

|..So ..|

|.... E +|

|....o . * O |

|ooo.. o X o|

|..+o+ . |

+----[SHA256]-----+

pantieruideMacBook-Pro:~ pantierui$

此時(shí)用以下命令查看生成等密鑰(確保當(dāng)前目錄為.ssh)

cat pantierui.pub (此文件為剛剛生成的,記錄下來(lái)以下步驟會(huì)用到)

登陸github網(wǎng)站,找到自己用的的【setting】下的【SSH and GPG keys】,點(diǎn)擊【New SSH key】

【title】此處隨便起個(gè)名字

【Key】此處就是剛剛cat出來(lái)的內(nèi)容

執(zhí)行以下命令驗(yàn)證是否可以鏈接到github

ssh -T git@github.com

會(huì)提示以下信息

The authenticity of host 'github.com (192.30.255.112)' can't be established.

RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.

Are you sure you want to continue connecting (yes/no)?

回復(fù)yes,繼續(xù)。此時(shí)會(huì)報(bào)以下錯(cuò)誤

Permission denied (publickey).

使用以下命令查看log,診斷信息如下

pantieruideMacBook-Pro:.ssh pantierui$ ssh -T -v git@github.com

OpenSSH_7.4p1, LibreSSL 2.5.0

debug1: Reading configuration data /etc/ssh/ssh_config

debug1: Connecting to github.com [192.30.255.112] port 22.

debug1: Connection established.

debug1: key_load_public: No such file or directory

debug1: identity file /Users/pantierui/.ssh/id_rsa type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/pantierui/.ssh/id_rsa-cert type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/pantierui/.ssh/id_dsa type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/pantierui/.ssh/id_dsa-cert type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/pantierui/.ssh/id_ecdsa type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/pantierui/.ssh/id_ecdsa-cert type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/pantierui/.ssh/id_ed25519 type -1

debug1: key_load_public: No such file or directory

debug1: identity file /Users/pantierui/.ssh/id_ed25519-cert type -1

debug1: Enabling compatibility mode for protocol 2.0

debug1: Local version string SSH-2.0-OpenSSH_7.4

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: curve25519-sha256@libssh.org

debug1: kex: host key algorithm: ssh-rsa

debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: compression: none

debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: 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/pantierui/.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: Trying private key: /Users/pantierui/.ssh/id_rsa

debug1: Trying private key: /Users/pantierui/.ssh/id_dsa

debug1: Trying private key: /Users/pantierui/.ssh/id_ecdsa

debug1: Trying private key: /Users/pantierui/.ssh/id_ed25519

debug1: No more authentication methods to try.

Permission denied (publickey).


因?yàn)閟sh會(huì)找id_rsa和id_rsa.pub文件,注意我們生成的pantierui和pantierui.pub不等于前面的兩個(gè)文件,顧驗(yàn)證失敗。使用以下命令復(fù)制出上名的文件

cp pantierui id_rsa && cp pantierui.pub id_rsa.pub

重新執(zhí)行驗(yàn)證命令

ssh -T git@github.com

需要回復(fù)密碼

Enter passphrase for key '/Users/pantierui/.ssh/id_rsa':(此處為創(chuàng)建key時(shí)的密鑰)

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

如果出現(xiàn)上述信息就可以使用github了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容