Contents

Set Up VS Code for Remote Development

Background

Remote development is crucial for many scenarios. If we have a Windows PC but need to develop our projects on Linux, remote development is the right way to go. VS Code is very easy to set up for remote development. Let’s dive into it.

Prerequisite

A virtual machine is already set up, the SSH tunnel is working between your local machine and the VM.

VS Code set up

First, install the Remote - SSH extension on your VS Code. https://raw.githubusercontent.com/williamyuaus/blog-img/master/img/202402091620879.png

Then, click the icon on the bottom left, and choose Connect to host on the top menu.

There will be a list of hosts present on the list. If your SSH tunnel is set up correctly, you can select the host and VS Code can handle the rest of the work. If you got error of the connection. You may need to configure the hosts. Select Configure SSH Hosts and click the SSH config file (normally would be ~/.ssh/config).

One common mistake is that the SSH requires the pem file to identify the identity. So, we need to add the path of the pem file in the config file. An example could be:

Host 16.16.16.16
  HostName 16.16.16.16
  IdentityFile ~/.ssh/dev-vm.pem
  User ubuntu

After the configuration, restart this step again, you may connect the VM successfully.

If the SSH connection is established, the hostname will show on the bottom left icon, and you can enjoy the remote development now.

https://raw.githubusercontent.com/williamyuaus/blog-img/master/img/202402091633965.png