如何连接并登录到运行 Windows 的 Azure 虚拟机How to connect and sign on to an Azure virtual machine running Windows

可以从 Windows 桌面使用 Azure 门户中的“连接”按钮来启动远程桌面 (RDP) 会话。You'll use the Connect button in the Azure portal to start a Remote Desktop (RDP) session from a Windows desktop. 首先连接到虚拟机,然后登录。First you connect to the virtual machine, and then you sign on.

若要从 Mac 连接到 Windows VM,需要为 Mac 安装 RDP 客户端,例如 Microsoft 远程桌面To connect to a Windows VM from a Mac, you will need to install an RDP client for Mac such as Microsoft Remote Desktop.

连接到虚拟机Connect to the virtual machine

  1. 转到 Azure 门户以连接到 VM。Go to the Azure portal to connect to a VM. 搜索并选择“虚拟机”。Search for and select Virtual machines.

  2. 从列表中选择虚拟机。Select the virtual machine from the list.

  3. 在虚拟机页的开头,选择“连接”。At the beginning of the virtual machine page, select Connect.

  4. 在“连接到虚拟机”页上,选择 RDP,然后选择相应的 IP 地址端口号On the Connect to virtual machine page, select RDP, and then select the appropriate IP address and Port number. 在大多数情况下,应使用默认的 IP 地址和端口。In most cases, the default IP address and port should be used. 选择“下载 RDP 文件”。Select Download RDP File. 如果 VM 具有实时策略集,则首先需要选择“请求访问”按钮来请求访问,然后才能下载 RDP 文件。If the VM has a just-in-time policy set, you first need to select the Request access button to request access before you can download the RDP file. 有关实时策略的详细信息,请参阅使用实时策略管理虚拟机访问For more information about the just-in-time policy, see Manage virtual machine access using the just in time policy.

  5. 打开下载的 RDP 文件,然后在出现提示时选择“连接”。Open the downloaded RDP file and select Connect when prompted. 将收到 .rdp 文件来自未知发布服务器的警告。You will get a warning that the .rdp file is from an unknown publisher. 这是正常情况。This is expected. 在“远程桌面连接”窗口中,选择“连接”以继续。In the Remote Desktop Connection window, select Connect to continue.

    有关未知发布者的警告的屏幕截图。

  6. 在“Windows 安全性”窗口中,依次选择“更多选择”、“使用其他帐户”。In the Windows Security window, select More choices and then Use a different account. 在虚拟机上输入帐户的凭据,然后选择“确定”。Enter the credentials for an account on the virtual machine and then select OK.

    本地帐户:通常,这是创建虚拟机时指定的本地帐户用户名和密码。Local account: This is usually the local account user name and password that you specified when you created the virtual machine. 在本示例中,域是虚拟机的名称,输入格式为 vmname\usernameIn this case, the domain is the name of the virtual machine and it is entered as vmname\username.

    已加入域的 VM:如果 VM 属于某个域,请以\用户名格式输入用户名。Domain joined VM: If the VM belongs to a domain, enter the user name in the format Domain\Username. 该帐户还需要属于管理员组或已被授予 VM 的远程访问权限。The account also needs to either be in the Administrators group or have been granted remote access privileges to the VM.

    域控制器:如果 VM 是域控制器,请输入该域的域管理员帐户的用户名和密码。Domain controller: If the VM is a domain controller, enter the user name and password of a domain administrator account for that domain.

  7. 选择“是”验证虚拟机的标识并完成登录。Select Yes to verify the identity of the virtual machine and finish logging on.

    显示有关验证 VM 标识的消息的屏幕截图。

    提示

    如果门户中的“连接”按钮灰显,并且你未通过 Express Route站点到站点 VPN 连接来连接到 Azure,则必须先为 VM 创建并分配一个公共 IP 地址,然后才能使用 RDP。If the Connect button in the portal is grayed-out and you are not connected to Azure via an Express Route or Site-to-Site VPN connection, you will need to create and assign your VM a public IP address before you can use RDP. 有关详细信息,请参阅 Azure 中的公共 IP 地址For more information, see Public IP addresses in Azure.

使用 PowerShell 连接到虚拟机Connect to the virtual machine using PowerShell

如果使用 PowerShell 并安装了 Azure PowerShell 模块,则还可以使用 Get-AzRemoteDesktopFile cmdlet 进行连接,如下所示。If you are using PowerShell and have the Azure PowerShell module installed you may also connect using the Get-AzRemoteDesktopFile cmdlet, as shown below.

此示例将立即启动 RDP 连接,引导完成与上述类似的提示。This example will immediately launch the RDP connection, taking you through similar prompts as above.

Get-AzRemoteDesktopFile -ResourceGroupName "RgName" -Name "VmName" -Launch

还可以保存 RDP 文件以供将来使用。You may also save the RDP file for future use.

Get-AzRemoteDesktopFile -ResourceGroupName "RgName" -Name "VmName" -LocalPath "C:\Path\to\folder"

后续步骤Next steps

如果连接有困难,请参阅远程桌面连接故障排除If you have difficulty connecting, see Troubleshoot Remote Desktop connections.