Debian 上的 SSH 密钥问题

Debian 上的 SSH 密钥问题

我决定使用密钥进行 SSH 连接,并且正在设置它们,但是,在运行时遇到以下问题scp

scp -P 88 .ssh/id_dsa [email protected]:/home/user1/.ssh/authorized_keys

调试:

OpenSSH_6.7p1 Debian-5, OpenSSL 1.0.1k 8 Jan 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.1.65 [192.168.1.65] port 67.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/user1/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user1/.ssh/id_rsa-cert type -1
debug1: identity file /home/user1/.ssh/id_dsa type 2
debug1: key_load_public: No such file or directory
debug1: identity file /home/user1/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user1/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user1/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user1/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user1/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Debian-5
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-4+deb7u2
debug1: match: OpenSSH_6.0p1 Debian-4+deb7u2 pat OpenSSH* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA e6:5d:9c:48:5f:5b:a7:a5:8a:b2:95:f0:71:aa:19:dc
debug1: Host '[192.168.1.65]:67' is known and matches the ECDSA host key.
debug1: Found key in /home/user1/.ssh/known_hosts:31
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering DSA public key: /home/user1/.ssh/id_dsa
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: user1@virt
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/user1/.ssh/id_rsa
debug1: Trying private key: /home/user1/.ssh/id_ecdsa
debug1: Trying private key: /home/user1/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
lost connection

我检查了authorized_keys文件的权限,它们是700,这里的主题表明这可能是一个原因。

答案1

您将~/.ssh/id_dsa私钥文件复制到~/.ssh/authorized_keys远程主机上。这不是authorized_keys 的工作原理。

删除远程主机上损坏的authorized_keys 文件并尝试以下操作:

ssh-copy-id -P 88 [email protected]

这要求远程主机允许密码访问(仅一次,以便可以复制公钥),并将您的公钥添加到远程主机上的 ~/.ssh/authorized_keys 文件中。

请参阅man ssh-copy-id获取更多详细信息和选项。

如果远程主机不允许密码登录,您必须手动将公钥添加到远程主机。您需要在本地计算机和远程计算机上登录。然后(在本地计算机上)运行cat ~/.ssh/*.pub并将输出复制粘贴到~user1/.ssh/authorized_keys192.168.1.65 上。

如果您没有登录 192.168.1.65 并且由于缺少密钥而无法登录,则必须获取[电子邮件受保护]为您编辑~user1/.ssh/authorized_keys文件(并确保权限正确)。

例如,您可以运行cat ~/.ssh/*.pub > /tmp/mykeys.txt然后将该文件通过电子邮件发送至[电子邮件受保护]并显示一条消息,要求他们将密钥复制到您的authorized_keys 文件中。

相关内容