你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
已启用 Arc 的服务器的 SSH 支持与已启用 Arc 的服务器的基于 SSH 的连接,而无需公共 IP 地址或其他开放端口。 本文提供的信息有助于排查尝试通过 SSH 连接到已启用 Azure 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 模块更新到最新版本:
Update-Module -Name Az.Ssh
Update-Module -Name Az.Ssh.ArcProxy
未安装 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).
若要修复此错误,请从 PowerShell 库安装模块: Install-Module -Name 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
可以通过确保用户帐户有权在管理计算机上执行 SSH 代理来解决此问题。
服务器端问题
使用本节中的信息来帮助解决尝试连接到已启用 Arc 的服务器过程中出现的错误问题。
服务器上不允许 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 的服务器上运行。
- 运行以下命令,确保已启用 Arc 的服务器在端口 22(或其他非默认端口)上启用该功能:
az rest --method put --uri https://management.azure.com/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
若要解决此错误,请确保在已启用 Arc 的服务器上具有“所有者”或“参与者”角色,或要求具有其中一个角色的人员设置 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.
若要解决此问题,请确保在您要连接的启用了 Arc 的服务器上具有“虚拟机本地用户登录角色”。 如果使用 Microsoft Entra 登录名,请确保具有虚拟机用户登录名或虚拟机管理员登录角色,并且 Microsoft Entra SSH 登录扩展安装在 Arc-Enabled 服务器上。
未注册 HybridConnectivity RP
如果 HybridConnectivity 资源提供程序没有注册订阅,可能会出现以下错误:
Request for Azure Relay Information Failed: (NoRegisteredProviderFound) Code: NoRegisteredProviderFound
若要解决此问题,请注册订阅的 HybridConnectivity 资源提供程序:
- 运行
az provider register -n Microsoft.HybridConnectivity
。 - 通过运行
az provider show -n Microsoft.HybridConnectivity
确认已成功,并验证registrationState
是否已设置为Registered
。 - 在已启用 Arc 的服务器上重启混合代理。
后续步骤
- 了解如何通过 SSH 访问已启用 Azure Arc 的服务器。
- 了解如何排查代理连接问题。