VS Code Remote SSH Extension

Use VS Code SSH with AWS Lightsail

In this post I cover how to set up the VS Code ‘Remote – SSH’ extension published by Microsoft with AWS Lightsail. This will allow you to SSH into your instance and use all of VS Code’s powerful features.

This setup in general applies to any machine you are able to access through a hosting provider. AWS Lightsail provides a quick ssh connection button. If you don’t have that feature with your hosting provider you will need to ssh into your machine using a different technique.

With some hosts such as Blue Host you can create an ssh key and add that key directly in your cpanel. Here are some resources on setting up ssh keys with some common hosting providers:

Here are the steps. Keep in mind these steps vary depending on your hosting provider:

  1. Generate your ssh key using the ssh-keygen command.
  2. Display the contents of your public key using the cat command. Copy this key.
  3. Log into AWS Lightsail. Open an ssh window for your instance.
  4. Navigate to the ssh folder: cd .ssh
  5. Edit the authorized_keys file: nano authorized_keys
  6. Paste your public key at the bottom of the authorized_keys file and save.
  7. Download VS Code if you haven’t done so already: https://code.visualstudio.com/download
  8. In VS Code, install the ‘Remote-SSH’ extension published by Microsoft.
  9. You’ll notice a green SSH button gets added to the bottom left of VS Code.
  10. Click this button and select ‘Open SSH Configuration File’.
  11. Then select your main SSH config file. The path should end with ‘/.ssh/config’
  12. Next you will enter your Host, HostName, User and Identity File.

Your Host is simply a name you are giving the connection.

Your HostName is the ip address of the machine you are connecting to. In this case our Lightsail instance.

The User is your SSH username. In our case this is ‘bitnami’.

The IdentifyFile is where your private SSH key that you generated in step 1 is located.

 

It should look something like this:

SSH Config File

To add a new website. Simply copy this block, paste it, then update the details.

Assuming you have entered all the details correctly and there are no other errors, you should now be able to connect to your Lightsail instance using VS Code.

Click the green SSH button again and select ‘Connect to Host’. Select the name of the website that you just added. If you added a password to your ssh key you will be prompted to enter this. If not you should automatically connect.

Now you can open a folder using the ‘File Explorer’ button in the top left. If you added a password to your SSH key you will be prompted to enter it one more time.

Now you’re connected! Enjoy the powerful features of VS Code with your AWS Lightsail instance.

Leave a Reply

Your email address will not be published.