The nine settings, in the order to apply them
RDP (Remote Desktop Protocol) is a sign-in prompt that listens on TCP port 3389 by default, and IANA registers that port for TCP and UDP under the service name ms-wbt-server. Anyone who can reach the server's IP address can try to sign in, so the work is to shrink who can reach it, make each attempt harder, and watch the log. Apply the steps below in this order, because the early ones protect you while you change the later ones.
| Step | What it does | Takes about |
|---|---|---|
| 1. Keep a way back in | Console access, so a wrong firewall rule cannot lock you out for good | 2 minutes |
| 2. Network Level Authentication (NLA) | Makes people authenticate before a desktop session is built | 1 minute |
| 3. Strong passwords and account lockout | Slows guessing and locks an account after repeated failures | 5 minutes |
| 4. Replace the name Administrator | Removes the user name every attacker tries first | 5 minutes |
| 5. Allow RDP only from your IP addresses | Stops everyone else reaching the port at all | 5 minutes |
| 6. Change the RDP port (optional) | Moves RDP off the port that scanners check first | 10 minutes |
| 7. VPN, SSH tunnel or RD Gateway | Takes RDP off the open internet completely | Depends on the option |
| 8. Windows updates | Closes known RDP and Windows flaws | One maintenance window |
| 9. Check failed logons (Event ID 4625) | Shows who is guessing and whether the other steps work | 5 minutes |
All commands run in an elevated PowerShell window (right-click PowerShell, Run as administrator) on the server. They are written for Windows Server 2019 and 2022, the versions on our Windows servers, and they also apply to Windows Server 2025.
Step 1: keep a way back in before you change anything
Several steps below edit firewall rules, the RDP port or the accounts that can sign in. One typing mistake can cut off your own RDP session, and you cannot fix a firewall from a session you no longer have. Before you start:
- Find your out-of-band console. A VPS or VDS control panel has a console that reaches the server without RDP. Open it once now and confirm it shows a Windows sign-in screen.
- Know your current public IP address. Open a browser on the PC you connect from and search for "what is my IP". You need this address in Step 5.
- Keep the first RDP session open while you test. A Windows Server allows two administration sessions at once by default (our RDP server page explains the limit), so you can test a new login or a new port in a second session and leave the first one as your safety net.
If a change goes wrong, use the table near the end of this guide, or the longer Remote Desktop can't connect guide.
Step 2: keep Network Level Authentication on
NLA makes the user authenticate before the remote session is set up. Microsoft recommends leaving it enabled whenever possible, and says to turn it off only for older clients that cannot use it. With NLA on, an unauthenticated visitor never reaches the Windows sign-in screen, so a guessing attack costs the server less. Only RDP clients that support protocol version 6.0 or later can connect when it is required.
Check the current setting:
Get-CimInstance -Namespace root/cimv2/terminalservices -ClassName Win32_TSGeneralSetting -Filter "TerminalName='RDP-tcp'" |
Select-Object TerminalName, UserAuthenticationRequired
UserAuthenticationRequired shows 1 when NLA is required and 0 when it is not. If it shows 0, switch it on:
Get-CimInstance -Namespace root/cimv2/terminalservices -ClassName Win32_TSGeneralSetting -Filter "TerminalName='RDP-tcp'" |
Invoke-CimMethod -MethodName SetUserAuthenticationRequired -Arguments @{ UserAuthenticationRequired = 1 }
A ReturnValue of 0 means it worked. In the graphical tools, the same switch is the checkbox "Allow connections only from computers running Remote Desktop with Network Level Authentication" under System Properties, Remote tab. If an old client then fails with a CredSSP or authentication error, update the client first. The RDP troubleshooting guide explains those two errors.
NLA does not stop someone who has a valid password, and it does not hide the port. It is one layer, so continue with the steps below.
Step 3: set strong passwords and an account lockout policy
Every account that can use RDP needs its own long, unique password. A password manager that generates 16 or more random characters is the simplest way to get one. Give each person their own account instead of sharing one login, and remove accounts when people leave. Members of the Administrators group and any users you add to the Remote Desktop Users group can connect over RDP, so add a non-administrator account to that group when the person does not need admin rights:
Add-LocalGroupMember -Group "Remote Desktop Users" -Member "accountant1"
Then limit how many wrong passwords an account accepts. The account lockout threshold is the number of failed sign-ins that lock an account. Microsoft's security baselines recommend 10 as an acceptable starting point, which leaves room for typing mistakes and still stops automated guessing. On a standalone server (not joined to a domain), set it with net accounts:
net accounts /lockoutthreshold:10 /lockoutduration:15 /lockoutwindow:15
net accounts
This locks an account for 15 minutes after 10 failed sign-ins, and counts failures inside a 15-minute window. The lockout duration has to be greater than or equal to the window. The second command prints the current policy so you can confirm the three values. The same settings live in secpol.msc under Account Policies, Account Lockout Policy. If the server is joined to a domain, a domain Group Policy can override a local setting.
Know the trade-off. Microsoft's own page warns that with a lockout threshold in place, an attacker who knows an account name can lock that account by failing on purpose. Microsoft also notes that the built-in Administrator account is excluded from this policy. That is the reason for the next step.
Step 4: replace the name Administrator
Attackers try the user name Administrator first because every Windows server has it, and the lockout policy does not protect it. Create your own administrator account with a name an outsider cannot guess, confirm it works, and then rename or disable the original.
# 1. Create the new admin account (you type the password at the prompt)
$pw = Read-Host -AsSecureString "Password for the new admin"
New-LocalUser -Name "srv-ops" -Password $pw -FullName "Server administrator"
Add-LocalGroupMember -Group "Administrators" -Member "srv-ops"
Now open a second RDP session as srv-ops and confirm it signs in and has admin rights, while your first session stays open. Only then retire the old name. Disabling is the stronger choice:
# Option A: disable the built-in account
Disable-LocalUser -Name "Administrator"
# Option B: keep it but rename it
Rename-LocalUser -Name "Administrator" -NewName "srv-old-admin"
# Check the result
Get-LocalUser | Select-Object Name, Enabled
Replace srv-ops with a name of your own. Before you disable the original account, check that no service, scheduled task or application on the server runs as Administrator, because those stop working when it is disabled. On Windows VDS servers the Administrator password is handed to you, so this change is yours to make.
Step 5: allow RDP only from your IP addresses
This is the step with the biggest effect. Windows Defender Firewall blocks incoming traffic unless it was requested or matches a rule, and a rule can filter by source IP address and port. If the rule for RDP lists only your office and home addresses, nobody else can send a single packet to the RDP port, so they cannot guess passwords, and the failed-logon log stays quiet.
Windows ships with built-in rules in the display group "Remote Desktop". List them first:
Get-NetFirewallRule -DisplayGroup "Remote Desktop" | Format-Table Name, DisplayName, Enabled, Direction
Then limit them to your addresses. -RemoteAddress accepts single addresses, CIDR ranges and address ranges, separated by commas. The addresses below are documentation examples; use your own public IP from Step 1:
Set-NetFirewallRule -DisplayGroup "Remote Desktop" -RemoteAddress 203.0.113.10,198.51.100.0/24
# Verify what each rule now allows
Get-NetFirewallRule -DisplayGroup "Remote Desktop" | Get-NetFirewallAddressFilter | Format-Table InstanceID, RemoteAddress
If you prefer the graphical route, run wf.msc, open Inbound Rules, double-click "Remote Desktop - User Mode (TCP-In)", open the Scope tab, choose "These IP addresses" under Remote IP address, add your addresses, and repeat for the UDP rule.
Test it from both sides. From an allowed network, the port should answer. From a network that is not on the list, for example a laptop tethered to a phone on mobile data, it should time out:
Test-NetConnection -ComputerName YOUR.SERVER.IP -Port 3389
TcpTestSucceeded : True from an allowed address and False from any other address is the result you want. Three points catch people out:
- Allow rules add up. Windows Firewall lets a packet in if any enabled allow rule matches it. A second, broader rule for the same port, such as one you created earlier, keeps the port open to everyone. Disable it or give it the same scope.
- The provider firewall is separate. A VPS platform can filter traffic before it reaches Windows. The rule there needs your IP too, and a rule in only one of the two places gives you a timeout.
- Your address has to stay put. If your internet connection changes its public IP, the rule no longer matches you. Use the console to add the new address, or use Step 7 so the allowed address is a VPN or a fixed office connection. Widening the rule to a whole range makes the allowlist weaker, so keep ranges as small as you can.
Step 6: change the RDP port, and know what it does not do
Moving RDP from 3389 to another port makes the server miss the scans that check only the default port, so the log shows fewer attempts. It adds no authentication and no encryption. A scan that checks all 65,535 ports finds the new port, so treat this step as noise reduction on top of Steps 2 to 5, never as a replacement for them. It also has a cost: every firewall (Windows and provider), saved RDP connection and script that uses 3389 has to change with it. Skip this step if you are not sure you can reach the console.
Microsoft's documented method is a registry value plus a firewall rule. Pick an unused port, add the firewall rule first, then change the port, then restart:
# Choose a port and check that nothing is already using it (no output means it is free)
$portValue = 50389
Get-NetTCPConnection -LocalPort $portValue -ErrorAction SilentlyContinue
# 1. Allow the new port, from your IP addresses only
New-NetFirewallRule -DisplayName 'RDP-Custom-TCP-In' -Direction Inbound -Action Allow -Protocol TCP -LocalPort $portValue -RemoteAddress 203.0.113.10
New-NetFirewallRule -DisplayName 'RDP-Custom-UDP-In' -Direction Inbound -Action Allow -Protocol UDP -LocalPort $portValue -RemoteAddress 203.0.113.10
# 2. Check the current value, then change it
Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name 'PortNumber'
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name 'PortNumber' -Value $portValue
# 3. Restart, as Microsoft's steps say
Restart-Computer
Add the same port in the provider firewall in the control panel before you restart. After the restart, connect to YOUR.SERVER.IP:50389 in Remote Desktop Connection, or run mstsc /v:YOUR.SERVER.IP:50389. Confirm that the server listens on the new port:
Get-NetTCPConnection -LocalPort 50389 -State Listen
Once a second session connects on the new port, close the old one by disabling the built-in rules, which are tied to port 3389:
Disable-NetFirewallRule -DisplayGroup "Remote Desktop"
If you ever need to undo it, set PortNumber back to 3389, enable the group again with Enable-NetFirewallRule -DisplayGroup "Remote Desktop" and restart.
Step 7: put RDP behind a VPN, an SSH tunnel or RD Gateway
An IP allowlist works when your addresses stay the same. When they do not, or when several people connect from different places, take the RDP port off the internet and put something in front of it. Microsoft's page on enabling Remote Desktop says that to connect from outside a network you can use port forwarding or set up a VPN. A VPN does not leave the RDP port open to the internet.
| Option | How it protects RDP | Fits when | What it needs |
|---|---|---|---|
| IP allowlist (Step 5) | Only listed addresses can reach the port | You connect from fixed office or home addresses | One firewall rule, in Windows and in the provider firewall |
| VPN | You join a private network first, and the RDP rule allows only the VPN address range | Several people, changing addresses, or other services on the same server | A VPN server you run or rent, and a client on every PC. Use multi-factor authentication where the VPN supports it |
| SSH tunnel | RDP travels inside an SSH connection, so the RDP port is not exposed to the internet | One or two administrators who already use SSH keys | An SSH server on the Windows VPS (OpenSSH Server is an optional Windows feature) and keys. See the SSH tunnel guide |
| RD Gateway | A Windows role that carries RDP over HTTPS on port 443 and checks authorisation policies before it forwards you to a server | A team that reaches several Windows servers | The RD Gateway role, a TLS certificate and policies. Check licensing when more than two people use the server |
Microsoft's description of the gateway says it uses RDP over HTTPS, sends the traffic to port 443 instead of 3389, and lets you set who can connect and to which computers. To add the role on a Windows Server:
Install-WindowsFeature RDS-Gateway -IncludeManagementTools
The role is only the first part. You still create a certificate and the authorisation policies in RD Gateway Manager. For one server and one or two administrators, the allowlist, a VPN or an SSH tunnel is less work than a gateway.
Step 8: keep Windows updated
RDP is part of Windows, so it is patched through Windows Update like everything else. Install updates on a schedule instead of leaving them for months, take a snapshot before a large update so you can roll back, and restart when the update asks for it. Open Settings, then Windows Update (Update and Security on Server 2019 and 2022), and choose Check for updates. To see what is installed, newest first:
Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 5 Description, HotFixID, InstalledOn
Both Windows Server 2019 and 2022 are inside Microsoft's extended support window, which ends in January 2029 for 2019 and October 2031 for 2022, as our Windows VPS guide sets out. Updates still arrive for both, but a new server is better placed on 2022.
Step 9: check failed logons (Event ID 4625)
Windows records every failed sign-in as Event ID 4625, "An account failed to log on", in the Security log. This is how you see whether anyone is guessing passwords and whether Steps 3 to 5 are working. First confirm that Logon auditing records failures:
auditpol /get /subcategory:"Logon"
# If Failure is not listed, turn it on
auditpol /set /subcategory:"Logon" /success:enable /failure:enable
Then read the last day of failures. This needs an elevated window, because the Security log is restricted to administrators. If the command reports that no events were found, there were no failed logons in that period:
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625; StartTime = (Get-Date).AddDays(-1) } -MaxEvents 5 |
Format-List TimeCreated, Message
To count the attempts by source address, which is the quickest way to spot guessing:
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625; StartTime = (Get-Date).AddDays(-1) } |
ForEach-Object {
$x = [xml]$_.ToXml()
($x.Event.EventData.Data | Where-Object Name -eq 'IpAddress').'#text'
} | Group-Object | Sort-Object Count -Descending | Select-Object Count, Name -First 10
In Event Viewer (eventvwr.msc), the same events are under Windows Logs, Security, then Filter Current Log. Four fields tell you what happened:
| Field | What to look at |
|---|---|
| Account For Which Logon Failed, Account Name | The user name that was tried. Names such as Administrator, admin or user that you never created point to guessing |
| Network Information, Source Network Address | The address the attempt came from. 127.0.0.1 or ::1 means the attempt came from the server itself |
| Logon Type | 10 is RemoteInteractive, a Remote Desktop sign-in. With NLA on, a failed attempt can be logged as type 3 (Network), because the check happens before the session exists |
| Status and Sub Status | 0xC000006A wrong password for a real account. 0xC0000064 the user name does not exist. 0xC0000234 the account is locked out. 0xC0000072 the account is disabled. 0xC000015B the user is not allowed this logon type, for example a user missing from Remote Desktop Users |
Microsoft notes that several 0xC0000064 events in a row can be a sign of a user-name enumeration attack, and that repeated 0xC000006A events against a real account are worth watching. What to do with what you find:
- Failures from many different addresses and names. The RDP port is reachable from the internet. Apply Step 5 first and look at the log again a day later; the count should fall close to zero.
- Failures against the disabled Administrator name. Expected, and it proves Step 4 is doing its job. Status
0xC0000072is the account being refused. - Failures from your own address. A mistyped password or an old saved credential in Remote Desktop Connection. Clear the saved one and sign in again.
- A single address that keeps coming back. A block rule works for one address:
New-NetFirewallRule -DisplayName "Block 198.51.100.7" -Direction Inbound -Action Block -RemoteAddress 198.51.100.7. A block list is no substitute for the allowlist, because a new address appears when you block one.
Check that everything is in place
| Check | Command | Expected result |
|---|---|---|
| NLA is required | Get-CimInstance -Namespace root/cimv2/terminalservices -ClassName Win32_TSGeneralSetting -Filter "TerminalName='RDP-tcp'" | Select-Object UserAuthenticationRequired | 1 |
| Lockout policy is set | net accounts | Lockout threshold 10, duration and window 15 minutes |
| Administrator is retired | Get-LocalUser | Select-Object Name, Enabled | Administrator shows False, or the name has changed |
| RDP is limited to your IPs | Get-NetFirewallRule -DisplayGroup "Remote Desktop" | Get-NetFirewallAddressFilter | Your addresses under RemoteAddress, not Any |
| Port is blocked for others | Test-NetConnection YOUR.SERVER.IP -Port 3389 from another network | TcpTestSucceeded : False |
| Port is open for you | The same command from an allowed address, or your custom port | TcpTestSucceeded : True |
| Failed logons are recorded | auditpol /get /subcategory:"Logon" | Success and Failure |
If you locked yourself out
Open the control panel console, sign in there, and use the row that matches what you changed.
| What you see | Likely cause | Fix from the console |
|---|---|---|
| RDP times out after Step 5 | Your public IP is not in the rule, or the provider firewall has no rule for it | Set-NetFirewallRule -DisplayGroup "Remote Desktop" -RemoteAddress Any, then repeat Step 5 with the right address. Check the provider firewall too |
| RDP times out after Step 6 | No rule for the new port in Windows or in the provider firewall, or the client still uses 3389 | Connect as ip:port. Add the missing rule, or enable the old one with Enable-NetFirewallRule -DisplayGroup "Remote Desktop" |
| "Your credentials did not work" for the new admin | The account is not in the Administrators group, or the password was mistyped when you created it | Add-LocalGroupMember -Group "Administrators" -Member "srv-ops", or reset it with Set-LocalUser -Name "srv-ops" -Password (Read-Host -AsSecureString) |
| "The connection was denied because the user account is not authorized for remote login" | The user is not in Administrators or Remote Desktop Users | Add-LocalGroupMember -Group "Remote Desktop Users" -Member "username" |
| Account locked out | The lockout threshold was reached | Wait for the lockout duration, or run net user username /active:yes to unlock it |
| An old client fails after Step 2 | The client cannot do NLA, or has a CredSSP mismatch | Update the client. See the RDP troubleshooting guide for the CredSSP error |
Common mistakes
- Treating the port change as the fix. The new port is found by a scan of all ports. The allowlist, NLA and lockout do the protecting.
- Changing the port without a firewall rule first. The service moves and the firewall still guards 3389, so you lock yourself out. Add the rules, test, then restart.
- Restricting the Windows rule and forgetting the provider firewall, or the reverse. Both have to allow your address.
- Disabling Administrator before the new account is tested. Windows has no account left to sign in with except the console.
- Setting the lockout threshold to 0. Zero means accounts are never locked, so guessing has no limit.
- Sharing one login. A shared account cannot be traced in the 4625 and 4624 events, and removing one person means changing the password for everyone.
- Leaving an old broad firewall rule enabled after adding a narrow one. Allow rules add up.
- Turning NLA off to fix a connection error. Update the client instead. The RDP troubleshooting guide covers the causes.
- Not reading the log. Event ID 4625 is the one place that shows whether the other settings work.
On Bigdomainhost Windows servers
Our Windows VPS and VDS plans give you your own Windows Server 2019 or 2022 with Administrator access over RDP, in Mumbai (BOM-1) or Delhi NCR (DEL-1). The Windows Server licence is included on Windows VDS, and the RDP server page explains the two administration sessions, when RDS CALs are needed and what we do not sell (shared or resold "admin RDP" accounts). Every command above runs as written on those servers. You set the inbound firewall rules per server in the control panel, and the console there gets you back in when a rule goes wrong.
Stuck on a step? Message us on WhatsApp at +91 75994 50220 at any time, call during IST working hours, or email support@bigdomainhost.com.
This guide was written by the Bigdomainhost team with AI assistance. Commands and behaviour were checked against Microsoft Learn documentation on 29 November 2026. Test each change in a second session or through the console before you close your first RDP session.
Sources (checked )
- Microsoft Learn (Wayback Machine snapshot): Change Remote Desktop listening port on Windows and Windows Server
- Microsoft Learn (Wayback Machine snapshot): Enable Remote Desktop on your PC (NLA, Remote Desktop users, strong passwords)
- Microsoft Learn (Wayback Machine snapshot): Account lockout threshold (recommended value 10, built-in Administrator exclusion)
- Microsoft Learn (Wayback Machine snapshot): 4625(F) An account failed to log on
- Microsoft Learn (Wayback Machine snapshot): auditpol set
- Microsoft Learn (Wayback Machine snapshot): Set-NetFirewallRule (-RemoteAddress formats)
- Microsoft Learn (Wayback Machine snapshot): Get-WinEvent (FilterHashtable)
- Microsoft Learn (Wayback Machine snapshot): Windows Firewall overview
- Microsoft Learn (Wayback Machine snapshot): Overview of TS Gateway (RDP over HTTPS, port 443)
- IANA: Service Name and Transport Protocol Port Number Registry: port 3389