解决git提示Permission denied (publickey)

在linux装完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 “your_email@example.com”

ssh-keygen -t rsa -C “your_email@example.com”

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

# 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 your_email@example.com    
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 your_email@example.com

Your identification has been saved in /Users/you/.ssh/id_rsa.

2.Key 添加到ssh-agent

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

ssh-agent -s

如果看到Agent pid xxxxx 那就说明已经启用

然后把私钥添加到ssh-agent就可以了。

ssh-add ~/.ssh/id_rsa
  1. 把公钥添加到自己的github

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

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

说明:本文出处https://wiyi.org/git-config.html

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值