EN

Windows Server

Unlock a locked account and secure RDP

Unlock a Windows Server account locked by an RDP attack, then curb brute-force attempts with IP filtering, a lockout policy, NLA, dedicated accounts and WireGuard VPN access.

11 min read, updated on 18 November 2026

On this page

Your values

Enter them once and the commands in this guide update.

A Windows server exposed to the Internet quickly starts receiving automated login attempts on the Remote Desktop port (RDP, TCP 3389 by default). When a lockout policy is active, these attempts end up locking your own account.

This guide helps you regain access, see where the attempts come from, and then shut the bots out. Do not stop once the account is unlocked: until the traffic is filtered, it can be locked again a few minutes later.

Prerequisites

  • A server running Windows Server 2019, 2022 or 2025
  • An account that belongs to the Administrators group
  • The public IP address of the computer you connect from
  • A fallback access method that does not depend on RDP:
    • on a VPS, the VNC console in your management interface, described in the Windows Installation guide
    • on a dedicated server without a remote console, contact support from your customer area before changing the firewall

Run the commands in this guide in Windows PowerShell as administrator.

Recognize a lockout

The Remote Desktop client displays one of these messages, in English or in French depending on your computer:

  • As a security precaution, the user account has been locked because there were too many logon attempts or password change attempts.
  • The referenced account is currently locked out and may not be logged on to.

The password is not necessarily the problem: the account refuses all network connections for as long as the lockout lasts, even with the correct password.

Step 1: Regain access

Use the first option available to you:

  1. Wait for the lockout period to end. If it is 10 minutes, the account unlocks on its own, but the bots can lock it again immediately.
  2. Use another administrator account over RDP, if you have one.
  3. Open the VNC console of the VPS and sign in with the built-in administrator account (Administrator, though the name can differ on a localized Windows). According to Microsoft, lockout of this account only affects network connections such as RDP: signing in at the console is still allowed.
  4. Contact support from your customer area if you have none of these options.

Unlock the account

Using the graphical interface:

  1. Run lusrmgr.msc.
  2. Open Users, then double-click the account.
  3. Clear Account is locked out.
  4. Confirm with OK.

Using PowerShell:

PowerShell
# Show the status of local accounts
Get-CimInstance Win32_UserAccount -Filter "LocalAccount=True" |
  Select-Object Name, Lockout, Disabled

# Unlock an account
Get-CimInstance Win32_UserAccount -Filter "LocalAccount=True AND Name='YOUR_USER'" |
  Set-CimInstance -Property @{ Lockout = $false }

Run the first command again: the Lockout column should show False.

Step 2: Measure the attack and confirm it failed

List the addresses and accounts targeted over the last 24 hours:

PowerShell
$since = (Get-Date).AddHours(-24)
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625; StartTime = $since } -MaxEvents 5000 -ErrorAction SilentlyContinue |
  ForEach-Object {
    $data = ([xml]$_.ToXml()).Event.EventData.Data
    [pscustomobject]@{
      Ip      = ($data | Where-Object { $_.GetAttribute('Name') -eq 'IpAddress' }).InnerText
      Account = ($data | Where-Object { $_.GetAttribute('Name') -eq 'TargetUserName' }).InnerText
    }
  } |
  Group-Object Ip, Account |
  Sort-Object Count -Descending |
  Select-Object -First 20 Count, Name

Event 4625 is a failed logon. The address can appear as - when the failure occurs during network authentication. In that case, also check the Microsoft-Windows-RemoteDesktopServices-RdpCoreTS/Operational log in Event Viewer.

Above all, check successful Remote Desktop connections (event 4624, logon type 10):

PowerShell
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4624; StartTime = (Get-Date).AddDays(-7) } -MaxEvents 5000 -ErrorAction SilentlyContinue |
  ForEach-Object {
    $data = ([xml]$_.ToXml()).Event.EventData.Data
    $field = { param($n) ($data | Where-Object { $_.GetAttribute('Name') -eq $n }).InnerText }
    if ((& $field 'LogonType') -eq '10') {
      [pscustomobject]@{
        Time    = $_.TimeCreated
        Account = & $field 'TargetUserName'
        Ip      = & $field 'IpAddress'
      }
    }
  }

