赞
踩
在新安装的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.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。