Using VSCode remotely on an EC2 instance

Christy Jacob
4 min readFeb 27, 2020

--

I recently started using EC2 for my deep-learning workloads and I was extremely bothered by the fact that I have to use either vi or some other boring IDE. Trust me, these editors are great but achieving feats like debugging and easily navigating between files, getting to view the folder structure etc. is much more elegant on an IDE.

My IDE of choice is VSCode and I haven’t found anything to hate about it. It is lightweight, has IntelliSense support for multiple languages and has some really amazing features that puts VSCode in a totally different ballpark. I’m talking about the LiveShare feature of VSCode that lets you collaborate with your team easily on projects while allowing you to be on a voice chat at the same time, is insane!

Another mind-blowing feature and which we’re going to focus on here, is its support for remote development. This basically means, you can ssh into any remote instance on any cloud service and get a VSCode instance up and running with absolutely no setup required on the instance!!!

I know what you’re thinking. This is too good to be true. So let me walk you through the steps required to set it up.

Create an instance

For the sake of this tutorial, I’m going to stick with AWS EC2, but this is applicable to any remote instance. VSCode has a tutorial on how you can set it up on an Azure instance.

You can follow the instructions here to set up an EC2 instance. This tutorial sets up an Oracle Image. Ensure that you choose the image of your choice.

Make sure that you edit the inbound rules in your security group to allow SSH on port 22 from your current IP.

Install the Remote SSH Extension

If you haven’t already, download and install VSCode for your OS from here.

You can then search for the extension “Remote-SSH” in the VSCode marketplace.

Once Installed, you should see a new Status bar item at the far left.

The status item can be used to quickly open the Remote SSH settings. Click on the status item.

Open The Configuration file

Choose the config file corresponding to the current user. (1st Option in this case.)

Enter the following details

  • Host (aws-ec2) is just a name that will appear in VS Code. It can be any name.
  • HostName is the server’s host or IP.
  • User is the Ubuntu username.
  • IdentityFile is the path to the private key.

To obtain the HostName and User for your instance, navigate to your EC2 console. Right Click on an instance > Connect. This will open up a dialog like

Here, ubuntu is the User and ec2–44–229–243–8.us-west-2.compute.amazonaws.com is the HostName.

Save the configuration file. Now you’re ready to connect to your Host. Click the status item on the bottom left and select Connect to Host. You should now be able to see your host.

That’s it. You are good to go! You can also browse and open folders on the remote home directory with File > Open Folder.

References

The images and gifs used in this article have been obtained from

  1. https://github.com/microsoft/vscode-remote-release
  2. https://code.visualstudio.com/remote-tutorials/ssh/getting-started

--

--