code-server 4.143.1 常用 CLI 命令详解
code-server 4.143.1 CLI 全参数与实测:--help 完整回显、--version、--auth、--bind-addr、--cert、数据目录、扩展安装卸载、systemd 托管与 journalctl 排障。
code-server 4.143.1 常用 CLI 命令详解
目标:把 code-server 4.143.1 的
--help全参数、认证与监听、数据目录、扩展管理、systemd 托管与 journalctl 一次讲清,并给出可直接照抄的实测回显。本文在 Ubuntu 22.04.5 LTS 上实跑(2026-10-27),版本 4.143.1;配置项逐个解释见《code-server 4.143.1 配置参数详解》,部署形态见站内部署篇。
一、环境信息
| 项目 | 实测值 |
|---|---|
| 版本 | 4.143.1 22ddf60dbc52f164cff13620ab515086dd08c90a with Code 1.143.1 |
| 系统 | Ubuntu 22.04.5 LTS(x86_64) |
| 二进制路径 | /usr/bin/code-server(deb 安装) |
| 运行用户 | root(服务单元 code-server@root) |
| 默认配置 | /root/.config/code-server/config.yaml |
| 默认数据目录 | /root/.local/share/code-server |
| 默认监听 | 0.0.0.0:8080(本文演示机配置) |
| 演示密码 | q1w2e3r4 |
| 实测端口 | 8140–8151、Unix socket |
| 查询日期 | 2026-10-27 |
二、命令结构与通用规则
2.1 基本形式
code-server [options] [path]
path 可以是目录,也可以是 .code-workspace 文件:
code-server ./path/to/your/project
code-server ./path/to/your/project.code-workspace
2.2 参数写法
- 长参数:
--bind-addr 127.0.0.1:8080或--bind-addr=127.0.0.1:8080; - 短参数:
-h、-v、-e、-n、-r、-vvv、-an、-w; - 布尔项直接写参数名,不需要值;写
--flag=false视为不开启; - 带值项如果后面紧跟另一个
-开头的 token,会被判定为“缺值”并报错; - 扩展、可信来源等数组项可以重复传入,例如
--install-extension a.b --install-extension c.d。
2.3 配置文件与命令行的关系
命令行参数优先于 config.yaml,环境变量又在两者之上参与覆盖(密码类除外)。完整优先级和 12 组实测见配置参数篇第三节、第五节。本篇只讲命令本身怎么用。
三、--help 全参数
code-server --help
4.143.1 实测完整输出:
code-server 4.143.1 22ddf60dbc52f164cff13620ab515086dd08c90a with Code 1.143.1
Usage: code-server [options] [path]
- Opening a directory: code-server ./path/to/your/project
- Opening a saved workspace: code-server ./path/to/your/project.code-workspace
Options
--auth The type of authentication to use. [password, none]
--password The password for password authentication (can only be passed in via $PASSWORD or the config file).
--hashed-password The password hashed with argon2 for password authentication (can only be passed in via $HASHED_PASSWORD or the config file).
Takes precedence over 'password'.
--cert Path to certificate. A self signed certificate is generated if none is provided.
--cert-host Hostname to use when generating a self signed certificate.
--cert-key Path to certificate key when using non-generated cert.
--disable-telemetry Disable telemetry.
--disable-update-check Disable update check. Without this flag, code-server checks every 6 hours against the latest github release and
then notifies you once every week that a new release is available.
--cookie-suffix Adds a suffix to the cookie. This can prevent a collision of cookies for subdomains, making them explixit.
Without this flag, no suffix is used. This can also be set with CODE_SERVER_COOKIE_SUFFIX set to any string.
--disable-file-downloads Disable file downloads from Code. This can also be set with CS_DISABLE_FILE_DOWNLOADS set to 'true' or '1'.
--disable-file-uploads Disable file uploads.
--disable-workspace-trust Disable Workspace Trust feature. This switch only affects the current session.
--disable-getting-started-override Disable the coder/coder override in the Help: Getting Started page.
--disable-proxy Disable domain and path proxy routes.
-h --help Show this output.
--link-protection-trusted-domains Links matching a trusted domain can be opened without link protection.
--locale Set vscode display language and language to show on the login page, more info see
https://en.wikipedia.org/wiki/IETF_language_tag
--open Open in browser on startup. Does not work remotely.
--bind-addr Address to bind to in host:port. You can also use $PORT to override the port.
--config Path to yaml config file. Every flag maps directly to a key in the config file.
--socket Path to a socket (bind-addr will be ignored).
--socket-fd File descriptor of a pre-bound, listening socket to use (for systemd socket activation).
--socket-mode File mode of the socket.
--trusted-origins Disables authenticate origin check for trusted origin. Useful if not able to access reverse proxy configuration.
-v --version Display version information.
--user-data-dir Path to the user data directory.
--extensions-dir Path to the extensions directory.
--list-extensions List installed VS Code extensions.
--force Avoid prompts when installing VS Code extensions.
--install-extension Install or update a VS Code extension by id or vsix. The identifier of an extension is `${publisher}.${name}`.
To install a specific version provide `@${version}`. For example: 'vscode.csharp@1.2.3'.
--enable-proposed-api Enable proposed API features for extensions. Can receive one or more extension IDs to enable individually.
--uninstall-extension Uninstall a VS Code extension by id.
--show-versions Show VS Code extension versions.
--github-auth GitHub authentication token (can only be passed in via $GITHUB_TOKEN or the config file).
--enable-remote-storage Persist VS Code workbench storage on the remote server instead of browser storage.
--proxy-domain Domain used for proxying ports.
--skip-auth-preflight Allows preflight requests through proxy without authentication.
-e --ignore-last-opened Ignore the last opened directory or workspace in favor of an empty window.
-n --new-window Force to open a new window.
-r --reuse-window Force to open a file or folder in an already opened window.
-vvv --verbose Enable verbose logging.
-an --app-name Will replace the {{app}} placeholder in any strings, which by default includes the title bar and welcome message
-w --welcome-text (deprecated) Text to show on login page
--abs-proxy-base-path The base path to prefix to all absproxy requests
--i18n Path to JSON file with custom translations. Merges with default strings and supports all i18n keys.
--idle-timeout-seconds Timeout in seconds to wait before shutting down when idle.
--reconnection-grace-time Override the reconnection grace time in seconds. Clients who disconnect for longer than this duration will need to
reload the window. Defaults to 10800 (3 hours).
--vscode-option Pass an option straight through to the VS Code server as flag=value, or as a bare flag for a
boolean. Repeatable; repeating the same flag builds an array. Use this to reach VS Code options
code-server does not model itself, e.g. --vscode-option enable-sandbox --vscode-option agents=true.
💡 说明:
--help不展示隐藏参数--log、--host、--port、--enable、--json、--session-socket、--builtin-extensions-dir、--locate-extension、--category。它们仍可解析,但属于内部/兼容用途,日常不要依赖。逐项含义见配置参数篇第四节。
四、版本与帮助
4.1 查看版本
code-server --version
4.143.1 22ddf60dbc52f164cff13620ab515086dd08c90a with Code 1.143.1
短参数等价:
code-server -v
版本串含义:code-server 版本 + commit + 捆绑的 VS Code 版本。升级后第一件事就是跑这一行确认。
4.2 帮助
code-server -h
code-server --help
两者输出相同,退出码 0。
五、认证与监听
5.1 --auth
# 密码认证(默认)
code-server --auth password
# 关闭认证,仅限本机/完全可信内网
code-server --auth none
实测 --auth none:
[2026-10-27T11:56:19.539Z] info HTTP server listening on http://127.0.0.1:8145/
[2026-10-27T11:56:19.539Z] info - Authentication is disabled
root page: 200
访问 / 直接 200,不再 302 到 /login。
⚠️ 注意:
--auth none等于把 Web Shell 裸露给能访问该端口的人。只在本机回环或一次性调试时使用,绝不和0.0.0.0一起出现在公网主机上。
5.2 --bind-addr
code-server --bind-addr 127.0.0.1:8151
code-server --bind-addr 0.0.0.0:8080
实测:
[2026-10-27T11:56:07.184Z] info HTTP server listening on http://127.0.0.1:8141/
要点:
- 只写主机不写端口时按 80 处理:
bind-addr: 127.0.0.1→http://127.0.0.1/; - 环境变量
PORT会覆盖这里的端口,只有显式--port能再压过PORT; - 生产环境通常写
127.0.0.1:8080,由反向代理对外提供 TLS。
5.3 --cert / --cert-host / --cert-key
自签证书(不提供路径时自动生成):
code-server --bind-addr 127.0.0.1:8147 --cert --cert-host demo.local
实测:
[2026-10-27T11:56:25.859Z] info HTTPS server listening on https://127.0.0.1:8147/
[2026-10-27T11:56:25.859Z] info - Using certificate for HTTPS: /root/.local/share/code-server/demo_local.crt
https root: 302
subject=CN = demo.local
issuer=CN = demo.local
notBefore=Oct 27 11:56:25 2026 GMT
notAfter=Oct 27 11:56:25 2027 GMT
自有证书:
code-server --bind-addr 0.0.0.0:8443 \
--cert /etc/ssl/certs/ide.example.com.crt \
--cert-key /etc/ssl/private/ide.example.com.key
⚠️ 注意:只给
--cert路径、不给--cert-key会直接报错--cert-key is missing。自签证书的.crt/.key默认落在默认数据目录下;即使同时传了--user-data-dir,本次实测仍落在/root/.local/share/code-server/。生产环境请用绝对路径的自有证书。
5.4 密码不能走命令行
code-server --password test123
[2026-10-27T11:57:25.111Z] error --password can only be set in the config file or passed in via $PASSWORD
exit=1
--hashed-password、--github-auth 同理,只能通过配置文件或对应环境变量传入。这是为了避免密码出现在 shell 历史和进程列表里。
六、数据目录
6.1 --user-data-dir
code-server --user-data-dir /var/lib/code-server \
--bind-addr 127.0.0.1:8146
实测:
[2026-10-27T11:56:22.714Z] info Using user-data-dir /tmp/cs4/ud6
[2026-10-27T11:56:22.721Z] info Session server listening on /tmp/cs4/ud6/code-server-ipc.sock
数据目录里包括:扩展、用户设置、工作区状态、日志、code-server-ipc.sock、coder.json。
6.2 --extensions-dir
code-server --extensions-dir /var/lib/code-server/extensions
不指定时自动为 <user-data-dir>/extensions。迁移数据时两个目录必须一起搬,否则扩展会“消失”(实际还在旧目录)。
6.3 隐藏参数 --session-socket
code-server --session-socket /run/code-server/ipc.sock
用于多实例时隔离会话 socket。日常不需要改;默认值为 <user-data-dir>/code-server-ipc.sock。
七、扩展管理
7.1 列出已安装扩展
code-server --list-extensions
code-server --list-extensions --show-versions
实测(空目录):
$ code-server --list-extensions --extensions-dir /tmp/cs5/ext --user-data-dir /tmp/cs5/ud
$ echo $?
0
实测(已安装一个扩展):
code-server --list-extensions --show-versions
editorconfig.editorconfig@0.18.2
要点:空列表也返回退出码 0,脚本里不要用“有没有输出”判断失败。
7.2 安装扩展
# 按 ID 安装(默认从 Open VSX 获取)
code-server --install-extension editorconfig.editorconfig
# 指定版本
code-server --install-extension editorconfig.editorconfig@0.18.2
# 安装本地 vsix
code-server --install-extension /path/to/extension.vsix
# 脚本化:不交互
code-server --install-extension editorconfig.editorconfig --force
实测完整回显:
Installing extensions...
(node:3957) [DEP0169] DeprecationWarning: `url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.
(Use `node --trace-deprecation ...` to show where the warning was created)
Installing extension 'editorconfig.editorconfig'...
Extension 'editorconfig.editorconfig' v0.18.2 was successfully installed.
Node 的 DEP0169 是 VS Code 扩展安装器内部的弃用告警,不影响安装结果。
7.3 卸载扩展
code-server --uninstall-extension editorconfig.editorconfig
实测:
Uninstalling editorconfig.editorconfig...
(node:4020) [DEP0169] DeprecationWarning: `url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.
(Use `node --trace-deprecation ...` to show where the warning was created)
Extension 'editorconfig.editorconfig' was successfully uninstalled!
卸载后再列:
code-server --list-extensions --extensions-dir /tmp/cs5/ext --user-data-dir /tmp/cs5/ud
echo $?
# 0(无输出)
7.4 其他扩展参数
| 参数 | 用途 | 示例 |
|---|---|---|
--force | 安装/卸载不提示 | -- install-extension a.b --force |
--show-versions | 列表显示版本 | --list-extensions --show-versions |
--enable-proposed-api | 为指定扩展启用 proposed API | --enable-proposed-api publisher.name |
--enable-remote-storage | 工作台存储放服务端 | 多设备场景 |
--github-auth | GitHub Token,仅配置文件/GITHUB_TOKEN | 私有扩展源 |
7.5 扩展目录只读会失败(实测)
把 --extensions-dir 指向一个只读目录(本次实测以只读挂载提供,目录内已有 extensions.json),再执行 --install-extension:
code-server --install-extension editorconfig.editorconfig --force \
--extensions-dir /home/coder/ext-ro
实测报错(退出码 1):
Installing extension 'editorconfig.editorconfig'...
Error while installing extension editorconfig.editorconfig: ENOENT: no such file or directory, mkdir '/home/coder/ext-ro/.3802a677-7f4d-4c86-9c83-8a284dbf7a69'
Failed Installing Extensions: editorconfig.editorconfig
[2026-10-27T11:59:22.300Z] error parent:1 Uncaught exception: ENOENT: no such file or directory, mkdir '/home/coder/ext-ro/.3802a677-7f4d-4c86-9c83-8a284dbf7a69'
注:结论只需记住:
--extensions-dir必须是可写目录,否则连扩展安装的临时目录都建不出来。
八、其他常用参数
8.1 关闭外联检查
code-server --disable-telemetry --disable-update-check
--disable-telemetry:关闭遥测;--disable-update-check:关闭每 6 小时的 GitHub 版本检查,内网环境必开。
8.2 关闭文件上传/下载与工作区信任
code-server \
--disable-file-uploads \
--disable-file-downloads \
--disable-workspace-trust
--disable-file-downloads 也可用 CS_DISABLE_FILE_DOWNLOADS=true 开启。
8.3 语言与标题
code-server --locale zh-cn --app-name "运维工作台"
实测登录页标题:
<title>运维工作台 login</title>
8.4 代理与可信来源
code-server \
--trusted-origins https://ide.example.com \
--proxy-domain ide.example.com \
--abs-proxy-base-path /codeserver
反代域名与访问域名不一致时,--trusted-origins 用来跳过 Origin 校验;--proxy-domain 用于端口转发域名。
8.5 超时与重连
code-server \
--idle-timeout-seconds 1800 \
--reconnection-grace-time 10800
--idle-timeout-seconds必须大于 60,否则启动失败:
[2026-10-27T11:56:29.818Z] error --idle-timeout-seconds must be greater than 60 seconds.
exit=1
--reconnection-grace-time默认 10800 秒(3 小时),反向代理超时要大于它。
8.6 日志
code-server --log trace
code-server -vvv
两者等价于最详细日志。--log 是隐藏参数,合法值 trace/debug/info/warn/error。
8.7 透传 VS Code 参数
code-server \
--vscode-option enable-sandbox \
--vscode-option agents=true
可重复;相同参数重复出现会组成数组。用于 code-server 没有建模的 VS Code 服务端选项。
8.8 浏览器与窗口控制
code-server --open # 启动时打开本机浏览器(远程无效)
code-server -e # 忽略上次打开目录
code-server -n # 强制新窗口
code-server -r # 复用已有窗口
8.9 Unix socket 监听
code-server --socket /run/code-server/code.sock --auth none
实测:
[2026-10-27T11:57:25.348Z] warn Could not create socket at /tmp/cs5/ud-sock/code-server-ipc.sock
[2026-10-27T11:57:25.349Z] info HTTP server listening on /tmp/cs5/code.sock
[2026-10-27T11:57:25.349Z] info - Authentication is disabled
[2026-10-27T11:57:25.349Z] info Session server listening on /tmp/cs5/ud-sock/code-server-ipc.sock
socket HTTP 200
要点:
--socket设置后忽略--bind-addr;- socket 父目录必须已存在,否则会话 socket 会告警;
- 进程退出时会删除监听 socket 文件,停止后
ls不到属正常; - 验证用
curl --unix-socket。
九、systemd 托管与 journalctl
9.1 服务单元
deb 包自带模板单元 /lib/systemd/system/code-server@.service:
[Unit]
Description=code-server
After=network.target
[Service]
Type=exec
ExecStart=/usr/bin/code-server
Restart=always
User=%i
[Install]
WantedBy=default.target
User=%i 表示实例名就是运行用户。启用:
systemctl enable --now code-server@root
普通用户则用 code-server@ubuntu 之类。
9.2 查看状态
systemctl status code-server@root --no-pager | head -14
实测:
* code-server@root.service - code-server
Loaded: loaded (/lib/systemd/system/code-server@.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2026-10-27 10:19:52 UTC; 1h 38min ago
Main PID: 2673 (MainThread)
Tasks: 22 (limit: 2932)
Memory: 76.8M
CPU: 1.227s
CGroup: /system.slice/system-code-server.slice/code-server@root.service
|-2673 /usr/lib/code-server/lib/node /usr/lib/code-server
`-2693 /usr/lib/code-server/lib/node /usr/lib/code-server/out/node/entry
查看单元文件:
systemctl cat code-server@root
查看关键属性:
systemctl show code-server@root -p MainPID -p ActiveState -p SubState -p ExecMainStartTimestamp
MainPID=2673
ExecMainStartTimestamp=Tue 2026-10-27 10:19:52 UTC
ActiveState=active
SubState=running
9.3 journalctl
# 最近日志
journalctl -u code-server@root --no-pager -n 20
# 实时跟踪
journalctl -u code-server@root -f
# 指定时间窗
journalctl -u code-server@root --since "10 min ago" --no-pager
# 只看错误
journalctl -u code-server@root -p err --no-pager
# 精确时间格式
journalctl -u code-server@root -o short-iso --no-pager -n 6
实测(short-iso):
2026-10-27T10:20:00+0000 39e721e306f2 code-server[2673]: [10:20:00] [shared storage] Creating shared storage database at '/root/.vscode-oss-shared/sharedStorage/state.vscdb' (wasCreated: true)
2026-10-27T10:20:00+0000 39e721e306f2 code-server[2673]: [10:20:00] [shared storage] Initializing fallback application storage (path: /root/.local/share/code-server/User/globalStorage/state.vscdb)
2026-10-27T10:20:00+0000 39e721e306f2 code-server[2673]: [10:20:00] Started initializing default profile extensions in extensions installation folder. file:///root/.local/share/code-server/extensions
2026-10-27T10:20:00+0000 39e721e306f2 code-server[2673]: [10:20:00] [shared storage] Fallback application storage initialized with 3 items
2026-10-27T10:20:00+0000 39e721e306f2 code-server[2673]: [10:20:00] Completed initializing default profile extensions in extensions installation folder. file:///root/.local/share/code-server/extensions
2026-10-27T10:20:17+0000 39e721e306f2 code-server[2673]: Failed login attempt {"remoteAddress":"127.0.0.1","userAgent":"curl/7.81.0","timestamp":1793096417}
9.4 在服务单元里加参数
模板单元默认只跑 code-server,不传参数。要让服务带参数启动,用覆盖单元:
systemctl edit code-server@root
写入:
[Service]
ExecStart=
ExecStart=/usr/bin/code-server --bind-addr 0.0.0.0:8080 --disable-telemetry --disable-update-check
密码不要写在命令行,用环境文件:
install -m 600 /dev/null /etc/code-server.env
printf 'PASSWORD=q1w2e3r4\n' > /etc/code-server.env
[Service]
EnvironmentFile=/etc/code-server.env
然后:
systemctl daemon-reload
systemctl restart code-server@root
journalctl -u code-server@root -n 30 --no-pager
9.5 启停与重载
systemctl start code-server@root
systemctl stop code-server@root
systemctl restart code-server@root
systemctl is-active code-server@root
配置文件和覆盖单元改动后必须 daemon-reload + restart;code-server 不热加载。
十、退出码与脚本化
| 场景 | 退出码 | 实测输出 |
|---|---|---|
--version / --help | 0 | 版本/帮助文本 |
--list-extensions 空目录 | 0 | 无输出 |
| 安装扩展成功 | 0 | was successfully installed. |
| 卸载扩展成功 | 0 | was successfully uninstalled! |
| 未知参数 | 1 | error Unknown option --not-a-flag |
命令行传 --password | 1 | --password can only be set in the config file or passed in via $PASSWORD |
--idle-timeout-seconds 60 | 1 | --idle-timeout-seconds must be greater than 60 seconds. |
| 扩展目录只读 | 1 | ENOENT: no such file or directory, mkdir ... |
| 配置文件未知键 | 1 | error reading ...: Unknown option --... |
实测未知参数:
code-server --not-a-flag
[2026-10-27T11:57:25.000Z] error Unknown option --not-a-flag
exit=1
脚本建议:
if ! code-server --version >/dev/null 2>&1; then
echo "code-server 不可用" >&2
exit 1
fi
十一、排障实录
11.1 code-server: command not found
which code-server
ls -l /usr/bin/code-server
deb 安装路径是 /usr/bin/code-server,standalone 是 /usr/local/bin/code-server。systemd 单元里写的是绝对路径,手工换路径后要同步改单元。
11.2 服务启动成功但外网访问不了
systemctl status code-server@root --no-pager
ss -ltnp | grep 8080
journalctl -u code-server@root -n 20 --no-pager
重点看日志里的 HTTP server listening on http://0.0.0.0:8080/。如果是 127.0.0.1:8080,说明监听只在本机,外网必然访问不到。
11.3 登录一直失败
- 检查密码来源:
journalctl -u code-server@root | grep 'Using password'; - 检查配置:
cat /root/.config/code-server/config.yaml; - 检查是否有
PASSWORD/HASHED_PASSWORD环境变量覆盖; - 用
curl直接验证:
curl -s -o /dev/null -w "%{http_code} -> %{redirect_url}\n" \
-X POST -d "password=q1w2e3r4" http://127.0.0.1:8080/login
# 302 -> http://127.0.0.1:8080/
11.4 扩展装不上
code-server --list-extensions --show-versions
code-server --install-extension publisher.name --force
常见原因:
- 扩展目录不可写(见 7.5);
- Open VSX 没有该扩展,或网络无法访问 open-vsx.org;
- 扩展要求更高的 VS Code 内核版本;
- 扩展是微软专有许可,不在 Open VSX 上架(如 Pylance),只能手工 vsix 或换扩展。
11.5 Unix socket 停止后文件消失
ls -l /run/code-server/code.sock
进程退出时会清理 socket 文件,属于正常行为;需要常驻就用 systemd 托管,不要用 nohup ... & 裸跑。
11.6 systemctl restart 后配置仍旧
覆盖单元里的 ExecStart= 必须先清空再写新值:
[Service]
ExecStart=
ExecStart=/usr/bin/code-server --bind-addr 127.0.0.1:8080
只写第二行会与模板里的 ExecStart 冲突,systemd 可能忽略或报错。改完执行:
systemctl daemon-reload
systemctl restart code-server@root
systemctl show code-server@root -p ExecStart