我一直在排查一个PubkeyAuthentication
仅限 - 的问题。当我使用详细模式时,我看到很多“key_load_public:没有这样的文件或目录”。
显然,密钥存在于文件系统中,因此该消息似乎没有惯常的含义:
$ ls -al ~/.ssh/id_*
-rw------- 1 jwalton staff 751 Feb 4 2013 id_dsa
-rw------- 1 jwalton staff 608 Feb 18 2015 id_dsa.pub
-rw------- 1 jwalton staff 314 Feb 4 2013 id_ecdsa
-rw------- 1 jwalton staff 180 Feb 18 2015 id_ecdsa.pub
-rw------- 1 jwalton staff 464 Aug 23 18:15 id_ed25519
-rw------- 1 jwalton staff 103 Aug 23 18:15 id_ed25519.pub
-rw------- 1 jwalton staff 2546 Feb 4 2013 id_rsa
-rw------- 1 jwalton staff 572 Feb 18 2015 id_rsa.pub
到底是什么“key_load_public:没有这样的文件或目录”意思是?
我的.ssh/config
文件有:
$ cat ~/.ssh/config
IdentityFile ~/.ssh/id_ed25519
IdentityFile ~/.ssh/id_ecdsa
IdentityFile ~/.ssh/id_dsa
IdentityFile ~/.ssh/id_rsa
添加*.pub
扩展没有效果。我尝试了有和没有扩展,*.pub
因为手册页对于需要指定哪个密钥(公钥还是私钥)含糊不清。(公钥是身份所需要的全部;私钥是在质询/响应中证明密钥所有权所需的):
IdentityFile
Specifies a file from which the user's DSA, ECDSA or DSA authen-
tication identity is read...
$ ssh -v -p 1522 [email protected]
OpenSSH_7.1p1, OpenSSL 1.0.2d 9 Jul 2015
debug1: Reading configuration data /Users/jwalton/.ssh/config
debug1: Reading configuration data /usr/local/etc/ssh_config
debug1: Connecting to 192.168.1.11 [192.168.1.11] port 1522.
debug1: Connection established.
debug1: identity file /Users/jwalton/.ssh/id_ed25519.pub type 4
debug1: key_load_public: No such file or directory
debug1: identity file /Users/jwalton/.ssh/id_ed25519.pub-cert type -1
debug1: identity file /Users/jwalton/.ssh/id_ecdsa.pub type 3
debug1: key_load_public: No such file or directory
debug1: identity file /Users/jwalton/.ssh/id_ecdsa.pub-cert type -1
debug1: identity file /Users/jwalton/.ssh/id_dsa.pub type 2
debug1: key_load_public: No such file or directory
debug1: identity file /Users/jwalton/.ssh/id_dsa.pub-cert type -1
debug1: identity file /Users/jwalton/.ssh/id_rsa.pub type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/jwalton/.ssh/id_rsa.pub-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
...
答案1
它的字面意思就是:没有 ssh 想要访问的文件或目录。
然而,它谈到了提到的文件以下,而不是上面。您只有常规公钥,但没有 SSH证书(可能是因为您不需要它们)。但是,OpenSSH 总是会尝试加载.pub-cert
每个身份密钥的关联文件。
如果您感兴趣的话,ssh-keygen(1) 手册讨论了如何创建 OpenSSH 证书颁发机构和签署证书。(注意:这不使用 X.509,只使用 OpenSSH 自己的证书格式。)
通常,仅当您拥有大量用户(和/或服务器)但不想使用 Kerberos 时,证书才有用。
答案2
在我的例子中,我尝试克隆一个 gitlab 项目,该解决方案应该适用于任何 git 服务。错误是
#15 0.589 debug1: identity file /root/.ssh/id_rsa type -1,
#15 0.589 debug1: key_load_public: No such file or directory
使用后消失
echo "Host *\n User git\n HostName gitlab.com\n AddKeysToAgent yes\n IdentityFile /root/.ssh/id_rsa" >> /etc/ssh/ssh_config
这也是您在消息块中所要求的内容:
debug1: Reading configuration data /etc/ssh/ssh_config
...
debug1: key_load_public: No such file or directory
解决方案证明 ssh 需要检查服务器是否为已知主机。如果你没有指定所需的已知主机,则 gitlab 服务器不受信任,这就是 的意思the key_load_public cannot be found
。是的,错误消息令人困惑。
echo
当然,您也可以不使用命令来手动填写 ssh_config 。
我刚刚看到这也是解决方案服务器故障。