Error Description
This error occurs when you attempt to connect to the local machine using Windows Remote Management (WinRM) through its loopback address (localhost, 127.0.0.1, or [::1]) without explicitly specifying an authentication mechanism that allows loopback traffic, or when using standard Kerberos authentication.
By default, the WinRM architecture and Kerberos security protocols prevent loopback authentication to protect against credential reflection attacks. Kerberos relies on Service Principal Names (SPNs) linked to active computer accounts; because localhost does not resolve to a unique Active Directory machine account, Kerberos authentication fails. To execute commands locally via WinRM, you must configure the WinRM client to allow the local connection or explicitly use an alternative authentication method like Basic or Negotiate.
Step-by-Step Fixes
Method 1: Use the Computer Name Instead of Localhost
The easiest and most secure workaround is to avoid loopback addresses entirely by targeting your actual machine name.
- Open Command Prompt or PowerShell.
- Find your computer name by running:
hostname - Use that returned hostname instead of
localhostor127.0.0.1in your WinRM or PowerShell Remoting command. For example:Enter-PSSession -ComputerName YOUR COMPUTER NAME
Method 2: Configure WinRM Trusted Hosts
If you must use localhost, you need to tell the WinRM client configuration to explicitly trust connections to it.
- Right-click the Windows Start menu and select Windows PowerShell (Admin) or Terminal (Admin).
- Run the following command to add
localhostto your trusted hosts list:Set-Item WSMan:\localhost\Client\TrustedHosts -Value "localhost" -Force(Note: If you need to allow IP loopbacks too, use
-Value "localhost,127.0.0.1,::1") - Restart the WinRM service to apply changes:
Restart-Service WinRM
Method 3: Change the Authentication Mechanism
If your command allows parameter flags, explicitly switch from Kerberos to Negotiate or Basic authentication, which handles loopback traffic correctly.
- For PowerShell sessions: Add the
-Authenticationparameter to your connection command:Enter-PSSession -ComputerName "localhost" -Authentication Negotiate - For general WinRM utility commands: Specify the authentication type using the
-aswitch:winrm get winrm/config/client -a:Negotiate
Method 4: Enable Local Account Token Filter Policy
If you are running the command as a local administrator account and still face access blocks after applying the steps above, Windows User Account Control (UAC) might be stripping your administrative privileges over the loopback connection.
- Press
Windows Key + R, typeregedit, and press Enter to open the Registry Editor. - Navigate to the following path:
HKEY LOCAL MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System - Right-click an empty space in the right pane, select New -> DWORD (32-bit) Value.
- Name the new value:
LocalAccountTokenFilterPolicy - Double-click
LocalAccountTokenFilterPolicyand change its Value data to1. - Click OK and restart your computer to apply the registry changes.
There may be some errors. Learn Microsoft