将公钥添加到授权主机后,为什么`ssh`无法正常工作?

时间:2017-03-26 17:28:08

标签: ssh amazon-ec2 ssh-keys pem

我设置了一个主节点和一个从节点的集群。我想在主节点和从节点之间进行ssh。

现在,我可以使用我的私钥ssh从我的本地计算机{和{1}}以及从我的主节点直接进入从属设备。我被要求输入密码,然后输入密码并可以从我的本地机器和我的开发大师访问从属节点。

理想情况下,我想从开发主服务器上的ssh -i ~/.ssh/id_rsa ec2-user@<IP>目录中删除我的私有id_rsa密钥,并仅在主服务器之间来回使用我的公钥~/.sshid_rsa.pub和从属节点。 (这是出于安全原因,加上它不应该那么困难,对吗?)。

因此,我将公钥ssh添加到从属节点上的id_rsa.pub。现在,当我尝试从主节点ssh到从属节点时,它会要求我输入authorized_keys的密码:

id_rsa.pub

并且,我输入的密码与ssh -i ~/.ssh/id_rsa.pub ec2-user@<IP> Enter passphrase for key '~/.ssh/id_rsa.pub' 相同,但密码失败。 :/(我也尝试按Enter(无密码))也不起作用。

我有两个问题:

  • 1)为什么id_rsa的密码与id_rsa.pub的密码不相同?
  • 2)当我将公共密钥id_rsa添加到id_rsa.pub文件时,为什么我不能使用公共密钥进入从属节点?

当我尝试从我的主服务器ssh到我的slave时,将公钥添加到authorized_keys这里是详细输出:

~/.ssh/authorized_keys

