无法通过 SSH 连接到 Azure VM——连接超时
Unable to ssh into Azure VM -- connection timed out
我正在尝试使用 Azure CLI 创建一个 VM,然后 ssh
从 Azure Cloud Shell 进入它。我按照官方指南 (https://docs.microsoft.com/en-us/azure/virtual-machines/linux/quick-create-cli) 运行 这些命令:
$ az group create --name myGroupName --location westus2
$ az vm create --resource-group myGroupName --name myVmName --image UbuntuLTS --admin-username azureuser --generate-ssh-keys
但是,当尝试通过 ssh
连接上面第二个命令报告的 public IP 地址时,连接超时:
$ ssh -vvv azureuser@publicIpAddress
OpenSSH_7.2p2 Ubuntu-4ubuntu2.10, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "publicIpAddress" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to publicIpAddress [publicIpAddress] port 22.
debug1: connect to address publicIpAddress port 22: Connection timed out
ssh: connect to host publicIpAddress port 22: Connection timed out
对我做错了什么有什么建议吗?
此外,我已经在本地计算机上的 Powershell 中尝试了 运行 这些命令。我发现在创建新资源组并启动 VM 后,我可以使用 Powershell ssh
进入 VM。但是当我断开与 VM 的连接然后尝试 ssh
重新连接时,我无法重新连接,因为它会导致超时错误。如果我尝试在同一个资源组下创建一个新的 VM,我根本无法 ssh
进入它。相反,如果我创建一个新的资源组和一个新的 VM,我可以 ssh
第一次进入它,但不能在后续尝试中。
据我所知,您可以在创建 Azure VM 后检查当前订阅中是否有 NSG 通过 Azure 策略或其他自动关联到您的 VM NIC 或子网。可能,它在 NSG 中添加了一些入站端口规则来阻止网络连接。如果要通过 SSH 连接到 Azure VM。它必须具有更高优先级的入站规则才能允许访问端口 22,如下所示。您还可以将您的客户端 public IP 添加为规则中的 源 以缩小限制。
尝试在 Azure 门户中测试您的连接
它向您指出“网络”选项卡中的确切入站规则可能会阻止您的连接。
我正在尝试使用 Azure CLI 创建一个 VM,然后 ssh
从 Azure Cloud Shell 进入它。我按照官方指南 (https://docs.microsoft.com/en-us/azure/virtual-machines/linux/quick-create-cli) 运行 这些命令:
$ az group create --name myGroupName --location westus2
$ az vm create --resource-group myGroupName --name myVmName --image UbuntuLTS --admin-username azureuser --generate-ssh-keys
但是,当尝试通过 ssh
连接上面第二个命令报告的 public IP 地址时,连接超时:
$ ssh -vvv azureuser@publicIpAddress
OpenSSH_7.2p2 Ubuntu-4ubuntu2.10, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "publicIpAddress" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to publicIpAddress [publicIpAddress] port 22.
debug1: connect to address publicIpAddress port 22: Connection timed out
ssh: connect to host publicIpAddress port 22: Connection timed out
对我做错了什么有什么建议吗?
此外,我已经在本地计算机上的 Powershell 中尝试了 运行 这些命令。我发现在创建新资源组并启动 VM 后,我可以使用 Powershell ssh
进入 VM。但是当我断开与 VM 的连接然后尝试 ssh
重新连接时,我无法重新连接,因为它会导致超时错误。如果我尝试在同一个资源组下创建一个新的 VM,我根本无法 ssh
进入它。相反,如果我创建一个新的资源组和一个新的 VM,我可以 ssh
第一次进入它,但不能在后续尝试中。
据我所知,您可以在创建 Azure VM 后检查当前订阅中是否有 NSG 通过 Azure 策略或其他自动关联到您的 VM NIC 或子网。可能,它在 NSG 中添加了一些入站端口规则来阻止网络连接。如果要通过 SSH 连接到 Azure VM。它必须具有更高优先级的入站规则才能允许访问端口 22,如下所示。您还可以将您的客户端 public IP 添加为规则中的 源 以缩小限制。
尝试在 Azure 门户中测试您的连接
它向您指出“网络”选项卡中的确切入站规则可能会阻止您的连接。