Friday 5 March 2021

Open SSH Connection in VS Code to Azure Ubuntu VM to Perform Remote Development

VS Code is a useful development tool which can be used on any platform to develop code in any language of your preference. In an Azure Ubuntu VM without setting up the desktop remote access, you may want to perform development work and may want to perform debugging activities, as you are doing with local files in a Linux environment. You can use ssh extension for VS Code and create ssh connection to a VM in Azure or anywhere over ssh and work connected to the remote Linux, MacOS or Windows machines via VS Code. Let’s look at steps to connect to a Ubuntu VM on Azure using a VS Code in Windows 10 local machine.

As a prerequisite create a Ubuntu VM and enable ssh with a key pair public key may be generated from putty for Windows.

Open up VS Code and search for ssh extension and install it.


Once the extension is installed in the bottom left corner of the VS Code you can see Open a Remote Window option.


Clicking on the Open a Remote Window shows couple of command options you can take. You can either open a configuration file or try to open a connection to a remote machine.


Once open connection to remote host option selected, you can add a new SSH host.


You can provide the ssh username@ipoftheazureubunutuvm format to gain ssh access to the Ubuntu VM in Azure.


You need to apply the new host to a config file. You should pick the option of using your user config file instead of the common config file for the machine in Program data.


Opening up the config fie now shows your host is added as Azure VM IP with the user name provided.


Before you try to connect VS Code to Ubuntu VM in Azure if you have used putty to generate the key pair you need to convert the putty generated private key to open ssh key to ensure it can be used with VS Code. You can do this via putty gen by loading the private key of the keypair and export as open ssh key.


Once the key file is saved as open ssh key file you need to ensure only you are the owner of the file, only you have access to the open ssh key file and no other user have any permissions on it. You can do this in using Windows file security options.


We can now try to open a connection to host by clicking on Open a Remote Window option where we will see the IP of the Azure VM.


Once clicked on the IP you will see the selection option for OS type in the remote VM. We can select Linux here.


Confirm that you want to continue.


Enter the paraphrase which you have sued to secure the private key when generating and saving it.


VS Code will be connecting with the Ubuntu machine and you are now having secure ssh connection to the VM and can perform remote development using VS Code on the Ubuntu VM in Azure, which we will be looking at in a next post.

No comments:

Popular Posts