【问题标题】:ESXi keeps prompting for password after adding ssh public key to authorized_keys将 ssh 公钥添加到 authorized_keys 后,ESXi 不断提示输入密码
【发布时间】:2022-08-12 22:24:15
【问题描述】:

我想将我的 ssh 公钥添加到 ESXi 7 主机,这样我就可以通过 ssh 登录而无需使用密码。

但是 esx 主机不断提示我输入密码。

我尝试了以下方法:

方案 A

使用“正常”方式将 ssh 密钥添加到主机时。

  1. ssh-keygen -t rsa 建立一个 ssh 密钥对
  2. 使用ssh-copy-id root@esx.host 将 ssh 公钥推送到 ESXi 主机
  3. 现在尝试使用ssh root@esx.host 登录到 esx 主机

    这将再次提示您输入密码。

    失败的原因

    ssh 密钥已添加到 esx 主机 ~/.ssh/authorized_keys - 但 SSH 服务预计会在 /etc/ssh/keys-root/authorized_keys 中找到密钥。

    方案 B

    添加正确的位置

    1. 通过cat ~/.ssh/id_rsa.pub | ssh root@esx.host \'cat >>/etc/ssh/keys-root/authorized_keys\'将密钥复制到esx中
    2. 再次尝试使用ssh root@esx.host 登录

      还是要密码。

    标签: ssh esxi authorized-keys


    【解决方案1】:

    场景 B 失败是有原因的

    失败的原因

    生成的 ssh 密钥默认为 2048 位,但应该是 4096 位。

    最终解决方案

    # Generate the 4096 ssh key
    ssh-keygen -t rsa -b 4096
    
    # Copy the public key the right place on the esx host
    cat ~/.ssh/id_rsa.pub | ssh root@esx.host 'cat >>/etc/ssh/keys-root/authorized_keys'
    
    # Then login
    ssh root@esx.host
    

    Tada - 现在无需使用密码即可登录

    Password:
    The time and date of this login have been sent to the system logs.
    
    WARNING:
       All commands run on the ESXi shell are logged and may be included in
       support bundles. Do not provide passwords directly on the command line.
       Most tools can prompt for secrets or accept them from standard input.
    
    VMware offers supported, powerful system administration tools.  Please
    see www.vmware.com/go/sysadmintools for details.
    
    The ESXi Shell can be disabled by an administrative user. See the
    vSphere Security documentation for more information.
    [root@esx.host:~]
    
    

    【讨论】:

      最近更新 更多