在虚拟机上进行 SSH 时要求输入无密码私钥的密码

在虚拟机上进行 SSH 时要求输入无密码私钥的密码

当我登录到特定虚拟机时,通过 SSH 连接到服务器时遇到一些问题。

在我的本地 PC 上,我可以使用命令很好地登录到服务器ssh -i .ssh/[my private key] username@domain

如果我然后通过 SSH 连接到另一个不相关的服务器(该服务器也具有相同的私钥)并运行上述命令,它也将很好地登录到该服务器。

但是,当我通过 SSH 连接到不相关服务器上的特定 OpenStack VM(同样具有相同的私钥),然后通过 SSH 连接到该服务器时,我开始收到输入密码短语的提示。但尚未为密钥设置密码,因此我不可避免地收到“权限被拒绝(公钥)”。错误。

为了仔细检查,我从虚拟机中删除了私钥,并scp再次将私钥从我的电脑放入其中,并尝试了相同的命令,但仍然提示输入密码。

换句话说:

  1. PC - SSH - Server1 = 工作正常
  2. PC - SSH - Server2 - SSH - Server1 = 工作正常
  3. PC - SSH - Server2 - SSH - 虚拟机 - SSH - 服务器 1 = 要求输入密码

这背后的原因可能是什么?这绝对是我正在使用的正确私钥,并且具有适当的权限。

ssh -v -i .ssh/[my private key] username@domain编辑 -按要求输出

OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to xxx.xxx.xxx.xxx [xxx.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /.ssh/[my private key].ppk type -1
debug1: key_load_public: No such file or directory
debug1: identity file /.ssh/[my private key].ppk-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to xxx.xxx.xxx.xxx:22 as '[my username]'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: [email protected] need=64 dh_need=64
debug1: kex: [email protected] need=64 dh_need=64
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:ZiugTjR5fM0E3evOwHoePFKspDQChA0Ab6L0q88KP/g
debug1: Host 'xxx.xxx.xxx.xxx' is known and matches the ECDSA host key.
debug1: Found key in /home/centos/.ssh/known_hosts:2
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /.ssh/[my private key].ppk
Enter passphrase for key '/.ssh/[my private key].ppk':
Enter passphrase for key '/.ssh/[my private key].ppk':
Enter passphrase for key '/.ssh/[my private key].ppk':
debug1: No more authentication methods to try.
Permission denied (publickey).

答案1

Enter passphrase for key '/.ssh/[my private key].ppk':

“ppk”是使用的扩展名油灰密钥生成工具。我认为密钥文件是使用 putty 工具生成的。不幸的是,OpenSSHssh实用程序无法读取 PuTTY 密钥文件格式。ssh要求输入密码,因为它会在无法解析密钥文件的任何时候执行此操作。

您可以使用putty key工具以OpenSSH格式导出密钥。您最终应该得到两个文件,my-private-key并且my-private-key.pub. .pub 文件包含安装在远程系统上的公钥部分。另一个文件包含您与该命令一起使用的私钥ssh

或者,您可以使用 OpenSSHssh-keygen实用程序生成新密钥。

相关内容