install code server on ubuntu
using vscode in browser
install code server
1 | sudo apt update |
config code server
配置文件 ~/.config/code-server/config.yaml
密码是你登录时需要输入的
1 | bind-addr: 0.0.0.0:8082 |
check running
on one terminal, just type code-server
, it will automatically using config file listed above
on another terminal, type
1 | curl http://localhost:8082 # ok if local-machine alright |
more
add autostart service
edit service file /etc/systemd/system/my-code-server.service
1 | [Unit] |
start service: sudo systemctl start my-code-server
set autostart: sudo systemctl enable my-code-server
xray forward
add xray config file xray-rootdir/conf/99_code-server.json
this wil redirect incoming 0.0.0.0:7401 into localhost:8082
1 | { |
enable SSL Certificate
using certbot to generate certs
1
2
3
4
5
6
7sudo apt instal certbot
sudo certbot certonly --standalone -d www.yourdomain.com
# Successfully received certificate.
# Certificate is saved at: /etc/letsencrypt/live/www.yourdomain.com/fullchain.pem
# Key is saved at: /etc/letsencrypt/live/www.yourdomain.com/privkey.pem
# This certificate expires on 2024-03-02.
# These files will be updated when the certificate renews.change service to run as root
vim /etc/systemd/system/my-code-server.service1
2
3
4
5
6
7
8
9
10[Unit]
Description=Code Server
[Service]
User=root
ExecStart=/usr/bin/code-server
Restart=always
[Install]
WantedBy=multi-user.targetchange code-server config
1
2
3
4
5
6bind-addr: 0.0.0.0:8082
auth: password
log: debug
password: yourdomain
cert: /etc/letsencrypt/live/code.yourdomain.com/cert.pem
cert-key: /etc/letsencrypt/live/code.yourdomain.com/privkey.pemrestart service
1
2sudo systemctl daemon-reload
sudo systemctl restart my-code-server.service
enable SSL Certificate( as normal user)
same to enable-ssl-certificate, generate keys first, note cerbot keep multi version keys for same domain name, see
ll /etc/letsencrypt/live/code.yourdomain.com/cert.pem
copy cert files
1
2
3# copy real cert file not symbolic link
sudo cp /etc/letsencrypt/live/code.yourdomain.com/ -rL .
sudo chown lull:lull code.yourdomain.com/*change code-server config
vim ~/.config/code-server/config.yaml
note: service started by system, run as user, so keep cert path as absolute1
2
3
4
5bind-addr: 0.0.0.0:8082
auth: password
password: yourdomain
cert: /home/lull/.config/code-server/code.yourdomain.com/cert.pem
cert-key: /home/lull/.config/code-server/code.yourdomain.com/privkey.pemrevert service config to run as normal user
vim /etc/systemd/system/my-code-server.service
1 | [Service] |
- restart service