Remote VS Code
Introduction
One of the coolest things I have recently found is the code-server project by cdr. It enables users to run Visual Studio Code inside remote servers! This blog post describes the procedure for setting all this up.
Setup
Prerequisites
- This setup requires you to have a remote UNIX server. I have tested this using an AWS EC2 instance, but it will work with similar solutions from other cloud vendors too.
- Your remote server should have enabled access from your IP. In case of AWS, you can do this in the following way:
- Go to your AWS console and open the EC2 service.
- Select the instance that you want to run VSCode on.
- In the details pane below, look at the inbound and outbound rules for this instance.
- If it has been allowed access from everywhere, better delete that rule for security.
- Go to the security group added to this instance and edit the inbound rules.
- Add a new rule and select type as
HTTPSand IP asMy IPfrom the dropdown menu - Do this again for
HTTP. - save this setting, and now this instance can only be accessed from your IP.
Bash script for automated setup
- Now that we have ensured access to our server, we need to install
code-serverto our server. - Make sure that you are able to SSH to your instance.
- Now, simply download the script below to your instance and run it.
https://gist.github.com/manparvesh/f7890a6031e076f7b4587bcfdcd4eeb2
About the script
The above script performs the following actions:
- Downloads the specified version of
code-serveron the instance - Sets up secure connection for this server
Configuring the script
- In case a newer version of code-server is released and you want to use that, you can change the version inside the script by changing the
CODE_SERVER_VERSIONvariable. - For running this script on a macOS server, change the
CODE_SERVER_ARCHvariable
Running the server
Now that our server is configured, we can run our server using the following server:
sudo ./code-server -p 80 --cert=~/certs/MyCertificate.crt --cert-key=~/certs/MyKey.key "~"
Using the server
Now everything is setup and VSCode server is running to. Go ahead and open the following link in your browser:
https://<your instance public IP>:80/
You will be asked for a password to enter, which you will find in the server logs while running it. Now enjoy making changes in the server using this setup! :smile: