当前位置:   article > 正文

Ubuntu 22.04系统git/repo/github/codeup等 无法用ssh方式下载代码问题修复_ubuntu22.04 git clone ssh失败

ubuntu22.04 git clone ssh失败

在新安装的Ubuntu 22.04系统上,默认无法使用git下载代码,以及基于git的各种命令和服务,如repo、codeup、github等。执行命令,错误提示:

Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
  • 1
  • 2
  • 3
  • 4

或者

kex_exchange_identification: Connection closed by remote host
Connection closed by 123.123.123.123 port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
  • 1
  • 2
  • 3
  • 4
  • 5

首先确认本地和服务器端的sshkey设置都没有问题。

经调查,在openssh(8.x版本)由于安全原因,替换了默认的加密算法rsa,改为SHA-1。可以通过配置文件修改默认的加密算法,继续使用rsa算法。

查看本机安装的openssh-server版本,是8.9版本。

$ apt search openssh-server
Sorting... Done
Full Text Search... Done
openssh-server/jammy-updates,now 1:8.9p1-3ubuntu0.1 amd64 [installed]
  • 1
  • 2
  • 3
  • 4

修改默认的加密算法,可在配置文件中添加如下选项:

PubkeyAcceptedKeyTypes +ssh-rsa
  • 1

修改本地的配置文件(~/.ssh/config):

$ cat .ssh/config 
Host your.git.domain
HostName your.git.domain
# PreferredAuthentications publickey
PubkeyAcceptedKeyTypes +ssh-rsa
IdentityFile ~/.ssh/id_rsa
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

修改后进行测试:
git服务器可正常访问。

$ ssh -p <git_port> git_user_name@your.git.domain
  ****    Welcome to Gerrit Code Review    ****
  Hi git_user_name, you have successfully connected over SSH.
Connection to gerrit.qisi.ltd closed.
  • 1
  • 2
  • 3
  • 4
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/649022
推荐阅读
相关标签
  

闽ICP备14008679号