This blog post will show how to connect to a Linux VM running in Azure using SSH from Visual Studio Code (VS Code).
When we create a Linux virtual machine (VM) in Azure, we are provided with the option to connect to it using SSH protocol and can access the VM over the internet using port 22. In this post, I will explain how to safely SSH to a Ubuntu Linux VM using an SSH key generated by Azure.
In this post, I’m going to SSH to a Ubuntu Linux VM using an SSH Key generated by Azure, which is the safest method of connecting.
SSH Config File
When creating a VM in Azure, Azure generates a private key for us to download. The private key has a file extension of .pem.
Save the file on your machine and open VS Code.
By default, if you are using a Windows machine like me, your SSH configuration file is located at
C:\users\YOURUSERNAME\.ssh\config
Open the file and add the following entry to it (you will need the details of your VM).
Host linuxVM
HostName 10.x.x.x
User azureuser
IdentityFile ~/.ssh/linux.pem
Save the file and Open VS Code.
From the bottom left corner, click on Connect
Select Connect to Host
Select the name of the VM you configured on the config file (Host)
Follow the prompt until you connect to the VM. Once connected you will see the host’s name in the connection icon.
Related Articles
- Create an SSH Config File and Save Connections
- Use SSH To manage Linux VM From PowerShell
- Question: How To Enable SSH On ESXi 5.0
- Reset SSH Key On Azure Linux VM
- How to Use SSH Keys To Login To a Linux Host
- Enable Microsoft 365 Safe Attachments With PowerShell