0
0
Azurecloud~5 mins

SSH and RDP access in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
SSH and RDP let you connect to virtual machines in the cloud. SSH is for Linux machines and RDP is for Windows machines. They help you manage your servers remotely as if you were sitting in front of them.
When you want to securely connect to a Linux virtual machine to install software or check logs.
When you need to access a Windows virtual machine to use graphical tools or configure settings.
When you want to troubleshoot a server that is not responding to your application requests.
When you want to run commands or scripts directly on your cloud server.
When you need to transfer files securely between your computer and the cloud server.
Commands
This command creates a Linux virtual machine with SSH access enabled by generating SSH keys automatically.
Terminal
az vm create --resource-group example-rg --name example-linux-vm --image UbuntuLTS --admin-username azureuser --generate-ssh-keys
Expected OutputExpected
{ "fqdns": "", "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/example-rg/providers/Microsoft.Compute/virtualMachines/example-linux-vm", "location": "eastus", "name": "example-linux-vm", "powerState": "VM running", "resourceGroup": "example-rg", "zones": "" }
--generate-ssh-keys - Automatically creates SSH keys if none exist for secure login
--admin-username - Sets the username for SSH login
This command connects you to the Linux VM using SSH with the username azureuser.
Terminal
ssh azureuser@example-linux-vm.eastus.cloudapp.azure.com
Expected OutputExpected
Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-1045-azure x86_64) azureuser@example-linux-vm:~$
This command creates a Windows virtual machine with RDP access enabled using a username and password.
Terminal
az vm create --resource-group example-rg --name example-windows-vm --image Win2019Datacenter --admin-username azureuser --admin-password StrongP@ssw0rd123
Expected OutputExpected
{ "fqdns": "", "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/example-rg/providers/Microsoft.Compute/virtualMachines/example-windows-vm", "location": "eastus", "name": "example-windows-vm", "powerState": "VM running", "resourceGroup": "example-rg", "zones": "" }
--admin-password - Sets the password for RDP login
--admin-username - Sets the username for RDP login
This command opens port 3389 on the Windows VM to allow RDP connections.
Terminal
az vm open-port --resource-group example-rg --name example-windows-vm --port 3389
Expected OutputExpected
Network security group rule created successfully.
--port - Specifies the port number to open for RDP
This command opens the Remote Desktop Connection client to connect to the Windows VM using RDP.
Terminal
mstsc /v:example-windows-vm.eastus.cloudapp.azure.com
Expected OutputExpected
No output (command runs silently)
Key Concept

If you remember nothing else, remember: SSH is for secure command-line access to Linux VMs, and RDP is for graphical access to Windows VMs.

Common Mistakes
Trying to SSH into a Windows VM or RDP into a Linux VM.
SSH and RDP use different protocols and are designed for different operating systems.
Use SSH for Linux VMs and RDP for Windows VMs.
Not opening the correct network port (22 for SSH, 3389 for RDP) in the VM's firewall.
Without the port open, the connection will be blocked and fail.
Use Azure CLI commands to open the required ports before connecting.
Using weak or default passwords for RDP access.
Weak passwords can allow unauthorized access and compromise security.
Always use strong, unique passwords for RDP login.
Summary
Create Linux VMs with SSH keys for secure command-line access.
Create Windows VMs with username and password for RDP access.
Open the correct network ports to allow remote connections.
Use SSH command to connect to Linux VMs and RDP client to connect to Windows VMs.