Connect to your Linux EC2 instance using SSH + Visual Studio Code

Connect to your Linux EC2 instance using SSH + Visual Studio Code

In this blog post i’ll show you how to configure VS Code to allow remote development for Linux based EC2 instances hosted on AWS.

On the rare occasion that I need to connect to Linux based EC2 instances, I normally use Session Manager through the AWS Management Console or use the Session Manager plugin for AWS CLI.

Recently I had to take part in a web development project, the remote development environment ran on an EC2 instance. I had no desire of using the VI text editor (that’s too hardcore) and preferred to use VS Code from my MacBook Pro as it has some pretty useful extensions installed.


AWS Account
Visual Studio Code

This blog post assumes the reader has some basic knowledge of SSH and is using macOS or a Linux based OS.

To get started you’ll need an SSH Config file, on macOS it can be located in the ~/.ssh directory. I’ve created a new EC2 instance, new key-pair and moved the private key from the Downloads directory to the ~/.ssh directory.

To modify the config file, use the below commands:

cd ~/.ssh
code config

Let’s add a new section containing our EC2 details. The section must conform to the below structure:

Host {Friendly Name Used for identification}
HostName {Public DNS of EC2 instance}
User {username}
IdentityFile {location of private key}

Next you’ll need to install the Remote - SSH Extension in VS Code.

Once installed, you’ll notice the Remote Explorer icon appear on the Activity Bar, select the icon, this will bring the Primary Side Bar into view.

From the dropdown, select SSH Targets, a list of SSH Targets will be listed.

Right-click the SSH target, you’ll be presented with 2 options: Connect to Host in Current Window and Connect to Host in New Window.

You will then be prompted to verify the fingerprint. Select Continue.

On the bottom left corner of VS Code, the Status bar will indicate the connection status.

That concludes this blog post where I showed how to configure VS Code for Remote Development for Linux based EC2 instances hosted on AWS.


Adrian Mudzwiti

Posted on


Updated on


Licensed under