Lockouts themselves are recorded as event 4740:

PowerShell
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4740 } -MaxEvents 20 -ErrorAction SilentlyContinue |
  Format-List TimeCreated, Message

Then change the password of the targeted account. The following command prompts for it without displaying it:

PowerShell
net user YOUR_USER *

Choose a long, unique password, ideally generated by a password manager. The Change a user password guide covers this in detail.

Step 3: Restrict RDP to your IP address

This is the most effective measure: bots can no longer reach the service, so they can no longer lock your accounts.

Prepare an automatic rollback

Find the RDP port and the address you are connected from:

PowerShell
$port = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp').PortNumber
$port
Get-NetTCPConnection -LocalPort $port -State Established | Select-Object RemoteAddress

Then schedule a task that will reopen RDP in 15 minutes if you lose access:

PowerShell
$cmd = "Get-NetFirewallPortFilter | Where-Object { `$_.LocalPort -contains '$port' } | Get-NetFirewallRule | Where-Object { `$_.Direction -eq 'Inbound' -and `$_.Action -eq 'Allow' } | Set-NetFirewallRule -RemoteAddress Any"
$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-NoProfile -NonInteractive -Command `"$cmd`""
$trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(15)
$principal = New-ScheduledTaskPrincipal -UserId 'S-1-5-18' -LogonType ServiceAccount -RunLevel Highest
Register-ScheduledTask -TaskName 'RDP-Rollback' -Action $action -Trigger $trigger -Principal $principal -Force

Apply the filter

Using the graphical interface:

  1. Run wf.msc, then open Inbound Rules.
  2. Open the Remote Desktop - User Mode (TCP-In) rule.
  3. On the Scope tab, under Remote IP address, choose These IP addresses, then add your address.
  4. Repeat for the UDP-In rule.

The Firewall configuration guide introduces this console.

Using PowerShell, in the same window as $port:

PowerShell
Get-NetFirewallPortFilter |
  Where-Object { $_.LocalPort -contains "$port" } |
  Get-NetFirewallRule |
  Where-Object { $_.Direction -eq 'Inbound' -and $_.Action -eq 'Allow' } |
  Set-NetFirewallRule -RemoteAddress 'YOUR_IP'

To allow several sources, pass a list: -RemoteAddress 'YOUR_IP','198.51.100.0/24'.

Validate, then remove the task

Open a new RDP connection from your computer. If it works, remove the rollback:

PowerShell
Unregister-ScheduledTask -TaskName 'RDP-Rollback' -Confirm:$false

If it does not, leave everything as it is: the task will reopen access at the scheduled time. Then correct the address and start again.

Step 4: Configure account lockout

Lockout slows down password guessing, but it also lets a third party block an account whose name they know. That is why it complements filtering rather than replacing it.

Microsoft cites 10 attempts, a 10-minute lockout and 10 minutes before the counter resets as a baseline.

Using the graphical interface:

  1. Run secpol.msc.
  2. Open Account Policies, then Account Lockout Policy.
  3. Set the values:
Policy What it controls Suggested value
Account lockout threshold Failed attempts allowed before the account locks 10
Account lockout duration How long the account stays locked 10 minutes
Reset account lockout counter after Time before the failed-attempt counter returns to zero 10 minutes

Using PowerShell:

PowerShell
net accounts /lockoutthreshold:10 /lockoutduration:10 /lockoutwindow:10
net accounts

The second command displays the active values. Avoid a duration of 0, which requires an administrator to unlock the account manually.

Include the Administrator account

The built-in administrator account was long exempt from lockout, which allowed unlimited attempts over RDP. Cumulative updates released from October 11, 2022 onward add the Allow Administrator account lockout policy, in the same location in secpol.msc. Enable it if it is available on your version of Windows.

Once it is enabled, the account can be locked out for network connections, and the console remains usable.

Step 5: Require Network Level Authentication (NLA)

