loading...

SSH to an EC2 instance from VS Code

dre4success profile image Damilare Joseph ・2 min read

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.

Posted on by:

dre4success profile

Damilare Joseph

@dre4success

A technical leader, I work with diverse teams to deliver enterprise projects while managing client’s expectations and making sure projects are delivered right and on time.

Discussion

pic
Editor guide
 

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

 

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.