key_load_public:ssh-keygen之后格式无效

时间:2017-04-07 08:07:05

标签: ubuntu ssh

将Ubuntu更新到16.04后我遇到了ssh连接的问题,现在连接需要密码,虽然我的公钥是通过ssh-copy-id复制到远程authorized_keys中的。在收到key_load_public: invalid format的新ssh-copy-id后,为了确保正确的密钥格式,我已经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.

1 个答案:

答案 0 :(得分:0)

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

cd ~/.ssh

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

cat <key>.pub >> authorized_keys

将另一个密钥文件(私钥)复制到您的计算机,然后使用它可以登录。使用以下命令

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

如果你想在没有密钥文件帮助的情况下实现ssh连接,每次将机器中生成的.pub文件添加到远程机器的〜/ .ssh / authorized_keys,这样你就可以通过给出ip或hostname来登录/ p>