With Network Level Authentication, users must authenticate before a remote session is opened. The server therefore spends fewer resources on unauthenticated connections.

Using the graphical interface:

  1. Run SystemPropertiesRemote.exe.
  2. Under Remote Desktop, check Allow connections only from computers running Remote Desktop with Network Level Authentication.
  3. Confirm with OK.

Using PowerShell:

PowerShell
$ts = Get-CimInstance -Namespace root/CIMV2/TerminalServices -ClassName Win32_TSGeneralSetting -Filter "TerminalName='RDP-Tcp'"
Invoke-CimMethod -InputObject $ts -MethodName SetUserAuthenticationRequired -Arguments @{ UserAuthenticationRequired = [uint32]1 }

# Check: the expected value is 1
(Get-CimInstance -Namespace root/CIMV2/TerminalServices -ClassName Win32_TSGeneralSetting -Filter "TerminalName='RDP-Tcp'").UserAuthenticationRequired

Then test a new connection. An account whose password has expired or must be changed may be refused with NLA: sort this out from the console.

Step 6: Use a dedicated administration account

Bots try the name Administrator first. An account with a less predictable name makes these attempts less useful.

Using the graphical interface, create the user in lusrmgr.msc, then add it to the Administrators group. In PowerShell, using the SID avoids depending on the Windows language:

PowerShell
$password = Read-Host 'Password' -AsSecureString
New-LocalUser -Name 'YOUR_USER' -Password $password -PasswordNeverExpires
Add-LocalGroupMember -SID 'S-1-5-32-544' -Member 'YOUR_USER'

Check that this account can connect over RDP. You can then deny RDP to the built-in account:

  1. In secpol.msc, open Local Policies, then User Rights Assignment.
  2. Open Deny log on through Remote Desktop Services.
  3. Add the built-in administrator account.

Changing the RDP port reduces noise in the logs, but a port scan will still find it: do not treat it as protection.

Step 7: Restrict RDP to a VPN

With a dynamic IP address or several administrators, a VPN saves you from maintaining a list of addresses. The firewall then only accepts RDP from the tunnel network. This example uses WireGuard, whose Windows client supports Windows Server 2019, 2022 and 2025. Only the VPN's UDP port stays open to the Internet.

Item Server Your computer
Tunnel address 10.66.66.1/24 10.66.66.2/24
UDP port 51820 no port to open

If this network is already in use on your side, choose another private range.

Install and configure the tunnel

  1. Install WireGuard on the server and on your computer with the official wireguard-installer.exe installer.
  2. On each machine, open WireGuard, then choose Add Tunnel and Add empty tunnel. The application generates the private key and displays the public key.
  3. Name the tunnel wg0 on the server and complete its configuration, keeping the generated PrivateKey line and entering the other machine's public key:
Configuration
[Interface]
PrivateKey = GENERATED_PRIVATE_KEY
Address = 10.66.66.1/24
ListenPort = 51820

[Peer]
PublicKey = CLIENT_PUBLIC_KEY
AllowedIPs = 10.66.66.2/32
  1. On your computer, complete the tunnel:
Configuration
[Interface]
PrivateKey = GENERATED_PRIVATE_KEY
Address = 10.66.66.2/24

