Can’t RDP or SSH to an Azure VM
-
Phase 0: Before you start
-
Phase 1: The foundation
-
Phase 2: Day-to-day operations
-
Phase 3: Enterprise architecture
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
“Azure VM RDP not working” is one of the most searched Azure problems, and the same steps sort out SSH on Linux. What helps most is to stop guessing and walk the path in order: is the VM up, does Azure let the packet in, does the guest firewall let it in, is the service listening, and do the credentials work.
Each layer has its own tool and each tool gives you a clear answer: Test-NetConnection tells you whether TCP gets through, IP flow verify tells you whether an NSG allows it, and Run Command shows you what the guest thinks. Within ten minutes you’ll know which layer is wrong.
In the lab you’ll build a Windows Server VM you can RDP to, break the NSG and then the Windows Firewall, and fix each one from outside the VM.
| Time | You need | Cost | By the end you can |
|---|---|---|---|
| About 50 minutes | A free account, the CLI, PowerShell and Remote Desktop on your laptop | Around 10 US cents: a small Windows VM and a public IP for less than an hour | Work out which layer is blocking RDP or SSH within minutes, and fix it without logging in |
What it is, in one line
When RDP or SSH fails, go through the layers in order: VM state, NSG, guest firewall, service, and credentials last.
In Simple Words
Visiting a friend in a gated society
You can’t get to your friend’s flat, and before you complain, you go through it in order. Is your friend at home (VM running)? Did the society gate let you in (NSG)? Did the building door open (guest firewall)? Is anyone answering the doorbell (RDP service)? And do you know the door code (credentials)?
Each check gives its own sign, and if the gatekeeper turned you away, ringing the doorbell louder won’t help. Engineers who jump straight to “reset the password” are ringing the doorbell while still standing at the gate.
Engineer's View
The RDP and SSH path, layer by layer
- VM state: Running, agent Ready and boot finished (if not, go to Lesson 60).
- Network path: public IP or Bastion, the NSGs on the subnet and the NIC (both have to allow it), route tables, and Azure Firewall if the traffic goes through a hub.
- IP flow verify: Network Watcher tests one specific 5-tuple against the effective NSG rules and tells you which rule allows or denies it.
- Guest firewall: on Windows, the “Remote Desktop – User Mode (TCP-In)” rule (name RemoteDesktop-UserMode-In-TCP); on Linux, ufw, firewalld or iptables for port 22.
- Service: TermService listening on 3389 (or whatever port it was moved to), and on Linux sshd on 22 with a valid config.
- Credentials: az vm user update (the VMAccess extension) resets passwords or SSH keys, and on Linux az vm user reset-ssh resets the SSH configuration.
- Better than public RDP: Bastion or just-in-time access (Lessons 27 and 28). If port 3389 is open to the internet, attacks start within minutes.
How it works, step by step
Here’s how to read the two most useful tests side by side:
- From your laptop, run Test-NetConnection to port 3389.
- If that works, the network is fine, so look at credentials, the RDP client or the user’s rights.
- If it fails, run IP flow verify with your public IP. A Deny means the NSG is the problem, and it’ll name the rule.
- If IP flow verify says Allow and TCP still fails, the packet is reaching the VM and something inside is dropping it, either the guest firewall or the service.
- Use Run Command to check the guest firewall and the listening port and fix them without logging in.
That split, where Azure says allow but TCP fails, is the most useful clue in this whole lesson.
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.
For Linux, use 22 instead of 3389, ufw or firewalld instead of Windows Firewall, and sshd instead of TermService. The order doesn’t change.
The same checks for SSH on Linux
The SSH client’s error message already points you at the right layer, so read it properly before you do anything else:
| SSH error | What it means | Where to look |
|---|---|---|
| Connection timed out | Packets never got an answer | NSG, route tables, public IP, Azure Firewall |
| Connection refused | The VM replied, but nothing is listening on 22 | sshd stopped, wrong port, or guest firewall reject |
| Permission denied (publickey) | Network fine, login rejected | User name, key, authorized_keys permissions |
| Host key verification failed | The VM was rebuilt with a new host key | After checking, remove the old entry from known_hosts |
For the guest checks, Run Command works the same on Linux, using RunShellScript in place of RunPowerShellScript:
az vm run-command invoke --resource-group <rg> --name <vm> --command-id RunShellScript --scripts 'ss -tlnp | grep :22; ufw status | head -3; sshd -t && echo sshd config ok' --query "value[0].message" -o tsv
az vm user reset-ssh --resource-group <rg> --name <vm>
az vm user update --resource-group <rg> --name <vm> --username azureuser --ssh-key-value ~/.ssh/id_rsa.pubsshd -t tests the SSH configuration file and prints the line that’s wrong. reset-ssh puts the SSH configuration back to defaults, and user update swaps the key for one user. Both go through the VMAccess extension, so the VM agent has to be Ready.
Build an RDP path and test every layer
1A Windows VM that only your IP can reach
Find your public IP, create the VM and allow RDP from that IP only (takes about 5 minutes):
$myIp = (Invoke-RestMethod https://api.ipify.org)
$pw = 'Sv-' + (-join ((65..90) + (97..122) + (48..57) | Get-Random -Count 14 | ForEach-Object { [char]$_ })) + '9!'
az group create --name rg-saat-l61 --location centralindia --tags course=saatvedha-azure lesson=61 -o none
az vm create --resource-group rg-saat-l61 --name vm-win --image Win2022Datacenter --size Standard_B2s --public-ip-sku Standard --nsg-rule NONE --admin-username azureadmin --admin-password $pw --tags course=saatvedha-azure lesson=61 -o none
az network nsg rule create --resource-group rg-saat-l61 --nsg-name vm-winNSG --name allow-rdp-me --priority 100 --direction Inbound --access Allow --protocol Tcp --source-address-prefixes $myIp --destination-port-ranges 3389 -o none
$ip = az vm show --resource-group rg-saat-l61 --name vm-win --show-details --query publicIps -o tsv
$priv = az vm show --resource-group rg-saat-l61 --name vm-win --show-details --query privateIps -o tsv2Test the path from outside
Check TCP from your laptop, then ask Network Watcher what the NSG decides:
Test-NetConnection $ip -Port 3389 -WarningAction SilentlyContinue | Select-Object RemoteAddress, TcpTestSucceeded
az network watcher test-ip-flow --resource-group rg-saat-l61 --vm vm-win --direction Inbound --protocol TCP --local "${priv}:3389" --remote "${myIp}:50000" -o tableYou should see something like this:
RemoteAddress TcpTestSucceeded
------------- ----------------
20.x.x.x True
Access RuleName
-------- ---------------------------
Allow securityRules/allow-rdp-me3Connect
Open Remote Desktop to the VM and sign in as azureadmin using $pw:
mstsc /v:$ipAccept the certificate warning (the VM has a self-signed RDP certificate), and sign out once you see the desktop.


✅ Checkpoint: vm-win accepts RDP from your IP only, and you’ve seen what a healthy Test-NetConnection and IP flow verify look like.
Break It, Then Fix It
Leave the VM running, since both breaks use it.
1Break it: your IP changed
Home and office internet IPs change all the time. Simulate that by pointing the rule at a different address:
az network nsg rule update --resource-group rg-saat-l61 --nsg-name vm-winNSG --name allow-rdp-me --source-address-prefixes 203.0.113.10 -o none
Test-NetConnection $ip -Port 3389 -WarningAction SilentlyContinue | Select-Object RemoteAddress, TcpTestSucceeded
az network watcher test-ip-flow --resource-group rg-saat-l61 --vm vm-win --direction Inbound --protocol TCP --local "${priv}:3389" --remote "${myIp}:50000" -o tableYou should see something like this:
RemoteAddress TcpTestSucceeded
------------- ----------------
20.x.x.x False
Access RuleName
-------- ----------------------------------
Deny defaultSecurityRules/DenyAllInBoundTCP fails and Azure says Deny, naming the default rule, because the NSG doesn’t know your current IP. Resetting the password or restarting the VM wouldn’t change a thing.
To fix it, update the rule with your current IP and test again:
$myIp = (Invoke-RestMethod https://api.ipify.org)
az network nsg rule update --resource-group rg-saat-l61 --nsg-name vm-winNSG --name allow-rdp-me --source-address-prefixes $myIp -o none
Test-NetConnection $ip -Port 3389 -WarningAction SilentlyContinue | Select-Object RemoteAddress, TcpTestSucceededTcpTestSucceeded is True again. For people whose IP keeps changing, the lasting fix is Bastion or just-in-time access.
2Break it: Azure allows it, the VM doesn’t
Someone “hardens” the server and switches off the Remote Desktop firewall rules inside Windows:
az vm run-command invoke --resource-group rg-saat-l61 --name vm-win --command-id RunPowerShellScript --scripts 'Disable-NetFirewallRule -Name RemoteDesktop-UserMode-In-TCP,RemoteDesktop-UserMode-In-UDP' --query "value[0].message" -o tsv
Test-NetConnection $ip -Port 3389 -WarningAction SilentlyContinue | Select-Object RemoteAddress, TcpTestSucceeded
az network watcher test-ip-flow --resource-group rg-saat-l61 --vm vm-win --direction Inbound --protocol TCP --local "${priv}:3389" --remote "${myIp}:50000" -o tableYou should see something like this:
RemoteAddress TcpTestSucceeded
------------- ----------------
20.x.x.x False
Access RuleName
-------- ---------------------------
Allow securityRules/allow-rdp-meAzure says Allow and TCP still fails, so the packet is reaching the VM and something inside is dropping it. In one step you’ve ruled out the entire Azure network.
Check the guest firewall and the listener from outside, and then fix it:
az vm run-command invoke --resource-group rg-saat-l61 --name vm-win --command-id RunPowerShellScript --scripts 'Get-NetFirewallRule -Name RemoteDesktop-UserMode-In-TCP | Select-Object Name, Enabled; Get-NetTCPConnection -LocalPort 3389 -State Listen | Select-Object LocalPort, State' --query "value[0].message" -o tsv
az vm run-command invoke --resource-group rg-saat-l61 --name vm-win --command-id RunPowerShellScript --scripts 'Enable-NetFirewallRule -Name RemoteDesktop-UserMode-In-TCP,RemoteDesktop-UserMode-In-UDP' --query "value[0].message" -o tsv
Test-NetConnection $ip -Port 3389 -WarningAction SilentlyContinue | Select-Object RemoteAddress, TcpTestSucceededYou should see something like this:
Name Enabled
---- -------
RemoteDesktop-UserMode-In-TCP False
LocalPort State
--------- -----
3389 Listen
RemoteAddress TcpTestSucceeded
------------- ----------------
20.x.x.x TrueThe service had been listening the whole time and only the firewall rule was off. Once you enable it, RDP works again.

3Clean up
Delete the lab resource group:
az group delete --name rg-saat-l61 --yes✅ Checkpoint: With two commands you told an NSG block apart from a guest firewall block, and you fixed both without logging in.
This happened at work
The RDP port that moved
A bank’s security team used Group Policy to move the RDP port on every Windows server from 3389 to 50133, to “reduce scanning”, but the NSGs still allowed 3389. After the next policy refresh the operations team couldn’t get onto a single server, and the change ticket had already been closed as “no impact”.
IP flow verify on 3389 said Allow, so the NSGs looked fine, yet Test-NetConnection on 3389 failed. Someone finally ran Get-NetTCPConnection through Run Command and saw the listener on 50133 instead of 3389, so the servers were perfectly healthy and just listening somewhere else.
What they changed: RDP went back to 3389 and is now reachable only through Azure Bastion, with no public RDP at all, so instead of moving ports they removed the exposure. For any guest-level security change, the change process now asks “which network rules depend on this setting?”
Common mistakes and troubleshooting
| Mistake | What you see | What to do |
|---|---|---|
| Resetting the password first | Still can’t connect | Test TCP and run IP flow verify before you touch credentials. |
| Rule on NIC NSG but subnet NSG denies | IP flow verify Deny | Both NSGs have to allow it, so check the effective rules. |
| Guest firewall rule disabled | Azure Allow, TCP fails | Check it with Run Command and turn the rule back on. |
| RDP port changed in the guest | Allow on 3389 but nothing listens | Check the listening port, then align the NSG or revert. |
| Home IP changed | Deny by DenyAllInBound | Update the source IP, or use Bastion or JIT. |
| Linux sshd_config broken | Connection refused on 22 | az vm user reset-ssh, or fix it through Run Command. |
Interview questions
Click a question to open it. Each one is phrased the way an interviewer would ask it, and underneath you’ll find why they ask it and one way you could answer in your own words.
Fresher level
1. A user can’t RDP to a VM. What do you check first?
Why they ask this: The basic method.
How you might answer: First, that the VM is running. Then I’d check whether TCP 3389 gets through with Test-NetConnection, and after that the NSG with IP flow verify.
2. What is IP flow verify?
Why they ask this: Tool knowledge.
How you might answer: It’s a Network Watcher test that takes a specific source, destination, port and protocol, checks it against the effective NSG rules and tells you which rule matched.
3. How do you reset a forgotten admin password?
Why they ask this: A practical task.
How you might answer: With az vm user update or Reset password in the portal. Both use the VMAccess extension, so the VM agent has to be running.
2–5 years experience
4. IP flow verify says Allow, but RDP fails. Why?
Why they ask this: A real troubleshooting path.
How you might answer: The packet is getting to the VM, so the guest is dropping it. It could be Windows Firewall, a changed RDP port, a stopped service or some third-party security software, and I’d check with Run Command.
5. RDP gives “An internal error has occurred”. What could it be?
Why they ask this: Experience question.
How you might answer: It could be an RDP certificate or TLS problem, a full disk, licensing in an RDS setup, or a CredSSP mismatch. I’d read the event logs through Run Command and look at the boot screenshot.
6. How do you troubleshoot SSH on Linux the same way?
Why they ask this: Parity check.
How you might answer: Test TCP 22 and run IP flow verify, check ufw or firewalld, look at sshd status and sshd_config, and then reset the SSH key or configuration with the az vm user commands.
Senior level
7. How should administrators reach VMs in production?
Why they ask this: They want secure design.
How you might answer: No public RDP or SSH at all. I’d use Azure Bastion or a VPN, just-in-time access and Entra ID login with MFA, and keep NSGs that allow management only from the Bastion subnet or a jump host.
8. How do you troubleshoot at scale when 100 VMs lose RDP?
Why they ask this: Scale thinking.
How you might answer: I’d look for the common change in the Activity log, like a GPO, NSG, route or firewall update, test a few of the VMs with IP flow verify and Run Command, and roll back the shared change.
9. What do you check when RDP through Bastion fails?
Why they ask this: Bastion depth.
How you might answer: The NSG rules on the Bastion subnet, whether the VM’s NSG allows the Bastion subnet, the guest firewall on the VM, and whether the SKU supports the connection method you’re using.
Quick quiz
Q1. Test-NetConnection fails and IP flow verify says Deny. Problem is?
- Guest firewall
- An NSG
- Password
- DNS
Show answer
B — The NSG blocks the packet.
Q2. IP flow verify Allow but TCP fails. Look where?
- NSG
- Inside the guest
- Route table
- Subscription
Show answer
B — The packet reached the VM.
Q3. Which tool resets a VM password without logging in?
- az vm restart
- az vm user update
- az vm redeploy
- az network nsg
Show answer
B — It uses the VMAccess extension.
Q4. Windows Firewall rule name for RDP TCP?
- RDP-Allow
- RemoteDesktop-UserMode-In-TCP
- TermService-In
- Port3389
Show answer
B — That’s the built-in rule name.
Q5. Best long-term way to avoid IP-based NSG rules for admins?
- Open 3389 to all
- Bastion or JIT
- Change the port
- Disable NSGs
Show answer
B — Remove public RDP exposure.
Quick recap
You can now find the broken layer behind any RDP or SSH ticket within minutes and fix it from outside.
- Check the VM, NSG, guest firewall and service, and credentials last.
- Test-NetConnection tells you whether TCP gets through.
- IP flow verify tells you whether the NSG allows it, and which rule.
- Azure Allow with a TCP failure means the guest is blocking it.
- Use Bastion or JIT rather than public RDP and SSH.
Next lesson
Lesson 62: Network Watcher: IP flow verify and Next hop → You use Network Watcher’s IP flow verify, next hop, connection troubleshoot and VNet flow logs to prove where packets go.
Further reading: Azure VM RDP not working
Want to go deeper into Azure VM RDP not working? See Microsoft’s Troubleshoot Remote Desktop connections to an Azure VM and IP flow verify overview. You can also see the full plan for this course on the Azure Cloud Administration course page.
