DEV Community

Cover image for Connect to your Linux EC2 instance using SSH + Visual Studio Code
Adrian Mudzwiti for AWS Community Builders

Posted on • Edited on • Originally published at adrianthegreat.com

4 1

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.

Pre-requisites:

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
Enter fullscreen mode Exit fullscreen mode

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}
Enter fullscreen mode Exit fullscreen mode

SSH Config

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.

Remote Explorer

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

SSH Fingerprint

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

Session

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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post