Skip to content

Instantly share code, notes, and snippets.

@xTCry
Last active June 22, 2024 19:03
Show Gist options
  • Save xTCry/ad0310f851ab8dd73f332ae526b60af5 to your computer and use it in GitHub Desktop.
Save xTCry/ad0310f851ab8dd73f332ae526b60af5 to your computer and use it in GitHub Desktop.
Fast install VSCode - Code-server

Fast install

Run by non-root user

curl -fsSL https://code-server.dev/install.sh | sh

Run the code-server command to start the service and generate the config, then you can immediately complete it

We look at the password in the config file...

nano ~/.config/code-server/config.yaml

We can set a public IP if we don't use nignx

bind-addr: 0.0.0.0:8084

Run service

sudo systemctl enable --now code-server@$USER

If need to open port

By firewall

sudo firewall-cmd --zone=public --add-port=8084/tcp
sudo firewall-cmd --reload

By iptables

sudo iptables -I INPUT 1 -p tcp --dport 8084 -j ACCEPT
service iptables save

Custom install (old)

wget https://github.com/cdr/code-server/releases/download/{VERSION}/code-server{VERSION}-linux-x86_64.tar.gz
wget https://github.com/cdr/code-server/releases/download/2.1665-vsc1.39.2/code-server2.1665-vsc1.39.2-linux-x86_64.tar.gz
tar -xvzf code-server2.1665-vsc1.39.2-linux-x86_64.tar.gz
rm code-server2.1665-vsc1.39.2-linux-x86_64.tar.gz
mv code-server2.1665-vsc1.39.2-linux-x86_64 code-server

cd code-server
sudo chmod +x code-server
./code-serve --port 8443 --auth none

(Test) Connect to http://{SERVER_IP}:8443

nano code-server.sh

export PASSWORD="myPassworrd"
{PATH_TO_CODESERVER_DIR}/code-server --port 8443 --auth password
sudo chmod +x ./code-server.sh

Create the service.

sudo nano /lib/systemd/system/code-server.service
[Unit]
Description=VS Code Server IDE
After=network.target

[Service]
Type=simple
Restart=on-failure
RestartSec=10

ExecStart=/bin/bash {PATH_TO_CODESERVER_DIR}/code-server.sh $(pwd)

StandardOutput=file:/var/log/code-server-output.log
StandardError=file:/var/log/code-server-error.log

[Install]
WantedBy=multi-user.target
sudo systemctl enable code-server
sudo systemctl start code-server
sudo systemctl status code-server

Nginx config

server {
	listen 80;
	server_name {YOUR_DOMAIN};

	# If use https
	#listen 443 ssl;
	#ssl_certificate /etc/letsencrypt/live/{YOUR_DOMAIN}/fullchain.pem;
	#ssl_certificate_key /etc/letsencrypt/live/{YOUR_DOMAIN}/privkey.pem;

	# If need redirect http to https
	#if ($ssl_protocol = "") {
	#	rewrite ^/(.*) https://$server_name/$1 permanent;
	#}
	
	location / {
		proxy_pass http://localhost:8443/;

		# Standard proxying headers
		proxy_set_header Host $host;
		proxy_set_header Accept-Encoding gzip;

		# Enable proxy websockets
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment