0

环境:

VM A : 我想在没有密码的情况下访问的机器

VM B : 我想从机器上访问没有密码的 VM A

问题描述:

由于我想在没有密码的情况下从 VM B 访问 VM A,我想首先将 VM B 的公钥注入 VM A,但如果我使用 ssh-copy,我仍然需要密码,所以我尝试通过挂载注入文件。

步骤:

  1. 从 LiveCD 启动 VM A
  2. 挂载VM A的根盘(包含操作系统)
  3. 在 ${mount_point}/root/.ssh/ 下创建一个 authorized_keys 文件
  4. 将 VM B 的公钥放入 authorized_keys 文件中
  5. 停止 VM A 并移除 LiveCD,然后再次启动 VM A
  6. 通过命令从 VM B 访问 VM A

    ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PasswordAuthentication=no root@9.112.224.130

结果:

debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug3: no such identity: /root/.ssh/identity
debug1: Offering public key: /root/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug3: Wrote 368 bytes for a total of 1645
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.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,password).

但是在我执行了以下命令之后,它就可以工作了(文件模式都是 600 并且与 diff 命令没有区别)

mv authorized_keys authorized_keys_bak
cp authorized_keys_bak authorized_keys

所以我尝试再次注入它,但是这次,我在从LiveCD启动之前创建了一个空的authorized_keys文件,并跳过了第3步,其他步骤都一样,这次VM B可以在没有密码的情况下访问VM A

问题:

  1. authorized_keys 和 authorized_keys_bak 的属性都是一样的,为什么一个有效,一个无效?

  2. 我的authorized_keys 只能在我创建文件而不是从LiveCD 挂载时工作?

4

1 回答 1

0

ssh-copy-id 将询问您一次密码以将密钥注入远程系统。

您显示的日志来自 ssh 客户端。我们还需要 ssh 服务器日志来检查为什么 ssh 服务器无法验证用户凭据。

从客户端日志中,我们可以说,它尝试了基于公钥(无密码)的身份验证,但失败了(意味着被服务器拒绝)。所以剩下的方法是“键盘交互”(服务器支持),但客户端不支持它,所以没有验证方法可以尝试,所以它失败了。

您还可以检查以下工作和非工作场景吗

检查客户端和服务器上用于客户端身份验证的用户公钥 -> 服务器上的 /users//.ssh/id_rsa.pub -> /etc/ssh/authorized_keys (检查您的用户名的条目)

于 2014-09-23T05:21:49.647 回答