Running Visual Studio Code on a VPS with openSUSE
The following article has been contributed by Dmitri Popov, Technical Writer at the SUSE Documentation team.
If you happen to use Visual Studio Code as your preferred writing and coding tool and you want to access it from anywhere, code-server can come in rather handy. Install the application on a server, and you can use your favourite IDE in a browser. Pair code-server with an inexpensive virtual private server (VPS), and you’ll have your very own cloud-based IDE that you can use from any machine.
To set up your own VPS-based IDE powered by Visual Studio Code, you need two things: a VPS instance and a domain name. A VPS needs to have at least 1GB RAM and two cores, and you should be able to install openSUSE on it. There are plenty of domain name registrars to choose from, but you should pick the one that allows you to modify DNS records. The following instructions assume that you have a VPS instance with a fresh installation of openSUSE 15.2.
Create a User
Normally, a VPS instance gives you only root access. So the first step is to add a regular unprivileged user. To create the vscode user, run the following commands:
useradd -m vscode passwd vscode zypper update zypper install sudo usermod -aG wheel vscode
These commands not only create a new user, but also add it to the wheel group, thus allowing it to run commands with root privileges. Now, log out and log in as the vscode user.
Install and Enable code-server
code-server includes an installer script that does the donkey job for you. It’s a good idea to do a dry run using the
curl -fsSL https://code-server.dev/install.sh | sh -s -- --dry-run
command first. If everything works properly, install and enable the code-server by running the following commands:
curl -fsSL https://code-server.dev/install.sh | sh sudo systemctl enable --now code-server@$USER
Open then the ~/.config/code-server/config.yaml file for editing and change the default password.
Now you have the code-server up and running, but it only accepts local connections, which is not particularly useful.
Access Your code-server Instance
To make the code-server instance accessible from the outside world, you need to map a domain name to the VPS and install the Caddy web server with HTTPS support.
The most straightforward way to map a domain name to the IP address of your VPS is to add an A record. Most domain name registrars allow you to do that via a web interface. Installing Caddy is a matter of running the following commands:
sudo zypper addrepo 'https://copr.fedorainfracloud.org/coprs/g/caddy/caddy/repo/opensuse-leap-15.1/group_caddy-caddy-opensuse-leap-15.2.repo' sudo zypper refresh sudo zypper install --allow-vendor-change caddy
Open the /etc/caddy/Caddyfile for editing and replace its entire content with the following two lines (replace mydomain.com with the actual domain name):
mydomain.com reverse_proxy 127.0.0.1:8080
Enable then the Caddy server:
sudo systemctl enable --now caddy
Point now your browser to https://mydomain.com (replace mydomain.com with the actual domain name). Log in using the password you specified in the config.yaml file, and you should see Visual Studio Code in all its beauty.
Finally, if you want to transplant your existing settings to code-server, copy the ~/.config/Code/User/settings.json file from your local machine into the /home/vscode/.local/share/code-server/User/ directory on the VPS.
No comments yet