Ubuntu 22.04系统git/repo/github/codeup等 无法用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.

或者

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.

首先确认本地和服务器端的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]

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

PubkeyAcceptedKeyTypes +ssh-rsa

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

$ cat .ssh/config 
Host your.git.domain
HostName your.git.domain
# PreferredAuthentications publickey
PubkeyAcceptedKeyTypes +ssh-rsa
IdentityFile ~/.ssh/id_rsa

修改后进行测试:
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.
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

抓饼先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值