SSH and FTP access from VS Code to a Remote Machine

If you have a VM somewhere in the cloud, like in GCP or AWS, you probably want to have FTP and SSH access to it so that you can upload files and run commands easily.

If you are using GCP specifically, then you should be able to access your VM’s console from the browser through your Compute Engine dashboard.

However sometimes this would not be enough for being productive. If you need to upload a bunch of files, you would use FileZilla to do that and if you need to edit these files, you can use VS Code. This guide will walk you through configuring these tools to work with a GCP VM.

SSH Keys

On a Mac, open the Terminal. Use the following command and refer to the example:

ssh-keygen -t rsa -f [path_and_file_name_no_extension] -C [user_name]@[ip_address]

ssh-keygen -t rsa -f /Users/john/Desktop/vm2_key -C

You will have to enter a passphrase and remember it.

After the command is successfully complete, two files will be generated at the specified location:

  1. A file with no extension but the name that you specified – your PRIVATE key. Begins with “—–BEGIN OPENSSH PRIVATE KEY—–“
  2. A file with a .pub extension – your PUBLIC key. Begins with ssh-rsa, ends with username@ip_address

Type in the Terminal and copy the output:
cat []

In GCP, go to Hamburger menu -> Compute Engine -> Metadata
Navigate to SSH Keys tab
Edit -> Add item
Paste your PUBLIC key here


Now go to FileZilla

Click on the icon in the top left corner:

Click New site

On the General tab:
Protocol: SFTP
Host: your IP
Logon Type: Key file
User: your username that you created your public key for
Key file: your PRIVATE KEY location (it will generate a new file for you automatically)

Now you can connect to the server to upload files through FileZilla

You can right-click any file on the server and hit View/Edit. Then choose a default editor (VS Code works well) and you can edit the file in that editor, then Filezilla will ask you if you want the edited file to be uploaded to the server.

Helpful tip:

In Filezilla, go to Edit -> Settings
Then on the left click: Transfers
On the right: Maximum simultaneous transfers: 10
This will allow you to upload/download multiple files way faster

VS Code

In order SSH into your VM through VS Code, you’ll need to install the Remote – SSH extension.

Then navigate to /Users/your_username/.ssh and find the config file
In that config file, create a new entry with the following format:

HostName 99.99.999.99
IdentityFile /Users/your_username/Desktop/vm2_key
User your_vm_username
PubKeyAuthentication yes

After this, something like this should appear in your remote explorer in VS Code:

You can access and edit your remote files here now after you connect.

Leave a Reply

Your email address will not be published. Required fields are marked *