当我的公钥被添加为debug2: ssh_connect: needpriv0 debug1: Connecting to <ip> [<ip>] port 22. debug1: Connection established. debug1: identity file /home/ec2-user/.ssh/identity type -1 debug3: Not a RSA1 key file /home/ec2-user/.ssh/id_rsa. debug2: key_type_from_name: unknown key type '-----BEGIN' debug3: key_read: missing keytype debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug2: key_type_from_name: unknown key type '-----END' debug3: key_read: missing keytype debug1: identity file /home/ec2-user/.ssh/id_rsa type 1 debug1: identity file /home/ec2-user/.ssh/id_dsa type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3 debug1: match: OpenSSH_5.3 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_5.3 debug2: fd 3 setting O_NONBLOCK debug1: SSH2_MSG_KEXINIT sent debug3: Wrote 792 bytes for a total of 813 debug1: SSH2_MSG_KEXINIT received debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 debug2: kex_parse_kexinit: ssh-rsa,ssh-dss debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: first_kex_follows 0 debug2: kex_parse_kexinit: reserved 0 debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 debug2: kex_parse_kexinit: ssh-rsa,ssh-dss debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: none,zlib@openssh.com debug2: kex_parse_kexinit: none,zlib@openssh.com debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: first_kex_follows 0 debug2: kex_parse_kexinit: reserved 0 debug2: mac_setup: found hmac-md5 debug1: kex: server->client aes128-ctr hmac-md5 none debug2: mac_setup: found hmac-md5 debug1: kex: client->server aes128-ctr hmac-md5 none debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP debug3: Wrote 24 bytes for a total of 837 debug2: dh_gen_key: priv key bits set: 138/256 debug2: bits set: 508/1024 debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY debug3: Wrote 144 bytes for a total of 981 debug3: check_host_in_hostfile: filename /home/ec2-user/.ssh/known_hosts debug3: check_host_in_hostfile: match line 1 debug1: Host '<ip>' is known and matches the RSA host key. debug1: Found key in /home/ec2-user/.ssh/known_hosts:1 debug2: bits set: 521/1024 debug1: ssh_rsa_verify: signature correct debug2: kex_derive_keys debug2: set_newkeys: mode 1 debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug3: Wrote 16 bytes for a total of 997 debug2: set_newkeys: mode 0 debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug3: Wrote 48 bytes for a total of 1045 debug2: service_accept: ssh-userauth debug1: SSH2_MSG_SERVICE_ACCEPT received debug2: key: /home/ec2-user/.ssh/identity ((nil)) debug2: key: /home/ec2-user/.ssh/id_rsa (0x7f2d4970bf40) debug2: key: /home/ec2-user/.ssh/id_dsa ((nil)) debug3: Wrote 64 bytes for a total of 1109 debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password debug3: authmethod_lookup gssapi-keyex debug3: remaining preferred: gssapi-with-mic,publickey,keyboard-interactive,password debug3: authmethod_is_enabled gssapi-keyex debug1: Next authentication method: gssapi-keyex debug1: No valid Key exchange context debug2: we did not send a packet, disable method debug3: authmethod_lookup gssapi-with-mic debug3: remaining preferred: publickey,keyboard-interactive,password debug3: authmethod_is_enabled gssapi-with-mic debug1: Next authentication method: gssapi-with-mic debug3: Trying to reverse map address <ip>. debug1: Unspecified GSS failure. Minor code may provide more information Server krbtgt/US-WEST-2.COMPUTE.INTERNAL@host.COM not found in Kerberos database debug2: we sent a gssapi-with-mic packet, wait for reply debug3: Wrote 96 bytes for a total of 1205 debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic debug2: we did not send a packet, disable method debug3: authmethod_lookup publickey debug3: remaining preferred: keyboard-interactive,password debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Trying private key: /home/ec2-user/.ssh/identity debug3: no such identity: /home/ec2-user/.ssh/identity debug1: Offering public key: /home/ec2-user/.ssh/id_rsa debug3: send_pubkey_test debug2: we sent a publickey packet, wait for reply debug3: Wrote 368 bytes for a total of 1573 debug1: Server accepts key: pkalg ssh-rsa blen 277 debug2: input_userauth_pk_ok: SHA1 fp df:e5:5b:18:67:05:8b:4d:06:6c:f9:99:c3:b5:2b:9f:4e:f2:52:8a debug3: sign_and_send_pubkey debug1: read PEM private key done: type RSA debug3: Wrote 640 bytes for a total of 2213 debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic debug1: Trying private key: /home/ec2-user/.ssh/id_dsa debug3: no such identity: /home/ec2-user/.ssh/id_dsa debug2: we did not send a packet, disable method debug1: No more authentication methods to try. Permission denied (publickey,gssapi-keyex,gssapi-with-mic). 时,我不知道为什么它不会让我进入从属节点。

或者,如果在主节点和从节点之间有一种更简单的authorized_keys方式,我也会对此持开放态度。感谢。

2 个答案:

答案 0 :(得分:2)

公钥和私钥是锁密钥对。您的公钥不是密钥,而是锁。您可以将锁定交给任何人,但绝不会泄露您的私钥。你的服务器有锁。如下面的评论中所述,您无法使用锁打开锁。使用ssh -i privatekey ip@aws将有效。不是ssh -i publickey ip@aws

答案 1 :(得分:1)

ssh -i ~/.ssh/id_rsa.pub ec2-user@<IP>

您应该在这里使用私钥。不是公众的。在最近的几个版本中,SSH错误地asking passphrase for quite everything,但现在应该修复它。

  

2)为什么我将公钥id_rsa.pub添加到authorized_keys文件时不能使用公钥id进入从节点?

键可能设置错误。以调试模式运行客户端和服务器(LogLevel DEBUG3ssh_confing中的sshd_config)并查看日志。如果您无法从中找到答案,请使用日志更新问题。

debug1: Server accepts key: pkalg ssh-rsa blen 277
debug2: input_userauth_pk_ok: SHA1 fp df:e5:5b:18:67:05:8b:4d:06:6c:f9:99:c3:b5:2b:9f:4e:f2:52:8a
debug3: sign_and_send_pubkey
debug1: read PEM private key done: type RSA
debug3: Wrote 640 bytes for a total of 2213
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic

上面的日志表明密钥已被接受,但仅授予您访问该服务器的权限。更多信息将显示在服务器日志中。