Remote Desktop Protocol (RDP) on port 3389 is constantly scanned across the internet. Automated tools try thousands of username and password combinations per hour, and a successful guess is one of the most common ways ransomware gets into servers. If you have just set up a Windows VPS or dedicated server and look at the Security event log, you will almost certainly already see failed logins from around the world.
The good news: a handful of settings make RDP very hard to break into. This guide goes through them in order of impact.
1. Strong, non-default accounts
Most attacks guess passwords for common usernames: Administrator, admin, user, test.
- Create your own administrator account with a non-obvious name and disable or rename the built-in Administrator — see Windows Server initial setup.
- Use long passphrases (16+ characters), unique to this server.
- Allow RDP only for accounts that need it: System Properties → Remote → Select Users. Remove anyone who does not need remote access.
2. Network Level Authentication (NLA)
With NLA, users must authenticate before a full Remote Desktop session is created. It reduces the server resources attackers can consume and the attack surface of the RDP service.
System Properties → Remote → tick “Allow connections only from computers running Remote Desktop with Network Level Authentication (recommended)”.
PowerShell:
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name UserAuthentication -Value 1
All current Windows, macOS and mobile RDP clients support NLA.
3. Account lockout policy
Lock an account after a few failed attempts so passwords cannot be guessed at speed:
Local Security Policy (secpol.msc) → Account Policies → Account Lockout Policy
| Setting | Suggested |
|---|---|
| Account lockout threshold | 5–10 invalid attempts |
| Account lockout duration | 15–30 minutes |
| Reset account lockout counter after | 15–30 minutes |
On recent Windows Server versions, the built-in Administrator account can also be locked out by this policy (on older versions it is exempt — another reason to disable it).
A lockout policy slows attackers down but can also lock out you during an attack on your username — which is why a non-obvious username matters.
4. Allow RDP only from your IP addresses
The single most effective measure: if attackers cannot reach port 3389, they cannot guess passwords.
Windows Defender Firewall with Advanced Security → Inbound Rules → Remote Desktop - User Mode (TCP-In) → Properties → Scope → Remote IP address → “These IP addresses” → add your office or home IP.
PowerShell:
Set-NetFirewallRule -DisplayGroup "Remote Desktop" -RemoteAddress 198.51.100.7,203.0.113.0/28
If your IP changes often, connect through a VPN with a fixed exit IP, or use a WireGuard tunnel (WireGuard has a Windows client) and allow RDP only from the tunnel address. Keep the provider’s VNC console in mind as an emergency way in if you lock yourself out.
5. Change the RDP port (reduces noise)
Moving RDP from 3389 to another port does not stop targeted attacks, but it removes a large share of automated scanning. Do it in the right order so you do not lock yourself out:
- Add a firewall rule for the new port first:
New-NetFirewallRule -DisplayName "RDP 53389" -Direction Inbound -Protocol TCP -LocalPort 53389 -Action Allow
- Change the port in the registry:
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -Name PortNumber -Value 53389
Restart-Service TermService -Force
- Connect to
SERVER_IP:53389. Once it works, disable the old 3389 rule.
Restarting the service disconnects your session; reconnect on the new port. If something goes wrong, use the VNC console.
6. Block attacking IPs automatically
Windows has no built-in equivalent of Linux’s Fail2ban, but several tools watch the Security log for failed logins (event ID 4625) and block offending IPs in Windows Firewall — for example the open-source IPBan or EvlWatcher, and some commercial products. Install from the project’s official site, add your own IPs to the whitelist, and test.
7. Two-factor authentication
For servers holding important data, add a second factor to RDP logins. Options include Duo for Windows Logon, and other RDP MFA products that add a push notification or one-time code to the Windows login. Read the vendor’s offline/failure behaviour carefully so you are not locked out if their service is unreachable.
8. Keep Windows updated
Several serious RDP vulnerabilities (such as BlueKeep in 2019) allowed attacks without any password. They were fixed by updates. Keep automatic updates on and reboot regularly — see Windows Server initial setup.
9. Monitor login attempts
Open Event Viewer → Windows Logs → Security and filter for:
| Event ID | Meaning |
|---|---|
| 4624 | Successful logon (Logon Type 10 = RemoteInteractive / RDP) |
| 4625 | Failed logon |
| 4740 | Account locked out |
PowerShell — top IPs with failed logons in the last 24 hours:
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625; StartTime=(Get-Date).AddDays(-1)} |
ForEach-Object { ([xml]$_.ToXml()).Event.EventData.Data | Where Name -eq 'IpAddress' | Select -Expand '#text' } |
Group-Object | Sort Count -Descending | Select -First 10 Count, Name
Successful logons you do not recognise mean you should treat the server as compromised: disconnect it, change passwords from a clean device, and investigate or reinstall.
10. RD Gateway for teams
For organisations with several users and servers, a Remote Desktop Gateway publishes RDP over HTTPS (port 443) with central policies, certificates and optional MFA, and keeps port 3389 closed on every server. It needs an additional server role and a TLS certificate; it is worth it once you manage more than a few servers.
11. Limit the damage if an account is compromised
- Do not browse the web or read email on the server.
- Keep backups off the server, so ransomware on the server cannot encrypt them.
- Give users non-administrator accounts unless they need admin rights.
- Disable clipboard and drive redirection in RDP for users who do not need them (Group Policy: Remote Desktop Session Host → Device and Resource Redirection).
Checklist
- Built-in Administrator disabled or renamed; strong unique passwords
- NLA enabled
- Account lockout policy configured
- RDP limited to your IPs or a VPN (or at least moved off 3389)
- Automatic blocking of attacking IPs
- Updates current
- Failed and successful logons reviewed
- Off-server backups