
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:
https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-ssh-using-terminal
https://www.bluehost.com/help/article/ssh-access
https://www.godaddy.com/help/connect-to-my-server-with-ssh-secure-shell-4943
https://support.hostinger.com/en/articles/1583245-how-can-i-connect-to-my-account-via-ssh
https://help.dreamhost.com/hc/en-us/articles/216041267-SSH-overview
https://www.hostgator.com/help/article/how-do-i-get-and-use-ssh-access
https://www.siteground.com/kb/access-site-ssh-connection/
https://wpengine.com/support/ssh-gateway/
https://www.a2hosting.com/kb/getting-started-guide/accessing-your-account/using-ssh-secure-shell
Here are the steps. Keep in mind these steps vary depending on your hosting provider:
- Generate your ssh key using the
ssh-keygen
command. - Display the contents of your public key using the
cat
command. Copy this key. - Log into AWS Lightsail. Open an ssh window for your instance.
- Navigate to the ssh folder:
cd .ssh
- Edit the authorized_keys file:
nano authorized_keys
- 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.
Leave a Reply