无法将IP地址为'xxx'的RSA主机密钥添加到已知主机列表(/home/webapp/.ssh/known_hosts)中。

3
我正在尝试在我的AWS项目中使用SSH而不是HTTPS访问Git。我按照这里的步骤添加了SSH密钥,但日志中出现了以下错误。
Failed to add the RSA host key for IP address 'xxx' to the list of known hosts (/home/webapp/.ssh/known_hosts).

我把所有权从ec2用户改为webapp。现在我有:
Warning: Permanently added the RSA host key for IP address '192.30.253.113' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

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

ssh -vT git@github.com

gives

OpenSSH_7.4p1,OpenSSL 1.0.2k-fips 于2017年1月26日发布。
debug1: 正在读取/etc/ssh/ssh_config配置文件
debug1: /etc/ssh/ssh_config文件第58行:应用所有选项*
debug1: 正在连接到github.com[192.30.253.112]的22端口。
debug1: 连接已建立。
debug1: 永久设置uid:0/0
debug1: 公钥未找到文件或目录
debug1: identity file /root/.ssh/id_rsa type -1
debug1: 公钥未找到文件或目录
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: 公钥未找到文件或目录
debug1: identity file /root/.ssh/id_dsa type -1
debug1: 公钥未找到文件或目录
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: 公钥未找到文件或目录
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: 公钥未找到文件或目录
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: 公钥未找到文件或目录
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: 公钥未找到文件或目录
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: 为协议2.0启用兼容模式
debug1: 本地版本字符串SSH-2.0-OpenSSH_7.4
debug1: 远程协议版本2.0,远程软件版本babeld-9db747ba
debug1: 没有找到匹配项:babeld-9db747ba
debug1: 正在作为“git”进行身份验证
debug1: SSH2_MSG_KEXINIT已发送
debug1: SSH2_MSG_KEXINIT已接收
debug1: kex: 算法:curve25519-sha256@libssh.org
debug1: kex: 主机密钥算法:rsa-sha2-512
debug1: kex: 服务器->客户端加密:chacha20-poly1305@openssh.com MAC: 压缩:无
debug1: kex: 客户端->服务器加密:chacha20-poly1305@openssh.com MAC: 压缩:无
debug1: kex: curve25519-sha256@libssh.org need=64 dh_need=64
debug1: kex: curve25519-sha256@libssh.org need=64 dh_need=64
debug1: 预计SSH2_MSG_KEX_ECDH_REPLY
debug1: 服务器主机密钥:ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: 主机“github.com”已知且匹配RSA主机密钥。
debug1: 在/root/.ssh/known_hosts中找到密钥的索引:1
警告:已将IP地址“192.30.253.112”的RSA主机密钥永久添加到已知主机列表中。
debug1: 134217728块后重新生成密钥
debug1: SSH2_MSG_NEWKEYS已发送
debug1: 预期SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS已接收
debug1: 134217728块后重新生成密钥
debug1: SSH2_MSG_EXT_INFO已接收
debug1: kex_input_ext_info: server-sig-algs=
debug1: 已接收SSH2_MSG_SERVICE_ACCEPT
debug1: 可以继续进行身份验证的方法:publickey


你完成了最后一步吗?https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account 例如,您可以将cat /root/.ssh/id_rsa.pub的输出添加到Github上的SSH密钥中。 - matthias
2个回答

2

我曾经遇到过同样的问题。对我来说,我没有known_hosts文件的写入权限。 这个命令解决了我的问题。 chmod 644 ~/.ssh/known_hosts


0

通过将配置文件添加到 .ssh 文件夹中进行修复


1
尝试运行以下命令:ssh-keyscan github.com >> ~/.ssh/known_hosts - Hfyuu
@Hfyuu 这是不安全的,容易受到中间人攻击的影响。 - jack

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接