Permission denied (publickey),需配

2021-07-15  本文已影响0人  Anne_M

当出现如下错误时,是因为没有配置git ssh keys:

Permission denied (publickey). fatal: The remote end hung up unexpectedly

配置步骤:

Step 1、检查SSH keys是否存在

输入下面的命令,如果有文件id_rsa.pub 或 id_dsa.pub,则直接进入步骤3将SSH key添加到GitHub中,否则进入第二步生成SSH key

默认的,公钥的文件名可能是下面的几个:

id_dsa.pub 、id_ecdsa.pub、id_ed25519.pub、id_rsa.pub

输出:

Step2:生成一个新的SSH密钥(SSH key)

第一步:用GitHub使用的e-mail地址生成public/private rsa key pair

在命令行中输入ssh-keygen -t rsa -C "your_email@example.com"

默认会在相应路径下(/your_home_path)生成id_rsa和id_rsa.pub两个文件,如下面代码所示

Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):   提示你:“输入一个用来保存钥匙的文件”,默认保存在/Users/you/.ssh/id_rsa,我们直接按回车键。(它保存的位置跟你当前路径没有关系,默认都是保存在~/.ssh/id_rsa路径(即/user/xxx/.ssh/id_rsa)里面)

第二步:输入passphrase(本步骤可以跳过 ,如果你直接按回车,就是没有密码)

Enter passphrase (empty for no passphrase): [Type a passphrase]

Enter same passphrase again: [Type passphrase again]

Your identification has been saved in /c/Users/UsersName/.ssh/id_rsa.

Your public key has been saved in /c/Users/UsersName/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:rwuerTS5wjzt86GtvvVt0jwm5nquIJWpdXt+kw2exYU注册Github用的邮箱

The key's randomart image is:

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

| |

| |

| . |

| o E .|

| = S . . |

| + o o . o |

| oo.* + o+ * |

| =+o@ *=.% . |

| =@*OO=*.o |

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

 现在你的公钥已经保存在/c/Users/you/.ssh/id_rsa.pub中。

第三步:将新生成的key添加到ssh-agent中:

# start the ssh-agent in the background

eval"$(ssh-agent -s)"Agent pid 59566

ssh-add ~/.ssh/id_rsa

Step3. 将ssh key添加到GitHub中

用文本编辑器打开id_rsa.pub文件,里面的信息即为SSH key,将这些信息复制到GitHub的Add SSH key页面即可

不同的操作系统,均有一些命令,直接将SSH key从文件拷贝到粘贴板中,如下:

mac

pbcopy < ~/.ssh/id_rsa.pub

# Copies the contents of the id_rsa.pub file to your clipboard

windows

clip < ~/.ssh/id_rsa.pub

# Copies the contents of the id_rsa.pub file to your clipboard

linux

sudo apt-get install xclip

# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)

xclip -sel clip < ~/.ssh/id_rsa.pub

# Copies the contents of the id_rsa.pub file to your clipboard

Step 4: 添加你的SSH key到GitHub账号

第一步:在页面的右上角, 点击头像, 然后点击 Settings。

第二步:In the user settings sidebar, click SSH keys.

第三步:Click Add SSH key.

第四步:Paste your key into the "Key" field.

第五步:Click Add key,到此,配置完成,可以去clone代码啦。

上一篇下一篇

猜你喜欢

热点阅读