【问题标题】:key_load_public: invalid format after ssh-keygenkey_load_public:ssh-keygen 后的格式无效
【发布时间】:2019-04-15 00:20:09
【问题描述】:

在将 Ubuntu 更新到 16.04 后,我的 ssh 连接出现了一些问题,现在连接需要密码,尽管我的公钥是通过 ssh-copy-id 复制到远程授权密钥中的。在收到新的 ssh-copy-id 后,我收到 key_load_public: invalid format,为了确保正确的密钥格式,我通过 ssh-keygen 生成了新密钥并重新启动 ssh-copy-id 但结果相同 key_load_public: invalid format,与我必须输入密码的所有 ssh 连接相同。

如何在我的远程服务器上生成密钥并复制而不会收到此“无效格式”错误?

ssh -v <user>@<host-name>:

OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: /etc/ssh/ssh_config line 57: Deprecated option "useroaming"
debug1: Connecting to <host-name> [<ip>] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/<user>/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<user>/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<user>/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<user>/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<user>/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<user>/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<user>/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/<user>/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to <my_host>:22 as '<user>'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:2XmTTbzpU31c8OfZCyzMPspS9HE0VASPA7RliKRX5aA
The authenticity of host '<host-name> (<ip>)' can't be established.
ECDSA key fingerprint is SHA256:2XmTTbzpU31c8OfZCyzMPspS9HE0VASPA7RliKRX5aA.

【问题讨论】:

  • 您使用的是什么密钥类型?完整的调试日志是什么样的?
  • Stackoverflow 为软件开发提供帮助。对于一般 ssh 使用的问题,您应该考虑在 Super UserUnix & Linux 上提问。话虽如此,我在您的问题中包含的 ssh 调试输出中没有看到无效的格式错误。如果您认为这个问题是这里的主题,您应该 edit 您的问题包含一个 ssh 调用,该调用实际上证明了您遇到的问题。
  • 好吧,你是对的!如何将我的问题转移到超级用户或 Unix 和 Linux?

标签: ubuntu ssh


【解决方案1】:

然后使用 ssh-keygen 命令在远程机器上生成密钥

cd ~/.ssh

在远程机器上生成 sshkey 并将 .pub 文件复制到授权密钥,只需执行以下命令即可

cat <key>.pub >> authorized_keys

将其他密钥文件(私钥)复制到您的机器,然后使用它可以登录。为此使用以下命令

ssh -i <key-file> <username>@<ip>

如果您想在每次不借助密钥文件的情况下实现 ssh 连接,请将您机器中生成的 .pub 文件添加到远程机器的 ~/.ssh/authorized_keys 中,以便您只需提供 ip 或主机名即可登录

【讨论】:

  • 谢谢你的回答,一个问题这个程序会影响其他用户的ssh连接吗?我不是唯一在这个远程服务器上使用 ssh 连接的人
  • 不,除非您从 authorized_keys 文件中删除任何内容,否则不会。
  • 大神,我试试这个程序,希望对我有帮助,非常感谢!
  • 一切正常,直到我尝试仅使用 user@hostname 的 ssh,在这种情况下,我收到相同的错误:key_load_public: invalid format,在我的授权密钥文件中,我复制了生成的 .pub 文件的内容在服务器上,奇怪的是当我启动ssh -i &lt;key_file_path&gt; user@host 时,连接不需要密码。有什么想法吗?
  • 从您的机器访问,过程是相反的,即;在您的机器中生成密钥并将 .pub 文件复制到远程机器的 ~/.ssh/authorized_keys 中。这也是一种无密码身份验证方法,只需要密钥作为身份验证。
猜你喜欢
  • 1970-01-01
  • 2010-10-31
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 2017-08-09
  • 2017-05-14
  • 1970-01-01
  • 2014-08-15
相关资源
最近更新 更多