Mac码云Permission denied(publickey)问题解决

前言:笔者曾在本机部署多个公钥(ssh key),一个是自己的码云账号使用,一个是公司码云账号使用。现在准备clone公司的新项目,发现出现以下错误:

运行命令: git clone [email protected]:xxxxx/xxx-xxx.git 

错误提示:

  • Cloning into 'xxx-xxx'...
  • Permission denied (publickey).
  • fatal: Could not read from remote repository.
  • Please make sure you have the correct access rights
  • and the repository exists.

笔者第一时间就想到说之前部署多个公钥可能导致此问题的出现.

从错误提示中我们可以发现公钥已经失去作用(不被允许,且我们的码云上的公钥还存在)

(一)我们验证一下我们的猜想:

运行命令:ssh -T -v [email protected]

果然,有如下错误:

  • OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
  • debug1: Reading configuration data /etc/ssh/ssh_config
  • .......(省略n多提示)
  • debug1: Authentications that can continue: publickey
  • debug1: Next authentication method: publickey
  • debug1: Trying private key: /root/.ssh/id_rsa
  • debug1: Trying private key: /root/.ssh/id_dsa
  • debug1: Trying private key: /root/.ssh/id_ecdsa
  • ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC9QViCuZYHM1QMLNfvaH2/C13U+HiWegRIEPKvPcQEdebug1: Trying private key: /root/.ssh/id_ed25519
  • debug1: No more authentication methods to try.
  • Permission denied (publickey).

(二)错误原因

提示信息表明路径 ~/.ssh下id_rsa文件存在,并且提供public key,然而无法和网站中的ssh-key匹配上。于是程序转而寻找!/.ssh路径下的id_dsa文件,id_ecdsa文件,id_ed25519文件,看它们是不是能提供新的public key。查看一下~/.ssh,会发现下面根本不存在id_dsa,id_ecdsa,id_ed25519文件。 出错的原因其实在于我们更新了本地的ssh key,然而网站上的ssh key还为旧值,所以匹配不上,就报错Permission denied (publickey)

(三)解决问题

(1)打开~/.ssh/id_rsa.pub(.pub为公钥文件,id_rsa为私钥文件),复制里面的内容

(2)添加到码云上的个人>安全设置>ssh公钥

Mac码云Permission denied(publickey)问题解决_第1张图片

(3)再次测试$ ssh -T [email protected],提示

      Hi xxx! You've successfully authenticated, but GITEE.COM does not provide shell access.

且运行命令: git clone [email protected]:xxxxx/xxx-xxx.git成功

Mac码云Permission denied(publickey)问题解决_第2张图片

Ok!排除问题~

你可能感兴趣的:(git,gitee,码云,Permission,denied,(publickey),公钥,git)