SSH and RDP access in Azure - Time & Space Complexity
When connecting to virtual machines using SSH or RDP, it's important to understand how the number of connections affects the system.
We want to know how the time to establish access grows as more machines or users are involved.
Analyze the time complexity of opening SSH or RDP sessions to multiple Azure VMs.
// Pseudocode for opening SSH or RDP sessions
for (int i = 0; i < vmCount; i++) {
ConnectToVM(vmList[i]);
}
void ConnectToVM(string vm) {
// Establish network connection
// Authenticate user
// Open session
}
This sequence opens a remote access session to each VM one by one.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Establishing a remote connection (SSH or RDP) to a VM.
- How many times: Once per VM, repeated for each VM in the list.
Each additional VM requires a new connection, so the total time grows as you add more VMs.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 connections |
| 100 | 100 connections |
| 1000 | 1000 connections |
Pattern observation: The number of connection operations grows directly with the number of VMs.
Time Complexity: O(n)
This means the time to establish access grows linearly with the number of VMs you connect to.
[X] Wrong: "Opening multiple SSH or RDP sessions happens all at once and takes the same time as one session."
[OK] Correct: Each connection requires its own setup time, so more sessions mean more total time.
Understanding how connection time scales helps you design systems that handle many users or machines efficiently.
"What if connections were opened in parallel instead of one after another? How would the time complexity change?"
Practice
Solution
Step 1: Identify SSH default port
SSH (Secure Shell) uses port 22 by default to connect securely to Linux machines.Step 2: Compare with other ports
Port 3389 is used by RDP, port 80 is for HTTP, and port 443 is for HTTPS, so they are incorrect for SSH.Final Answer:
Port 22 -> Option BQuick Check:
SSH = Port 22 [OK]
- Confusing SSH port with RDP port
- Using HTTP or HTTPS ports for SSH
- Assuming SSH uses a random port
Solution
Step 1: Identify RDP port and protocol
RDP uses TCP protocol on port 3389 for Windows remote desktop connections.Step 2: Match correct NSG rule syntax
Allowing inbound TCP on port 3389 opens RDP access. Other options use wrong ports or protocols.Final Answer:
Allow inbound TCP on port 3389 -> Option AQuick Check:
RDP = TCP 3389 inbound [OK]
- Using UDP instead of TCP
- Opening wrong port 22 for RDP
- Setting outbound instead of inbound rules
az network nsg rule create --resource-group MyResourceGroup --nsg-name MyNSG --name AllowSSH --protocol Tcp --direction Inbound --priority 1000 --source-address-prefixes '*' --source-port-ranges '*' --destination-address-prefixes '*' --destination-port-ranges 22 --access Allow
Solution
Step 1: Analyze command parameters
The command creates an NSG rule named AllowSSH allowing inbound TCP traffic on port 22 from any source to any destination.Step 2: Confirm traffic direction and protocol
Direction is inbound, protocol is TCP, port is 22, and access is Allow, so it opens SSH access.Final Answer:
Allows inbound TCP traffic on port 22 from any source -> Option AQuick Check:
Inbound TCP 22 allowed = SSH access [OK]
- Confusing inbound with outbound
- Using UDP instead of TCP
- Misreading port number
Solution
Step 1: Understand RDP connection requirements
RDP requires inbound TCP access on port 3389 to allow remote desktop connections.Step 2: Identify blocking rule
If NSG blocks inbound TCP on port 3389, the connection will time out because traffic is denied.Final Answer:
NSG blocks inbound TCP on port 3389 -> Option CQuick Check:
Blocked inbound TCP 3389 causes timeout [OK]
- Confusing inbound with outbound rules
- Using wrong port for RDP
- Assuming UDP is needed for RDP
Solution
Step 1: Identify SSH port and protocol
SSH uses TCP on port 22, so the rule must allow TCP on port 22.Step 2: Restrict source IP to office IP
To secure access, restrict source to the office IP with /32 mask for a single IP.Step 3: Exclude incorrect options
Allow inbound TCP on port 22 from source 0.0.0.0/0 allows all IPs (not secure), Allow inbound UDP on port 22 from source 203.0.113.5/32 uses UDP (wrong protocol), Allow inbound TCP on port 3389 from source 203.0.113.5/32 uses RDP port (wrong service).Final Answer:
Allow inbound TCP on port 22 from source 203.0.113.5/32 -> Option DQuick Check:
Restrict SSH TCP 22 to office IP [OK]
- Allowing all IPs instead of specific IP
- Using UDP instead of TCP
- Opening wrong port for SSH
Ready to prove it?
Pass the test and this pattern moves unknown
