排查通过 SSH 访问已启用 Azure Arc 的服务器的问题

本文提供有关排查和解决尝试通过 SSH 连接到已启用 Azure Arc 的服务器时可能出现的问题的信息。 如需常规信息,请参阅通过 SSH 访问已启用 Arc 的服务器概述

客户端问题

这些问题是由用户从其连接的计算机上发生的错误造成的。

找不到客户端二进制文件

找不到连接所需的客户端 SSH 二进制文件时,会出现此问题。 可能的错误:

  • Failed to create ssh key file with error: \<ERROR\>.
  • Failed to run ssh command with error: \<ERROR\>.
  • Failed to get certificate info with error: \<ERROR\>.
  • Failed to create ssh key file with error: [WinError 2] The system cannot find the file specified.
  • Failed to create ssh key file with error: [Errno 2] No such file or directory: 'ssh-keygen'.

解决方法:

  • 使用 --ssh-client-folder 参数提供包含 SSH 客户端可执行文件的文件夹路径。
  • 确保文件夹位于 Azure PowerShell 的 PATH 环境变量中

Azure PowerShell 模块版本不匹配

如果安装的 Az.Ssh 版本不支持安装的 Azure PowerShell 子模块 Az.Ssh.ArcProxy,则会出现此问题。 错误:

  • This version of Az.Ssh only supports version 1.x.x of the Az.Ssh.ArcProxy PowerShell Module. The Az.Ssh.ArcProxy module {ModulePath} version is {ModuleVersion}, and it is not supported by this version of the Az.Ssh module. Check that this version of Az.Ssh is the latest available.

解决方法:

  • 更新 Az.Ssh 和 Az.Ssh.ArcProxy 模块

未安装 Az.Ssh.ArcProxy

