Mac linux 解决 Permission denied (publickey)

解决git提示Permission denied (publickey)

在linux 或 mac os 装完git,然后clone github的项目时出问题,报以下错误。

Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights

出现这个错误很显然是ssh key的问题。我们只需要跟github官方的配置ssh的流程走一遍就行了。

1.生成SSH Keys

如果已经生存了ssh key,那就可以跳过这一步了。可以用以下命令查看
ls -l ~/.ssh

ls -l ~/.ssh

如果出现id_rsa 和 id_rsa_pub 那就说明已经生成。

如果没有,按一下步骤生成

ssh-keygen -t rsa -C “[email protected]

下面的步骤,可以一直都敲回车,如果对安全性要求很高,就自己输入密码吧。成功后,你会看到下面的提示:

Your public key has been saved in /Users/you/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
Your identification has been saved in /Users/you/.ssh/id_rsa.
Your public key has been saved in /Users/you/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
Your identification has been saved in /Users/you/.ssh/id_rsa.

2.Key 添加到ssh-agent

ssh-agent 貌似是对解密的专用密钥进行高速缓存。在windows 没有这一步,linux mac os还需要手动添加到ssh-agent。首先确定ssh-agent是否启用

ssh-agent -s

如果看到Agent pid xxxxx 那就说明已经启用
然后把私钥添加到ssh-agent就可以了。

ssh-add ~/.ssh/id_rsa

把公钥添加到自己的github
这个过程很简单,我简略写一下。依次进入settings–>ssh keys–>add ssh key 然后把你的公钥添加进这里就ok了。

找了许多解决方法都搞不定,最终还是按照github 官方的流程走通了。git 不是linux的亲儿子么,怎么在linux配置比其他平台还麻烦,不得不吐槽啊。。

你可能感兴趣的:(Mac linux 解决 Permission denied (publickey))