Damilare Joseph

SSH to an EC2 instance from VS Code

Requirements:

  1. You must have VSCode or VSCode Insider installed.

  2. A running SSH server preferrable a linux server running on an EC2 instance.

  3. An SSH Client on your local system.

Steps to SSH on VSCode

a) Install the Remote extension pack on your vscode.

b) In VSCode, press F1 to open the command palette, and type connect.

c) Select Remote-SSH: Connect to Host. This will bring out options for you to add or configure SSH Hosts.

d) Select configure SSH Hosts. This will give you options to create a config file. For mine I selected the first option /Users/username/.ssh/config.

This will open a new file for you were you can create an ssh config.

The Host is any name you want VSCode to use to recognize your file. The HostName is the public dns of your EC2 instance or public ip address of your server. The User is the username of your server. The IdentityFile is the path to your ssh key which you got when you created your EC2 instance.

Press F1 again to open the command palette. Select Remote-SSH and this time, you should see the Host you just created. As you can see in the image below, mine is the personal that appears.

Select yours, and it will attempt connecting to it. When it has successfully connected, you will see something like this in the bottom left corner of your VSCode.

Congrats!! 🥳 You have successfully connected your remote server to VSCode. Now you can start working on those files you want.

If it didn't connect, don't despair, it will output some messages in the VSCode debug console. From there, you can see what's wrong.