Help us improve the AWS re:Post Knowledge Center by sharing your feedback in a brief survey. Your input can influence how we create and update our content to better support your AWS journey.
How do I troubleshoot authentication errors that occur when I use RDP to connect to an Amazon EC2 Windows instance?
I receive authentication errors when I use Remote Desktop Protocol (RDP) to log in to my Amazon Elastic Compute Cloud (Amazon EC2) Windows instance.
Short description
You might receive the following authentication errors when you use RDP to log in to an EC2 Windows instance:
"An authentication error has occurred. The Local Security Authority cannot be contacted."
"The remote computer that you are trying to connect to requires Network Level Authentication (NLA), but your Windows domain controller cannot be contacted to perform NLA. If you are an administrator on the remote computer, you can disable NLA by using the options on the Remote tab of the System Properties dialog box."
These errors occur for the following reasons:
- The trust relationship between your domain and the instance that's joined to the domain failed during the RDP login.
- The instance is domain-joined, but can't reach the domain controller.
- The Secure Channel or Netlogon service on the domain-joined instance is broken.
- You activated Network Layer Authentication (NLA) for the server.
Resolution
Run the AWSSupport-Troubleshoot runbook
Prerequisites:
- Make sure that the instance has an AWS Identity and Access Management (IAM) instance profile role with the AmazonSSMManagedInstanceCore Amazon managed policy attached.
- Verify that your current IAM user or role has the required permissions. For more information, see Required IAM permissions on AWSSupport-TroubleshootRDP.
Note: If you choose the AllowOffline option, then the runbook uses the AWSSupport-ExecuteEC2Rescue runbook to fix issues offline. To start the AWSSupport-ExecuteEC2REscue runbook, your IAM role or user must have the AmazonSSMAutomationRole IAM managed policy.
To automatically resolve configuration issues at the operating system (OS) level, run the AWSSupport-TroubleshootRDP runbook.
Troubleshoot trust relationship failure during RDP login
If the trust relationship fails, then use the cached user credentials to log in to the unreachable instance. When you use cached credentials, you avoid domain controller authentication and can gain access to the instance. If you can't use cached credentials, then proceed to Troubleshoot domain-joined instances.
Prerequisites:
- At least one domain AWS account must have been logged in when the instance communicated with the domain controller.
Note: It's a best practice to use a local account. - You must have a local account that can successfully authenticate to the instance.
- If the domain controller isn't available, then make sure that Interactive logon: Number of previous logons to cache (in case domain controller is not available) is set to at least 1. For more information, see Interactive logon: Number of previous logons to cache (in case domain controller is not available) on the Microsoft website.
Note: You can set the policy to the default value of 10. By default, the policy isn't defined and you can use the server's local policy.
To use cached user credentials to log in, complete the following steps:
- Open the Amazon EC2 console.
- In the navigation pane, choose Security groups.
- Choose Create security group.
- Add a security group name and description.
- Under Inbound rules, choose Add rule.
- For Type, select RDP. Then, enter information for the source that you connect from.
- Under Outbound rules, remove all outbound access.
- Choose Create security group.
- In the navigation pane, choose Instances, and then choose the unreachable instance.
- Choose Actions, and then select Security.
- Choose Change security groups.
- Remove the existing security groups, and then add the security group that you created.
- Use RDP to connect to the instance with the domain account.
Note: Because you removed outbound access from Amazon EC2, RDP uses the cached credentials that are stored on the server. After you log in, you can change the security group settings back to the original state. - Troubleshoot issues with the Windows instance.
Troubleshoot domain-joined instances
Verify that the instance can reach the domain controller
Complete the following steps to use Fleet Manager, a capability of AWS Systems Manager, to check your instance:
- Open the AWS Systems Manager console.
- In the navigation pane, choose Fleet Manager.
- Choose your managed instance.
- In the Node actions menu, select Start terminal session.
- Run the following command to test connectivity to the domain controller:
If the command fails or returns errors, then the instance can't reach the domain controller. To resolve this issue, check the instance's security group and network access control list (network ACL). Make sure that they allow outbound traffic on ports 88 (Kerberos), 389 (LDAP), 445 (SMB), and 49152–65535 (RPC dynamic ports) to the domain controller.nltest /dsgetdc:your-domain-name - Run the following command to confirm that the domain controller is running and reachable from the instance's virtual private cloud (VPC) subnet:
Note: Replace IP-address-computer-name with the domain controller's IP address or computer name and port-example with the instance's port.Test-NetConnection IP address-computer-name -Port port-example -InformationLevel "Detailed" - Run the following command in the terminal session to verify that the instance's DNS settings point to the domain controller's IP address:
ipconfig /all
If the DNS settings don't point to the domain controller's IP address or DNS server, then complete the following steps to update the settings:
- Choose the Start menu, and then open Control Panel.
- Choose Network and Internet, and then choose Network and Sharing Center.
- Choose Change adapter settings.
- Open the context (right-click) menu for your network adaptor, and then select Properties.
- Choose Internet Protocol Version 4 (TCP/IPv4), and then choose Properties.
- Select Use the following DNS server addresses, and then enter your domain controller's IP address.
- Choose Ok.
Repair the Secure Channel for domain-joined instances
Complete the following steps:
-
Open the Systems Manager console.
-
In the navigation pane, choose Fleet Manager.
-
Choose your managed instance.
-
In the Node actions menu, select Start terminal session.
-
Run the following Windows PowerShell command to test the Secure Channel:
Test-ComputerSecureChannel -Verbose -
If the Secure Channel is broken, then run the following command to repair it:
Test-ComputerSecureChannel -Repair -Credential (Get-Credential)Note: When prompted, enter the credentials of a domain administrator account.
-
Wait for the repair to complete.
If you still encounter Secure Channel issues, then see Secure channel problems detected on the Microsoft website.
Troubleshoot Netlogon service issues
To troubleshoot Netlogon service issues, see The Netlogon service doesn't start and event IDs 2114 and 7024 are logged on the Microsoft website.
Reset the computer's account password for domain-joined instances
If you still encounter issues after you repaired the Secure Channel, then complete the following steps to reset your computer's account password:
- Log in to a domain controller, or to another domain-joined machine with domain administrator credentials.
- Run the following Windows PowerShell command:
Note: Replace InstanceComputerName with the name of the instance.Reset-ComputerMachinePassword -Server DomainControllerName -Credential (Get-Credential)
-or-
Run the following Netdom command:
Note: Replace DomainControllerName with your domain controller name and DOMAIN\AdminUser with your user account.netdom resetpwd /server:DomainControllerName /userd:DOMAIN\AdminUser /passwordd:* - When prompted, update the instance password.
- Stop and start the instance.
Deactivate NLA for the server
NLA errors occur if an instance loses connectivity to a domain controller because the domain or network credentials aren't authenticated. If you completed the troubleshooting steps and still encounter NLA issues, then use one of the following methods to deactivate NLA on the unreachable instance.
Note: You must change the registry when you change the NLA. Before you start, create an Amazon Machine Image (AMI) of your instance to use as a backup. If you receive an "Internal error" error message after you deactivate NLA, then see Resolve the "Internal errors" issue
Use Session Manager to connect to your instance and deactivate NLA
Prerequisites:
- Make sure that your configuration adheres to the prerequisites for Session Manager, a capability of AWS Systems Manager.
- Make sure that the instance has an IAM role with the required Session Manager permissions.
Complete the following steps:
- Open the Systems Manager console.
- In the navigation pane, choose Fleet Manager.
- Choose your managed instance.
- In the Node actions menu, select Start terminal session.
- Run the following commands in the terminal session to deactivate NLA:
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v SecurityLayer /t REG_DWORD /d 0 /f reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v UserAuthentication /t REG_DWORD /d 0 /f reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v fAllowSecProtocolNegotiation /t REG_DWORD /d 0 /f
Or, to deactivate NLA with the aws:runPowerShellscript in Run Command, a capability of AWS Systems Manager, complete the following steps:
-
Open the Systems Manager console.
-
In the navigation pane, choose Run Command, and then choose Run a Command.
-
For Command document, search for and select AWS-RunPowerShellScript.
-
For Command parameters, enter the following commands:
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v SecurityLayer /t REG_DWORD /d 0 /f reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v UserAuthentication /t REG_DWORD /d 0 /f reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v fAllowSecProtocolNegotiation /t REG_DWORD /d 0 /f -
For Target selection, select Choose instances manually, and then select your instance.
-
Choose Run.
-
Wait until the Overall status is Success. Then, stop and start the instance.
Manually change the registry offline
Complete the following steps:
-
Launch a rescue instance in the same Availability Zone as the unreachable instance.
Important: To avoid disk signature issues, it's a best practice to launch a Windows instance that uses a different OS version than the unreachable instance. -
Attach the root volume to the rescue instance as /dev/xvdf.
-
Choose the Start menu, and then open Disk Manager.
-
Open the context (right-click) menu for the root volume, and then select Online.
-
In a command prompt, run the following command to open the Registry Editor:
regedit.exe -
Choose HKEY_LOCAL_MACHINE, and then choose File.
-
Choose Load Hive, and then navigate to the Windows folder for the volume. The default path is D:\Windows\System32\config.
-
Choose the SYSTEM file, and then name it. For example, name the file badsys.
-
The badsys system file now appears under HKEY_LOCAL_MACHINE. Under badsys, choose ControlSet001.
-
Navigate to Control\Terminal Server\WinStations\RDP-Tcp, and then choose the key.
-
Double-click SecurityLayer, and then set the value to 0.
-
Choose UserAuthentication, and then set the value to 0.
-
Choose AllowSecProtocolNegotiation, and then set the value data to 0.
-
Repeat steps 11-16 for ControlSet002, Terminal Server, WinStations, and RDP-Tcp.
-
Choose badsys, and then choose File.
-
Choose Unload Hive.
-
After the hive unloads, unmount and detach the volume from the rescue instance.
-
Attach the volume to the original instance as the /dev/sda1 root volume.
Resolve the "Internal errors" issue
If you receive an "Internal error" error message after you deactivate NLA, then you must fix the RSA MachineKeys permissions. Use Session Manager or RDP with local credentials to connect to the instance. Then, run the following Windows PowerShell commands as an administrator:
Get-ChildItem C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys | ForEach-Object {icacls C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys\$_ /grant system:F} Get-ChildItem C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys | ForEach-Object {icacls C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys\$_ /grant NetworkService:R} Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" -Name fAllowSecProtocolNegotiation -Value 1 -Force Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" -Name UserAuthentication -Value 1 -Force Restart-Service TermService -Force
Unjoin and rejoin the domain
If you still encounter issues, then complete the following steps to unjoin and rejoin the domain:
-
Use Session Manager or a local administrator account to log in to the instance.
-
Run the following Windows PowerShell command to remove the instance from the domain:
Remove-Computer -UnjoinDomainCredential (Get-Credential) -PassThru -Verbose -Restart -
After the instance restarts, log in with a local administrator account.
-
Run the following Windows PowerShell command to rejoin the domain:
Add-Computer -DomainName your-domain-name -Credential (Get-Credential) -Restart -
After the instance restarts, use RDP to log in to the instance with domain credentials.
Note: When you unjoin and rejoin the domain, the instance gets a new machine account in Active Directory. Make sure to apply Group Policy Objects (GPOs) or domain-based configurations to the rejoined instance.
Troubleshoot further
If you still can't connect to the instance, then see How do I troubleshoot RDP connection issues with my EC2 Windows instance?
- Language
- English
Related videos


reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v SecurityLayer /t REG_DWORD /d 0 /f reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v UserAuthentication /t REG_DWORD /d 0 /f reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v fAllowSecProtocolNegotiation /t REG_DWORD /d 0 /f this section of code was not working sometime on 2022 addition .
Hello, I found out the formatting of the commands on this page is messed up. There should be 3 lines of commands. Now it's showing only two lines, and the commands are squeezed together.
Relevant content
- asked 2 years ago
- asked 3 years ago
- asked 3 years ago
- asked 3 years ago
- asked 2 years ago