Windows Server on EC2: RDP, passwords and user data
-
Phase 0: Before you start
-
Phase 1: The foundation
-
Phase 2: Operations and security
-
Phase 3: SQL Server on AWS
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
Plenty of companies run Active Directory, file servers and SQL Server on Windows. Running Windows Server on EC2 feels a lot like Linux, apart from a few things that catch people out: the key type, how you get the Administrator password, and how you connect.
You’ll launch win01 with Windows Server 2025, let a start-up script install IIS, decrypt the password on your laptop and open a Remote Desktop session that only your IP can reach.
| Time | You need | By the end you can |
|---|---|---|
| 60 minutes (instance running for about an hour) | saat-vpc and saat-web-sg, your laptop signed in with aws login --profile saat-admin, and Remote Desktop Connection (mstsc, which comes with Windows). It costs about USD 0.15 if you terminate within an hour. | Launch a Windows Server instance with an RSA key, get its password and decrypt it, connect over RDP, run user data on Windows, and spot the silent ED25519 and blocked-port problems. |
What it is, in one line
Windows Server on EC2 is a Windows virtual machine with the licence built into the hourly price, which you reach over RDP using an Administrator password encrypted with your key.
In Simple Words
A locker with a combination sent in a sealed envelope
Imagine renting a locker at a railway station. When you rent it, the office sets a new combination and seals it in an envelope that only your personal key can open, so you collect the envelope, open it at home and then go to the locker. If you’d handed the office a key it can’t seal envelopes with, you’d still get a locker, but your envelope would never arrive, and that’s what happens when you launch Windows with the wrong key type. And if the locker room only lets in people from your street, you can’t get in from a friend’s house, which is the “my IP changed” problem with RDP.
Engineer's View
How Windows on EC2 works
Amazon’s Windows AMIs include the Windows Server licence, and you pay for it in the hourly price, which is why a Windows instance costs more than a Linux one of the same size (Lesson 41 covers bringing your own licence). AWS publishes the latest AMI IDs in public SSM parameters like /aws/service/ami-windows-latest/Windows_Server-2025-English-Full-Base.
On first boot the EC2Launch v2 agent sets a random password for the local Administrator account, encrypts it with the public half of your key pair and passes it to EC2. aws ec2 get-password-data downloads it, and with --priv-launch-key the CLI decrypts it on your machine using your .pem file. This only works with RSA keys; an ED25519 key launches the instance without complaint, but the password never becomes available.
Windows user data goes between <powershell>...</powershell> tags and runs once, as Local System, through EC2Launch. Remote Desktop uses TCP 3389, which in this lab you open only to your own IP, and from Lesson 13 on you won’t open 3389 at all.
Size matters more on Windows, and 1 GiB won’t cut it. Use t3.medium (4 GiB) for a lab server; the root volume is 30 GiB by default.
How it works, step by step
The password travels from the instance to your laptop in a sealed envelope.
1Create an RSA key pair
saat-rsa is for Windows servers, and saat-key (ED25519) stays for Linux.
2Launch with user data
A <powershell> block installs IIS and writes a page, so you can check the server from outside before you’ve even logged in.
3Wait for the password
Windows boots more slowly than Linux, and the password usually shows up 4 to 10 minutes after launch. Until it does, get-password-data returns an empty value rather than an error.
4Connect and look around
RDP in from your IP, and once inside, check that the AWS agents (EC2Launch, SSM Agent) are running, because the next lesson needs them.
This is what’s different compared with the Linux server from Lesson 11.
The habits stay the same: no admin ports open to the world, tags on everything, IMDSv2 required, and terminate when you’re done.
✅ Checkpoint: You can say why Windows needs an RSA key, where the password comes from, and why it can take a few minutes to show up.
Hands-on lab: Windows Server on EC2 with IIS and RDP
Before you run any command, double-check it
Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.
Start as usual:
cd C:\aws-lab
aws login --profile saat-admin
$env:AWS_PROFILE = 'saat-admin'
$v = Get-Content C:\aws-lab\saat-vpc.json | ConvertFrom-Json1Create an RSA key pair for Windows
Paste this whole block:
$key = aws ec2 create-key-pair --key-name saat-rsa --key-type rsa --key-format pem --tag-specifications 'ResourceType=key-pair,Tags=[{Key=course,Value=saatvedha-aws},{Key=lesson,Value=12}]' --query KeyMaterial --output text
[IO.File]::WriteAllText('C:\aws-lab\saat-rsa.pem', (($key -join "`n") + "`n"))
icacls C:\aws-lab\saat-rsa.pem /inheritance:r /grant:r "$($env:USERNAME):(R)"2Find the Windows Server 2025 image
Run this:
$ami = aws ssm get-parameter --name /aws/service/ami-windows-latest/Windows_Server-2025-English-Full-Base --query Parameter.Value --output text
$amiYou should see an AMI ID, something like this:
ami-0e1f2a3b4c5d6e7f83Allow RDP from your IP only
Paste this whole block:
$myip = (Invoke-RestMethod https://checkip.amazonaws.com).Trim()
$rdpSg = aws ec2 create-security-group --group-name saat-rdp-temp --description "RDP from one admin IP (temporary)" --vpc-id $v.VpcId --tag-specifications 'ResourceType=security-group,Tags=[{Key=Name,Value=saat-rdp-temp},{Key=course,Value=saatvedha-aws},{Key=lesson,Value=12}]' --query GroupId --output text
aws ec2 authorize-security-group-ingress --group-id $rdpSg --protocol tcp --port 3389 --cidr "$myip/32" | Out-Null4Launch win01
Paste this whole block:
@'
<powershell>
Install-WindowsFeature Web-Server -IncludeManagementTools
Set-Content -Path C:\inetpub\wwwroot\index.html -Value '<h1>Hello from win01</h1>'
</powershell>
'@ | Set-Content C:\aws-lab\win01-userdata.txt
$id = aws ec2 run-instances --image-id $ami --instance-type t3.medium --key-name saat-rsa --subnet-id $v.PublicA --security-group-ids $v.WebSg $rdpSg --user-data file://win01-userdata.txt --metadata-options HttpTokens=required --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=win01},{Key=course,Value=saatvedha-aws},{Key=lesson,Value=12},{Key=owner,Value=yourname.admin}]' 'ResourceType=volume,Tags=[{Key=course,Value=saatvedha-aws},{Key=lesson,Value=12}]' --query "Instances[0].InstanceId" --output text
aws ec2 wait instance-running --instance-ids $id
$ip = aws ec2 describe-instances --instance-ids $id --query "Reservations[0].Instances[0].PublicIpAddress" --output text
"$id $ip"Windows user data doesn’t mind Windows line endings, so Set-Content is fine here.
5Wait for and decrypt the password
Paste this whole block. It checks every 30 seconds and usually finishes within 10 minutes:
do { Start-Sleep 30; $pw = aws ec2 get-password-data --instance-id $id --priv-launch-key C:\aws-lab\saat-rsa.pem --query PasswordData --output text } until ($pw)
if ($pw) { 'Password received' }You should see this:
Password received6Check the web page and the RDP port
Run this:
(Invoke-WebRequest "http://$ip" -UseBasicParsing).Content
Test-NetConnection $ip -Port 3389 -InformationLevel QuietYou should see this. If the page isn’t there yet, IIS is still installing, so give it two minutes:
<h1>Hello from win01</h1>
True
7Connect with Remote Desktop
Run this:
cmdkey /generic:$ip /user:Administrator /pass:$pw
mstsc /v:$ipAccept the certificate warning (the server uses a self-signed certificate). Then, in the remote session, open Windows PowerShell and run:
$t = Invoke-RestMethod -Method Put -Uri http://169.254.169.254/latest/api/token -Headers @{ 'X-aws-ec2-metadata-token-ttl-seconds' = '300' }
Invoke-RestMethod -Uri http://169.254.169.254/latest/meta-data/instance-type -Headers @{ 'X-aws-ec2-metadata-token' = $t }
Get-Service AmazonSSMAgent | Select-Object Status, NameYou should see something like this:
t3.medium
Status Name
------ ----
Running AmazonSSMAgentAmazon’s Windows AMIs come with the SSM Agent already installed and running, and in Lesson 13 it’ll let you manage servers without any RDP port open.
✅ Checkpoint: win01 served “Hello from win01”, get-password-data gave you a password, and RDP worked from your IP. Keep win01 for the break lab, which ends with the cleanup.
Break It, Then Fix It
Neither of these gives you an error message, you just get nothing, and that’s why they eat up so much time.
1Break it: launch Windows with the ED25519 key
Launch a second, smaller test server with your Linux key, wait 10 minutes and then ask for its password:
$id2 = aws ec2 run-instances --image-id $ami --instance-type t3.medium --key-name saat-key --subnet-id $v.PublicA --security-group-ids $rdpSg --metadata-options HttpTokens=required --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=win02},{Key=course,Value=saatvedha-aws},{Key=lesson,Value=12}]' --query "Instances[0].InstanceId" --output text
Start-Sleep 600
aws ec2 get-password-data --instance-id $id2 --priv-launch-key C:\aws-lab\saat-key.pem --query PasswordData --output text
aws ec2 describe-key-pairs --key-names saat-key --query "KeyPairs[0].KeyType" --output textYou should see an empty line followed by the key type (something like this):
ed25519
The console shows “Password is not available” for this instance and gives no reason. Fix: Windows needs an RSA key pair, and since you can’t change the key on a running instance, terminate it and launch again with saat-rsa.
2Break it: your IP changed
This happens when you move from the office Wi-Fi to home, or when your provider changes your address. To simulate it, replace your rule with someone else’s IP:
aws ec2 revoke-security-group-ingress --group-id $rdpSg --protocol tcp --port 3389 --cidr "$myip/32"
aws ec2 authorize-security-group-ingress --group-id $rdpSg --protocol tcp --port 3389 --cidr 203.0.113.10/32 | Out-Null
Test-NetConnection $ip -Port 3389 -InformationLevel QuietYou’ll get something like this:
WARNING: TCP connect to (13.234.17.88 : 3389) failed
FalseAll RDP tells you is that it can’t connect. Fix: compare your current IP with the one in the rule, then correct it:
(Invoke-RestMethod https://checkip.amazonaws.com).Trim()
aws ec2 describe-security-group-rules --filters "Name=group-id,Values=$rdpSg" --query 'SecurityGroupRules[?IsEgress==`false`].CidrIpv4' --output text
aws ec2 revoke-security-group-ingress --group-id $rdpSg --protocol tcp --port 3389 --cidr 203.0.113.10/32
aws ec2 authorize-security-group-ingress --group-id $rdpSg --protocol tcp --port 3389 --cidr "$myip/32" | Out-Null3Clean up
Paste this whole block:
aws ec2 terminate-instances --instance-ids $id $id2 | Out-Null
aws ec2 wait instance-terminated --instance-ids $id $id2
aws ec2 delete-security-group --group-id $rdpSg
cmdkey /delete:$ip
.\Find-LabResources.ps1Hang on to the saat-rsa key pair and its .pem file for the later Windows lessons.
✅ Checkpoint: You saw an empty password caused by the key type and a silent RDP failure caused by an IP change, fixed both, and terminated both instances.
This happened at work
The “quick test” RDP port
A consultant was setting up a Windows server for a client demo and opened RDP 3389 to 0.0.0.0/0 “just for the afternoon”. To make logging in quicker, he also swapped the generated Administrator password for something short he could type fast.
The demo went fine, and the port stayed open afterwards. Within a day the Windows Security log had tens of thousands of failed logins (event 4625) from addresses all over the world, and on day four one of them got in.
The attacker installed ransomware, which encrypted the server and a mapped file share. The client restored from backups and lost two days of work. After that the rules were: no 3389 or 22 open to the internet, ever; admin access through Systems Manager Session Manager or Fleet Manager; an AWS Config rule that flags any security group with 3389 open to the world; and generated passwords kept in a password manager instead of being swapped for easy ones.
Common mistakes and troubleshooting
| Mistake | What happens | What to do |
|---|---|---|
| Launching Windows with an ED25519 key | “Password is not available”, forever | Use an RSA key pair for Windows |
| Asking for the password straight after launch | An empty result that looks broken | Wait 4 to 10 minutes, looping until it appears |
| t3.micro for Windows | A slow, unresponsive server | t3.medium (4 GiB) or larger |
| RDP open to 0.0.0.0/0 | Brute-force attempts start within hours | Your IP only for now, then Session Manager from Lesson 13 |
| Rule for an old IP address | RDP times out without any explanation | Check your current IP and the rule |
| Forgetting the licence cost | Windows costs more per hour than Linux | Terminate test servers, and use Linux where you can |
Interview questions
Click a question to open it. Each one is worded the way an interviewer might ask it, and underneath you’ll find why they ask it and one way you could answer in your own words.
Fresher level
1. You’ve just launched a Windows instance. How do you get the Administrator password to log in?
Why they ask this: They’re checking the basics of running Windows on EC2, since it’s the first thing you need on any new Windows server.
How you might answer: On first boot, EC2Launch sets a random password and encrypts it with the instance’s public key. I fetch it with aws ec2 get-password-data and decrypt it with my private key, or in the console the Get password button does the same job.
2. A manager asks why the Windows instance costs more than a Linux one of the same size. What would you tell them?
Why they ask this: They want to see basic licensing awareness, because managers ask cost questions like this all the time.
How you might answer: I’d tell them Amazon’s Windows AMIs include the Windows Server licence, and it’s billed inside the hourly price. We could bring our own licence, but Microsoft licensing adds extra rules for that and it might need dedicated hosts.
3. You created an ED25519 key pair and launched a Windows instance with it. Why might you be in trouble?
Why they ask this: They want to see you know a small detail that causes real problems, which tells them you’ve done this by hand and not only read about it.
How you might answer: For the password, Windows instances only work with RSA key pairs. ED25519 is fine on Linux, but on Windows I’d have no way of retrieving the Administrator password with it.
2–5 years experience
4. A user says they can’t RDP to a Windows instance. Walk me through what you’d check.
Why they ask this: They want a clear troubleshooting order from the outside in, because jumping straight to a reboot is the habit they want to avoid.
How you might answer: I’d check the instance state and status checks first, then the security group rule for 3389 against my current IP, then the network ACL and route table. I’d make sure it has a public IP, or that I’m on the right private path, and check Windows Firewall. Test-NetConnection to port 3389 tells me whether it’s a network problem or a login problem, and if the network’s fine but RDP still isn’t, I’d go in through the EC2 serial console or Session Manager.
5. How is user data on a Windows instance different from Linux?
Why they ask this: They want to see you can automate Windows servers as well. The tags and log locations are different, and that catches people out.
How you might answer: On Windows the script goes inside <powershell> or <script> tags, or YAML for EC2Launch v2. It runs as Local System through EC2Launch, and by default only on the first boot. When it fails, I look at the logs under C:\ProgramData\Amazon\EC2Launch\log.
6. Say you’re asked to manage 100 Windows servers, but RDP is closed. How would you do your job?
Why they ask this: They’re looking for modern operations habits, since managing servers without open inbound ports is safer and scales better.
How you might answer: I’d do nearly everything through Systems Manager: Session Manager for a shell, Run Command for scripts and Patch Manager for updates. When I need a remote desktop, Fleet Manager gives me one through the console, and State Manager keeps the configuration in place, all without any inbound ports.
Senior level
7. A team wants to lift-and-shift 50 Windows servers to EC2. What would you plan for before the first move?
Why they ask this: They want to see real migration thinking, because licensing, identity and access are where these projects tend to go wrong.
How you might answer: I’d sort out licensing first, included or bring-your-own, and size the instances from real metrics. I’d also plan domain membership and DNS, the storage layout, and backup and patching through AWS Backup and Patch Manager, with admin access that doesn’t need open RDP. For the move itself I’d use something like AWS Application Migration Service and do test cutovers first.
8. How would you keep the local Administrator account safe across a whole fleet of Windows servers?
Why they ask this: They want to see how you handle identity on servers. A shared local password across a fleet is a big risk.
How you might answer: I’d rotate the password on each server with Windows LAPS or Secrets Manager, and nobody would use it for daily work. The servers join a domain or AWS Managed Microsoft AD, we audit logons, and RDP stays closed to the internet.
Quick quiz
Q1. Which key pair type must you use for a Windows instance?
- ED25519
- RSA
- Either
- None
Show answer
B: Windows needs an RSA key to deliver the encrypted Administrator password.
Q2. get-password-data returns an empty value 2 minutes after launch. What is the most likely reason?
- The key is wrong
- The password isn’t ready yet
- RDP is closed
- The instance is Linux
Show answer
B: Windows usually takes 4 to 10 minutes before the password is ready.
Q3. Which port does Remote Desktop use?
- 22
- 80
- 443
- 3389
Show answer
D: RDP runs on TCP 3389.
Q4. How does Windows user data need to be wrapped?
- #!/bin/bash
- <powershell> … </powershell>
- { “script”: … }
- No wrapping
Show answer
B: EC2Launch runs scripts that sit inside <powershell> or <script> tags.
Q5. Which smallest instance type is sensible for a Windows Server lab?
- t3.nano
- t3.micro
- t3.medium
- x2iedn.32xlarge
Show answer
C: Windows needs more memory, and t3.medium has 4 GiB.
Quick recap
- Windows on EC2 needs an RSA key pair, because an ED25519 key launches fine but never gives you a password.
- EC2Launch v2 sets and encrypts the Administrator password, and get-password-data with
--priv-launch-keydecrypts it once it’s ready after 4 to 10 minutes. - Windows user data goes in <powershell> tags, and you should use t3.medium or bigger.
- For now, RDP 3389 is open only from your current IP, and when that IP changes it shows up as a silent timeout.
- The SSM Agent already runs on Amazon’s Windows AMIs, ready for Lesson 13.
Next lesson
Lesson 13: Systems Manager Session Manager → Next you’ll reach both Linux and Windows servers without any SSH or RDP port open.
Further reading: Windows Server on EC2
If you want to go further with Windows Server on EC2, read Connect to your Windows instance using RDP and Configure a Windows instance using EC2Launch v2. The full plan for this course is on the AWS Cloud Administration course page.
