對 Arc 已啟用伺服器的 SSH 讓使用者能在不需要公用 IP 位址或額外開啟埠的情況下,建立到 Arc 已啟用伺服器的 SSH 連線。 本文提供的資訊可協助您針對嘗試透過 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
許可權不足,無法執行 Proxy
如果您的帳戶沒有執行用來連線的 SSH Proxy 許可權,您可能會看到下列錯誤:
/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 Proxy 的許可權,來解決此問題。
伺服器端問題
使用本節中的資訊,協助解決您嘗試連線之 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}.
若要解決此問題:
- 確定正在已啟用 Arc 的伺服器上執行 SSHD 服務。
- 執行下列命令,確定已啟用 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 的伺服器上重新啟動混合式代理程式。
下一步
- 了解已啟用 Azure Arc 的伺服器的 SSH 存取。
- 了解如何針對代理程式連線問題進行疑難排解。