在客户端计算机上找不到代理模块时,会出现此问题。 错误:

  • Failed to find the PowerShell module Az.Ssh.ArcProxy installed in this machine. You must have the Az.Ssh.Proxy PowerShell module installed in the client machine in order to connect to Azure Arc resources. You can find the module in the PowerShell Gallery (see: https://aka.ms/PowerShellGallery-Az.Ssh.ArcProxy).

解决方法:

用户没有权限执行代理

当用户没有权限执行用于连接的 SSH 代理时,则会发生此问题。 错误:

  • /bin/bash: line 1: exec: /usr/local/share/powershell/Modules/Az.Ssh.ArcProxy/1.0.0/sshProxy_linux_amd64_1.3.022941: cannot execute: Permission denied
  • CreateProcessW failed error:5 posix_spawnp: Input/output error

解决方法:

  • 确保用户有权执行代理文件。

服务器端问题

参加公共预览版计划后无法连接

如果用户已经参加了公共预览版,并且已将其 Arc 代理和 Azure CLI/PowerShell 更新到正式发布版本,则连接可能会失败。

解决方法:

服务器上不允许 SSH 流量

如果 SSHD 未在服务器上运行,或者服务器上不允许 SSH 流量时,则会出现此问题。 错误:

  • {"level":"fatal","msg":"sshproxy: error copying information from the connection: read tcp 192.168.1.180:60887-\u003e40.122.115.96:443: wsarecv: An existing connection was forcibly closed by the remote host.","time":"2022-02-24T13:50:40-05:00"}
  • {"level":"fatal","msg":"sshproxy: error connecting to the address: 503 connection to localhost:22 failed: dial tcp [::1]:22: connectex: No connection could be made because the target machine actively refused it.. websocket: bad handshake","proxyVersion":"1.3.022941"}
  • SSH connection is not enabled in the target port {Port}.

解决方法:

  • 确保 SSHD 服务在已启用 Arc 的服务器上运行。
  • 确保端口 22(或其他非默认端口)上已启用 Arc 的服务器上,已启用此功能

az rest --method put --uri https://management.chinacloudapi.cn/subscriptions/<subscription>/resourceGroups/<resourcegroup>/providers/Microsoft.HybridCompute/machines/<arc enabled server name>/providers/Microsoft.HybridConnectivity/endpoints/default/serviceconfigurations/SSH?api-version=2023-03-15 --body '{\"properties\": {\"serviceName\": \"SSH\", \"port\": \"22\"}}'

Azure 权限问题

角色分配错误,无法启用 SSH 连接

当为当前用户分配的角色不正确,使其无法为目标资源做出贡献时,会出现此问题。 错误:

  • Client is not authorized to create a Default connectivity endpoint for {Name} in the Resource Group {ResourceGroupName}. This is a one-time operation that must be performed by an account with Owner or Contributor role to allow connections to target resource

解决方法:

  • 确保拥有资源的“所有者”或“参与者”角色,或联系资源的所有者/参考者来设置 SSH 连接。

分配的角色不正确,无法连接

当前用户在目标资源上没有适合的角色分配时,特别是缺少 read 权限时,会出现此问题。 可能的错误:

  • Unable to determine the target machine type as Azure VM or Arc Server
  • Unable to determine that the target machine is an Arc Server
  • Unable to determine that the target machine is an Azure VM
  • Permission denied (publickey).
  • Request for Azure Relay Information Failed: (AuthorizationFailed) The client '\<user name\>' with object id '\<ID\>' does not have authorization to perform action 'Microsoft.HybridConnectivity/endpoints/listCredentials/action' over scope '/subscriptions/\<Subscription ID\>/resourceGroups/\<Resource Group\>/providers/Microsoft.HybridCompute/machines/\<Machine Name\>/providers/Microsoft.HybridConnectivity/endpoints/default' or the scope is invalid. If access was recently granted, please refresh your credentials.

解决方法:

  • 确保在要连接的资源上拥有“虚拟机本地用户登录”角色。 如果使用 Microsoft Entra 登录,请确保拥有“虚拟机用户登录”或“虚拟机管理员登录”角色,并确保在启用了 Arc 的服务器上安装 Microsoft Entra SSH 登录扩展。

未注册 HybridConnectivity RP

HybridConnectivity 资源提供程序未注册订阅时,会出现此问题。 错误:

  • 请求 Azure 中继信息失败: (NoRegisteredProviderFound) Code: NoRegisteredProviderFound

解决方法:

  • az provider register -n Microsoft.HybridConnectivity运行
  • 通过运行 az provider show -n Microsoft.HybridConnectivity 确认成功,验证 registrationState 是否设置为 Registered
  • 在已启用 Arc 的服务器上重启混合代理

更新 CLI 工具和 Arc 代理后无法连接

当更新后的命令在 Arc 代理更新之前创建新的服务配置时,会出现此问题。 这只会影响更新到版本 1.31 或更高版本时低于 1.31 的 Azure Arc 版本。 错误:

  • 未知端口 65535 关闭的连接

    解决方法:

    • 删除现有服务配置,并允许在下一个连接时由 CLI 命令重新创建它。 az rest --method delete --uri https://management.chinacloudapi.cn/subscriptions/<SUB_ID>/resourceGroups/<RG_NAME>/providers/Microsoft.HybridCompute/machines/<VM_NAME>/providers/Microsoft.HybridConnectivity/endpoints/default/serviceconfigurations/SSH?api-version=2023-03-15运行

对已启用 Arc 的服务器禁用 SSH

可以通过完成以下操作来禁用此功能:

  • 从启用了 Arc 的服务器中删除 SSH 端口和功能:az rest --method delete --uri https://management.chinacloudapi.cn/subscriptions/<subscription>/resourceGroups/<resourcegroup>/providers/Microsoft.HybridCompute/machines/<arc enabled server name>/providers/Microsoft.HybridConnectivity/endpoints/default/serviceconfigurations/SSH?api-version=2023-03-15 --body '{\"properties\": {\"serviceName\": \"SSH\", \"port\": \"22\"}}'

  • 删除默认连接终结点:az rest --method delete --uri https://management.chinacloudapi.cn/subscriptions/<subscription>/resourceGroups/<resourcegroup>/providers/Microsoft.HybridCompute/machines/<arc enabled server name>/providers/Microsoft.HybridConnectivity/endpoints/default?api-version=2023-03-15

后续步骤