问题

由于业务需求,在Google Cloud Platform (GCP)上面开了一台Windows的Computer Engine。跑了一段时间之后,远程桌面无法链接了,但是http等其他服务还是可以正常访问。

解决

正常的操作方法是进入到服务器管理后台,进控制台(VNC),登录到服务器,排查解决问题。但是GCP好像没有提供控制台(VNC)的管理功能。 经过阅读GCP文档,发现他们提供通过windows SAC(特殊管理控制台)链接到windows服务器
接下来我们就使用windows SAC链接到这台windows服务器来解决问题。

先决条件

必须先为虚拟机启用交互式访问权限,然后才能使用交互式串行控制台连接到虚拟机

方法

  1. 在 Google Cloud Console 中,转到虚拟机实例页面。
  2. 点击要连接到的虚拟机的名称。
  3. 点击连接到串行控制台以打开交互式控制台。

系统会打开交互式串行控制台。当您看到以下输出时,即可使用:

Computer is booting, SAC started and initialized.

Use the "ch -?" command for information about using channels.
Use the "?" command for general help.

SAC>

在 Windows SAC 中打开命令提示符

常用的工作流是打开命令提示符或 Powershell 以允许运行命令。如需打开 cmd 渠道,请执行以下操作:

1.输入 cmd,然后按 Enter 键。您将看到以下输出内容:

SAC>cmd
The Command Prompt session was successfully launched.
SAC>
EVENT:   A new channel has been created.  Use "ch -?" for channel help.
Channel: Cmd0001
SAC>

2.使用 ch -sn CHANNEL_NAME 命令,然后按 Enter 键。将 CHANNEL_NAME 替换为您在上一步中创建的渠道的名称

SAC>ch -sn Cmd0001

Name:                  Cmd0001
Description:           Command
Type:                  VT-UTF8
Channel GUID:          28de7392-5413-11ea-bb03-c9656a2ed613
Application Type GUID: 63d02271-8aa4-11d5-bccf-00b0d014a2d0

Press <esc><tab> for next channel.
Press <esc><tab>0 to return to the SAC channel.
Use any other key to view this channel.

3.按空格键,然后使用系统中注册的本地凭据登录。

Please enter login credentials.
Username: USERNAME
Domain: DOMAIN (leave blank if no domain),这里我输入的localhost
Password: PASSWORD

连接后,即可使用命令提示符 shell。

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Windows\system32>

4.进入 Powershell 提示符,请输入 powershell.exe,然后按 Enter 键。

# 查看指定端口的防火墙策略
Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "PortNumber"

# 关闭防火墙
Set-NetFirewallProfile -Profile Domain -Enabled False
Set-NetFirewallProfile -Profile Private -Enabled False
Set-NetFirewallProfile -Profile Public -Enabled False

其他powershell命令请移步微软官方文档

文章目录