How to SSH into Azure VM: Simple Steps to Connect
To SSH into an Azure VM, use the
ssh command with your VM's public IP address and username, like ssh azureuser@your_vm_ip. Ensure your VM allows SSH traffic on port 22 and you have the correct private key if using SSH keys.Syntax
The basic syntax to SSH into an Azure VM is:
ssh [username]@[public-ip-address]: Connects to the VM using the specified username and IP.-i [path-to-private-key](optional): Specifies the SSH private key file if key authentication is used.
Make sure port 22 is open in the VM's network security group to allow SSH connections.
bash
ssh azureuser@20.50.40.30 ssh -i ~/.ssh/id_rsa azureuser@20.50.40.30
Example
This example shows how to SSH into an Azure VM named myVM with username azureuser and a private key stored at ~/.ssh/id_rsa. The VM's public IP is 20.50.40.30.
bash
ssh -i ~/.ssh/id_rsa azureuser@20.50.40.30Output
Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-1045-azure x86_64)
azureuser@myVM:~$
Common Pitfalls
- Port 22 blocked: The VM's network security group might block SSH traffic. Always check and allow inbound port 22.
- Wrong username: Use the username set when creating the VM, often
azureuseror custom. - Missing or wrong private key: If using SSH keys, ensure the private key matches the public key on the VM.
- Using password authentication: Azure VMs often disable password login by default for security.
bash
Wrong way: ssh user@20.50.40.30 Right way: ssh azureuser@20.50.40.30 Wrong way: ssh -i ~/.ssh/wrong_key azureuser@20.50.40.30 Right way: ssh -i ~/.ssh/id_rsa azureuser@20.50.40.30
Quick Reference
Remember these quick tips when SSHing into Azure VMs:
- Use the correct username and public IP.
- Open port 22 in the VM's network security group.
- Use the right private key file if using SSH keys.
- Use Azure CLI
az vm showto find your VM's IP.
Key Takeaways
Use
ssh username@public-ip to connect to your Azure VM.Ensure port 22 is open in the VM's network security group for SSH access.
Use the correct SSH private key if your VM requires key authentication.
Check your VM's username and public IP before connecting.
Azure VMs often disable password login; use SSH keys for secure access.