提示:不同的仓库平台可能会要求不同的key生成算法,配置key时请注意检查
执行
ssh -T xxx@gerrit.rnd.test.com -p 29999
报错:Permission denied (publickey).
解决办法一:执行ssh-agent bash; ssh-add ~/.ssh/id_rsa
(注意,这里是私钥)
如果按解决办法一处理后出现相同报错,执行ssh -vv xxx@gerrit.rnd.test.com -p 29999 查看使用的key:
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/test/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279 #使用了sha2的key
debug1: Authentications that can continue: publickey
debug1: Offering ECDSA public key: /home/test/.ssh/id_ecdsa
debug1: Authentications that can continue: publickey
debug1: Offering ED25519 public key: /home/test/.ssh/id_ed25519
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
解决办法二:
ssh-keygen -t ed25519
#生成~/.ssh/id_ed25519,注意不要删除原有的 ~/.ssh/id_rsa
vim .ssh/config
加以下内容
Host gerrit.rnd.test.com
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
PreferredAuthentications publickey
将~/.ssh/id_ed25519.pub加到gerrit.rnd.test.com
执行ssh -vv xxx@gerrit.rnd.test.com -p 29999 ,显示结果包含以下内容:
debug1: Offering ED25519 public key: ~/.ssh/id_ed25519 #key替换成功,新旧版本gerrit服务器使用不同的ssh key。
debug1: Server accepts key: pkalg ssh-ed25519 blen 51
debug1: Authentication succeeded (publickey).
Authenticated to gerrit.rnd.test.com ([172.56.17.2]:29999).
如果到这一步,还不行,请按照步骤一将步骤二生成的私钥add一下,可能会提示
Permissions 0644 for 'id_ed25519' are too open.
解决办法:执行以下命令修改文件权限,密钥文件权限太大也会导致无法访问仓库
chmod 500 id_ed25519
https://blog.csdn.net/halazi100/article/details/124496131