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:
- Generate your ssh key using the
- Display the contents of your public key using the
catcommand. Copy this key.
- Log into AWS Lightsail. Open an ssh window for your instance.
- Navigate to the ssh folder:
- Edit the authorized_keys file:
- Paste your public key at the bottom of the authorized_keys file and save.
- Download VS Code if you haven’t done so already: https://code.visualstudio.com/download
- In VS Code, install the ‘Remote-SSH’ extension published by Microsoft.
- You’ll notice a green SSH button gets added to the bottom left of VS Code.
- Click this button and select ‘Open SSH Configuration File’.
- Then select your main SSH config file. The path should end with ‘/.ssh/config’
- 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:
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.