With this 45000 Star tool, you can run the strongest Editor VS Code in the browser!

[introduction]: a tool that allows you to run VS Code in the browser.

brief introduction

Code server is an online editor based on VS Code. It runs VS Code on any machine anywhere and accesses it in the browser. Any device can access VS Code through the browser, so as to realize remote online development.

Its highlights are:

  • Provide users with a consistent code development environment;
  • Accelerate testing, compiling and downloading based on server;
  • Extend the battery life of personal computers and transfer intensive tasks to servers;

Officials suggest that the server should have at least 1 GB of memory and 2 cores.

The project address is:

https://github.com/cdr/code-server

Download and install

Script installation

The official provides a script to install code server for Linux, macOS and FreeBSD.

  • First, try to print the details of the installation process, which will not be installed:
curl -fsSL https://code-server.dev/install.sh | sh -s -- --dry-run
  • Real installation:
curl -fsSL https://code-server.dev/install.sh | sh

Independent installation

The official provides an independent compressed installation file. Download the version of the corresponding server and decompress it to use.

// Visit after completion http://127.0.0.1:8080 , the password is saved in ~ / config/code-server/config.yaml configuration file
mkdir -p ~/.local/lib ~/.local/bin
curl -fL https://github.com/cdr/code-server/releases/download/v$VERSION/code-server-$VERSION-linux-amd64.tar.gz \
  | tar -C ~/.local/lib -xz
mv ~/.local/lib/code-server-$VERSION-linux-amd64 ~/.local/lib/code-server-$VERSION
ln -s ~/.local/lib/code-server-$VERSION/bin/code-server ~/.local/bin/code-server
PATH="~/.local/bin:$PATH"
code-server
# Your password is in 

Docker installation

# This will start a code server container and pass http://127.0.0.1:8080 visit
mkdir -p ~/.config
docker run -it --name code-server -p 127.0.0.1:8080:8080 \
  -v "$HOME/.config:/home/coder/.config" \
  -v "$PWD:/home/coder/project" \
  -u "$(id -u):$(id -g)" \
  -e "DOCKER_USER=$USER" \
  codercom/code-server:latest

Access configuration

The official strongly recommends not to expose the code server that does not require authentication or encryption on the public network. By default, the code server will use password authentication and obtain the password from the configuration file (~ /. Config / code server / config. Yaml). It only listens to requests from localhost to avoid exposing itself. If you want to use code server safely from different places, you can use the following methods.

SSH forwarding

This method is officially recommended because there is no need for any additional settings, only an SSH service on the remote machine. The disadvantage is that it cannot be accessed on devices without SSH client, such as iPad.

  • First, enter the instance via ssh and edit the code server configuration file to disable password authentication:
# Replace "auth: password" with "auth: none"
sed -i.bak 's/auth: password/auth: none/' ~/.config/code-server/config.yaml
  • Restart:
sudo systemctl restart code-server@$USER
  • The local computer runs the following command to forward the local port 8080 to the remote instance:
# -N disables executing a remote shell
ssh -N -L 8080:127.0.0.1:8080 [user]@<instance-ip>

You can now pass it on your local computer http://127.0.0.1:8080 Access code server

Use Let's Encrypt

  1. First, you need to buy a domain name and recommend Google Domains
  2. Bind the code server instance IP to the domain name
  3. Install nginx:
sudo apt update
sudo apt install -y nginx certbot python3-certbot-nginx
  1. Put the following in the / etc / nginx / sites available / code server file:
server {
    listen 80;
    listen [::]:80;
    server_name mydomain.com;

    location / {
      proxy_pass http://localhost:8080/;
      proxy_set_header Host $host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;
    }
}

mydomain.com is the domain name you use.

  1. Enable configuration
sudo ln -s ../sites-available/code-server /etc/nginx/sites-enabled/code-server
sudo certbot --non-interactive --redirect --agree-tos --nginx -d mydomain.com -m me@example.com

among me@example.com Use your own actual email. visit https://your-domain-name You can access code server.

\6. Caddy can be used to replace the above 3 to 5. For details, please refer to the official website.

Use self signed certificate

It is recommended to use this as a last resort because the self signed certificate does not apply to the iPad and may lead to other strange problems.

First ssh into the code server server and edit the configuration file to use the randomly generated self signed certificate:

# Replaces "cert: false" with "cert: true" in the code-server config.
sed -i.bak 's/cert: false/cert: true/' ~/.config/code-server/config.yaml
# Replaces "bind-addr: 127.0.0.1:8080" with "bind-addr: 0.0.0.0:443" in the code-server config.
sed -i.bak 's/bind-addr: 127.0.0.1:8080/bind-addr: 0.0.0.0:443/' ~/.config/code-server/config.yaml
# Allows code-server to listen on port 443.
sudo setcap cap_net_bind_service=+ep /usr/lib/code-server/lib/node

Restart:

sudo systemctl restart code-server@$USER

FAQ

There are some problems when using code server. For example, what is the difference with VS Code? How do i disable telemetry? How to debug the code server? These questions can be found in the official FAQ document:

https://github.com/cdr/code-server/blob/main/docs/FAQ.md#how-should-i-expose-code-server-to-the-internet

Open source outposts share popular, interesting and practical open source projects on a daily basis. Participate in maintaining the open source technology resource library of 100000 + Star, including Python, Java, C/C + +, Go, JS, CSS and node js,PHP,. NET, etc.

Added by warpoet on Fri, 28 Jan 2022 08:01:29 +0200