【已解决】git clone 报错:Could not read from remote repository. Please make sure you have the correct acce


一、问题

换电脑了,克隆代码遇到报错:

git clone [email protected]:qwertyuiopasdfghjkl/projectName.git
Cloning into 'projectName'...
找不到代码库,请确认是否有权限且代码库路径正确
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

找到本地公钥,复制到添加 SSH 公钥处,遇到报错:

该密钥已被添加为用户密钥或部署密钥,添加失败

官方提出的解决办法:添加 SSH Keys 报已存在怎么办?
按照官方的提示,大概率是原因1,只能重新生成了

但是现在本地这个 SSH Key 在其他地方有使用(Gitee/Github/…),想要保留,再生成一个。

二、解决

按照以下两篇官方说明:

决定尝试 ED25519 算法生成的密钥(同一算法需要指定不同路径,使用不同算法就免了)

ssh-keygen -t ed25519 -C "<注释内容>"

按照默认路径生成后,配置config文件(~/.ssh/config)

# Codeup (2023.05.18 add)
HostName codeup.aliyun.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_ed25519

当本地存在多个密钥,如果不设置认证规则,本机将随机选择一个密钥用于认证,可能造成认证失败。

接下来复制公钥粘贴到指定位置

# Windows
cat ~/.ssh/id_ed25519.pub | clip

保存后就可以使用啦

三、拓展学习

1.ssh命令

  • 远程登录(查看当前使用的密钥对应的账号)
ssh -t [email protected]

正常显示:

Welcome to Codeup, userName!
Connection to codeup.aliyun.com closed.

SSH(远程登录)

2.Ed25519:一个高速度高安全的签名方法

  • Ed25519:一个高速度高安全的签名方法
  • 官方介绍:Introduction
  • 它的签名长度为64个字节,公钥长度是32个字节

签名一共经过三个环节

  1. 生成公钥、私钥
  2. 使用私钥签名
  3. 使用公钥验签

over

猜你喜欢

转载自blog.csdn.net/qq_32682301/article/details/130754765