This tutorial shows you how to connect to a Linux virtual machine (VM) hosted in Azure using Secure Shell (SSH). SSH is a secure cryptographic network protocol for operating network services securely over an unsecured network.
Always ensure your SSH client and server configurations are up-to-date and follow security best practices to protect your VM from unauthorized access.
You need the public IP address of your Azure Linux VM to establish an SSH connection. You can find this information in the Azure portal:
Launch your SSH client application on your local machine.
Use the following SSH command syntax, replacing {username}
with your VM's login username and {publicIpAddress}
with the public IP address you found in Step 1:
ssh {username}@{publicIpAddress}
For example, if your username is azureuser
and your VM's public IP address is 203.0.113.5
, the command would be:
ssh azureuser@203.0.113.5
If this is your first time connecting to this VM, you might see a message like:
The authenticity of host '203.0.113.5 (203.0.113.5)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Type yes
and press Enter to continue. This adds the VM's host key to your known hosts list.
You will be prompted to enter the password for your VM's login username. Type your password and press Enter. Note that for security reasons, the password characters will not be displayed as you type.
If you used SSH keys for authentication during VM creation, you will not be prompted for a password. Instead, your SSH client will use your private key to authenticate.
Once authenticated, you will see the command prompt for your Azure Linux VM. You can now execute commands on your VM.
azureuser@myvm:~$
When you are finished working on your VM, you can disconnect by typing:
exit
or by pressing Ctrl+D
.
~/.ssh/known_hosts
file.For more advanced connection scenarios, such as using Bastion or connecting via private IP addresses, please refer to the Azure documentation on VM networking.