[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = YOUR_SERVER_IP:51820
AllowedIPs = 10.66.66.1/32
PersistentKeepalive = 25

With AllowedIPs limited to 10.66.66.1/32, only traffic destined for the server goes through the tunnel: your browsing is unaffected.

Open the port and activate the tunnel

On the server:

PowerShell
New-NetFirewallRule -DisplayName 'WireGuard-In' -Direction Inbound -Protocol UDP -LocalPort 51820 -Action Allow

Activate the tunnel in the application on both machines, then make sure it starts automatically on the server:

PowerShell
Set-Service -Name 'WireGuardTunnel$wg0' -StartupType Automatic
Get-Service -Name 'WireGuardTunnel$wg0'

Allow the tunnel network

VPN traffic arrives from 10.66.66.2, an address that the filter from step 3 still rejects. In a single PowerShell window, run both blocks from Prepare an automatic rollback (step 3) again: they set $port and schedule RDP-Rollback. Then allow your current address and the tunnel:

PowerShell
Get-NetFirewallPortFilter |
  Where-Object { $_.LocalPort -contains "$port" } |
  Get-NetFirewallRule |
  Where-Object { $_.Direction -eq 'Inbound' -and $_.Action -eq 'Allow' } |
  Set-NetFirewallRule -RemoteAddress 'YOUR_IP','10.66.66.0/24'

From your computer, without closing your current session, test the port, adjusting 3389 if you changed the RDP port:

PowerShell
Test-NetConnection 10.66.66.1 -Port 3389

Then open a Remote Desktop connection to 10.66.66.1.

Restrict RDP to the tunnel

Once this connection works, remove your public address in the same PowerShell window. If the 15 minutes of RDP-Rollback have run out, schedule the task again first:

PowerShell
Get-NetFirewallPortFilter |
  Where-Object { $_.LocalPort -contains "$port" } |
  Get-NetFirewallRule |
  Where-Object { $_.Direction -eq 'Inbound' -and $_.Action -eq 'Allow' } |
  Set-NetFirewallRule -RemoteAddress '10.66.66.0/24'

After a new successful connection through 10.66.66.1, remove the RDP-Rollback task.

Check the result

  • net accounts shows the threshold and durations you chose.
  • UserAuthenticationRequired is 1.
  • An RDP connection works from an allowed address or through the VPN.
  • From another network, such as a mobile hotspot, Test-NetConnection YOUR_SERVER_IP -Port 3389 reports TcpTestSucceeded : False (adjust the port if you changed it).
  • The number of new 4625 events drops sharply.
PowerShell
(Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625; StartTime = (Get-Date).AddHours(-1) } -ErrorAction SilentlyContinue | Measure-Object).Count

Troubleshooting

I can no longer connect after filtering

Wait for RDP-Rollback to run, or open the VNC console and run:

PowerShell
$port = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp').PortNumber
Get-NetFirewallPortFilter |
  Where-Object { $_.LocalPort -contains "$port" } |
  Get-NetFirewallRule |
  Where-Object { $_.Direction -eq 'Inbound' -and $_.Action -eq 'Allow' } |
  Set-NetFirewallRule -RemoteAddress Any

Then check your current public address, including over IPv6, and apply the filter again.

The account still gets locked after filtering

An application or task may be using an old password. Run the 4625 query from step 2 again, look at the Caller Computer Name field of event 4740 and the Process Name field of event 4625, then check the services, scheduled tasks and saved credentials on your computers.

The port is still reachable from an unauthorized address

Another rule is probably allowing the traffic, such as a rule with no specific port. List the active inbound rules and their remote addresses:

PowerShell
Get-NetFirewallRule -Direction Inbound -Enabled True -Action Allow |
  ForEach-Object {
    $p = $_ | Get-NetFirewallPortFilter
    $a = $_ | Get-NetFirewallAddressFilter
    [pscustomobject]@{ Name = $_.DisplayName; Protocol = $p.Protocol; Port = ($p.LocalPort -join ','); Remote = ($a.RemoteAddress -join ',') }
  } |
  Where-Object { $_.Port -eq 'Any' -or $_.Port -split ',' -contains '3389' }

Adjust 3389 if your RDP port is different.

The remote computer requires NLA

The message The remote computer requires Network Level Authentication means the client cannot perform it. Update Windows and the Remote Desktop client on your computer. Only disable NLA temporarily, from the console, while you fix the computer.

"CredSSP encryption oracle remediation" error

The client and the server are not at the same CredSSP patch level. Install Windows updates on both machines. Use the console if the server is the one that is out of date.

The WireGuard tunnel does not come up

In the application, the Latest handshake line should update. If it stays empty:

  • check that each machine has the other's public key
  • check Endpoint, UDP port 51820 and the WireGuard-In rule
  • make sure the clocks on both machines are correct

If the handshake works but RDP fails, check that the RDP rules accept 10.66.66.0/24 on the network profile of the wg0 interface, shown by Get-NetConnectionProfile.