Certificate warnings are annoying, regardless of the program. In this case, a remote desktop connection (RDP) warns of an invalid certificate.
Everyone is probably familiar with this message:
Es handelt sich hier um einen „normalen“ Windows Server, also keinen Remote Desktop Host (Terminal Server), RDP ist hier nur für die Administration aktiviert. Windows verwendet in der Standard Konfiguration ein selbstsigniertes Zertifikat:
As the self-signed certificate is not accepted by the client, the warning appears as shown above.
In my case, it is an Exchange server that already has a valid certificate from a public CA for its host name:
Warum nicht also dieses Zertifikat auch für RDP nutzen und damit die Warnung loswerden? Nein, auf „Nicht erneut fragen“ klicken ist keine Option :-)
Natürlich klappt folgende Weg auch mit jedem anderen Zertifikat und auch mit „Nicht-Exchange“-Servern. Woher das Zertifikat stammt, von einer internen PKI oder öffentlichen CA, spielt dabei keine Rolle. Hauptsache der entsprechende Hostname steht auf dem Zertifikat und die Sperrlisten sind erreichbar.
Use existing certificate for RDP
To assign a new certificate to the Remote Desktop Service, the thumbprint of the new certificate is required. The certificate must be in the computer's certificate store.
The thumbprints of the existing certificates can be displayed with the following command:
Get-ChildItem -Path cert:/LocalMachine/My
The output then looks something like this:
The thumbprint of the corresponding certificate can now be used to assign the certificate to the Remote Desktop Service:
$TSpath = (Get-WmiObject -Class "Win32_TSGeneralSetting" -Namespace root\cimv2\terminalservices -Filter "TerminalName='RDP-tcp'").__path Set-WmiInstance -Path $TSpath -Argument @{SSLCertificateSHA1Hash="5C526C2AB97D100249B411EA11566D55846B5ED3"}
With the two commands above, only the thumbprint needs to be exchanged accordingly. The output should look like this:
Note: The PowerShell must be run as an administrator.
That was all. The new certificate is used for the next RDP connection and the certificate warning has disappeared.
Use standard certificate for RDP
The change can also be reversed by simply reassigning the old self-signed certificate.
Das Standardzertifikat wird im Zertifikatsspeicher des Computers im Ordner „Remote Desktop“ gespeichert. Mit dem folgenden Befehl kann der Thumbprint ermittelt werden:
Get-ChildItem -Path "cert:/LocalMachine/Remote Desktop"
Now the original certificate can be assigned again (replace thumbprint in the second command):
$TSpath = (Get-WmiObject -Class "Win32_TSGeneralSetting" -Namespace root\cimv2\terminalservices -Filter "TerminalName='RDP-tcp'").__path Set-WmiInstance -Path $TSpath -Argument @{SSLCertificateSHA1Hash="7E3044CDB0E5CF038D421E3E001F8DFE632E4A1D"}
The original certificate is used again for the next RDP connection.