如果要重置设备的 root 密码,您必须将 NSX 设备配置为在引导时显示 GRUB 菜单。

NSX 4.0.1.1 开始,您可以使用 CLI 或 API 命令设置 GRUB 超时值和密码。部署 NSX 后,您可以按照以下命令进行操作。

重要说明: 如果在部署设备后未执行配置并且忘记了 root 密码,则无法进行重置。

过程

  1. 使用 CLI 设置 GRUB 菜单:
    1. 登录到 NSX 命令行界面。
    2. 运行 set grub menu timeout <value>

      其中,<value> 是以秒为单位的时间。默认超时值为 4。

    3. 运行 set grub user root password <newpassword>

    4. 运行 set grub user root password

      Enter password:<newpassword>

      Confirm password:<newpassword>

  2. 使用 API 设置 GRUB 菜单:
    1. 使用 GET API 检索 GRUB 菜单值。
      GET https://<nsx-mgr>/api/v1/node/grub
      
      Example Response:
      {
        "timeout": 4,
        "users": [
          {
            "username": "root"
          }
        ]
      }
    2. 设置 GRUB 超时值。
      PUT https://<nsx-mgr>/api/v1/node/grub { "timeout": 4 }
      Example Response:
      {
        "timeout": 4
      }
    3. 设置 GRUB 菜单密码。
      PUT https://<nsx-mgr>/api/v1/node/grub/root { "password": "Str0ng_Pwd!Wins$" }
      Example Response:
      {
        "username": "root"
      }
  3. 获取 GRUB 超时值。

    get grub menu timeout

    GRUB 菜单超时 = 4