DEV Community

Damilare Joseph
Damilare Joseph

Posted on

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.

Please leave your questions and comments below. I will be happy to answer them.

Top comments (6)

Collapse
 
ydekel6 profile image
ydekel6 • Edited

my computer uses windows. should I insert in IdentityFile the full path including c:/? also, should I use the .pem or .ppk file?
I keep getting the following error:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
[18:37:12.028] > The process tried to write to a nonexistent pipe.
[18:37:12.341] "install" terminal command done
[18:37:12.342] Install terminal quit with output: The process tried to write to a nonexistent pipe.
[18:37:12.342] Received install output: The process tried to write to a nonexistent pipe.
[18:37:12.343] Resolver error: The process tried to write to a nonexistent pipe

Collapse
 
efleurine profile image
Emmanuel

did you ever solved it?

Collapse
 
gcrumpley profile image
Guy Crumpley

You just need to enter the full path IN QUOTES using the normal backslashes. :)

Collapse
 
marcusturewicz profile image
Marcus Turewicz

Thanks for the post.

I was getting the error "permission 0644 are too open ssh" because I hadn't set my pem file to be only readable by me:

stackoverflow.com/a/9270753/6939988

After this, it worked.

Collapse
 
gcrumpley profile image
Guy Crumpley • Edited

Fun fact: OpenSSH client will hang on the initial connection UNLESS you either: 1) Import the remote SSH server as a "known host"; OR, 2) Relax your security for the initial connection (below).

DISABLE StrictHostKeyChecking in your ssh config file in order to avoid initial connection failures. Something like this (only the last line is relevant to solving this problem):

Host [Your Connection Name]
HostName [AWS external DNS]
User [Typically "ec2-user for community AMIs, but Ubuntu user is "ubuntu"]
IdentityFile [Full file path with quotes if spaces are included]
StrictHostKeyChecking no

Collapse
 
imspikey profile image
imspikey

Thanks that was the most accurate explanation and the only tutorial that worked for me