VS Code on a headless coding VM, via code-server and an SSH tunnel
I do my coding on a headless VM. The machine in front of me is just a remote
terminal: I ssh into the VM and do everything there, in tmux, with Claude Code
and LazyVim. That works great for code, and it has
one big weak spot: reading Markdown. Claude produces a lot of Markdown
(plans, design docs, READMEs, AGENTS.md), and reading it as raw text in a
terminal is a pain. Tables come out as ASCII soup, there are no images, and I
can’t click links.
I tried a few remote Markdown viewers. Then it dawned on me: VS Code has a perfectly good Markdown preview, and while I’m at it, VS Code is also a full-blown IDE. code-server runs VS Code on the VM and serves it to a browser. All I need is a browser on the terminal machine and an SSH tunnel.
The setup in one picture
terminal machine headless VM
┌────────────────────────┐ ssh -L 5000 ┌──────────────────────────────┐
│ browser │ ════════════▶ │ code-server │
│ http://localhost:5000 │ │ listening on 127.0.0.1:5000 │
└────────────────────────┘ └──────────────────────────────┘
code-server listens only on the VM’s loopback, so nothing on the network can reach it. The SSH tunnel is the only way in. It still has a password, though, because of what the tunnel opens on the terminal machine (more below).
Install code-server on the VM
I followed the Debian/Ubuntu
instructions: grab
the .deb from the GitHub releases, install it, and enable the systemd unit
the package ships:
VERSION=4.137.0
curl -fOL https://github.com/coder/code-server/releases/download/v$VERSION/code-server_${VERSION}_amd64.deb
sudo dpkg -i code-server_${VERSION}_amd64.deb
sudo systemctl enable --now code-server@$USER
code-server@.service is a template unit, so code-server@mavi runs
code-server as the user mavi, starts it at boot and restarts it if it dies.
One thing to know: the .deb doesn’t add an apt repository, so
apt upgrade won’t update it. See Upgrading below.
Why not the Docker image?
There’s an official codercom/code-server
image (published by Coder from the code-server repo; linuxserver/code-server
is a separate community image), and upgrading would be just a docker pull.
Mounting ~/work into the container read-write is easy too. The catch is that
only the files come from the VM. Everything VS Code runs, runs inside the
container: the integrated terminal, git, the language servers, the debugger,
the extensions. And the container is a bare Debian: no JDK, no Ruby, no mise, no
Claude Code, no ~/.gitconfig, no SSH keys. Red Hat’s Java extension needs a
JDK in there, Ruby LSP needs Ruby, and so on. I’d end up building and
maintaining my own dev container image, and that’s way more work than
upgrading a .deb now and then.
If all you want is the Markdown preview, the image is fine. Just publish the
port as -p 127.0.0.1:5000:8080: a plain -p 5000:8080 listens on all
interfaces, and Docker’s iptables rules bypass ufw.
Configure it: localhost only, with a password
The config file is ~/.config/code-server/config.yaml. On first start
code-server generates one with a random password. Mine looks like this:
bind-addr: 127.0.0.1:5000
auth: password
password: <the generated one, or your own>
cert: false
bind-addr: 127.0.0.1:5000binds to loopback only, so the VM’s network interfaces don’t expose it at all.auth: passwordkeeps the login page. It’s tempting to turn it off withauth: none: the VM is mine alone, and SSH already authenticated me. The catch is the other end of the tunnel.ssh -Lopenslocalhost:5000on the terminal machine, and a loopback port has no notion of users: every account logged in there can connect to it. Without a password, any other user on the terminal machine gets a full VS Code running as me on the VM: a terminal, my files, my SSH keys. A password is cheap, so why not. The browser remembers the login in a cookie, so I rarely have to type it.cert: falsemeans plain HTTP. There’s no need for TLS, because the tunnel already encrypts the traffic.
Restart it after editing the config:
sudo systemctl restart code-server@$USER
Tunnel it to the terminal machine
On the terminal machine:
ssh vm -L 5000:localhost:5000
Then open http://localhost:5000 in the browser. That’s the whole trick: the full VS Code, with the VM’s filesystem, terminals, git and language servers, in a browser tab.
I don’t pass -N, so the same ssh session also gives me a shell. My
tmux+Claude workflow stays where it was, and VS Code sits next to it. To make
the tunnel automatic, add it to ~/.ssh/config on the terminal machine:
Host vm
LocalForward 5000 localhost:5000
Why it has to be localhost
Don’t be tempted to skip the tunnel and open http://<vm-ip>:5000 directly
(with bind-addr: 0.0.0.0). Some browser features only work in a secure
context, which means either HTTPS or localhost/127.0.0.1. Plain HTTP to
an IP address is not a secure context, so the browser disables things like:
- Clipboard access. Copy/paste between VS Code and the rest of your desktop stops working properly.
- Service workers. VS Code webviews depend on them, and per the code-server FAQ, webviews break without a secure context. The Markdown preview is a webview, so you’d lose exactly the feature I came here for.
Through the tunnel the browser sees localhost, which counts as secure, so
everything works without dealing with certificates.
Make it feel like LazyVim
My muscle memory is LazyVim’s, so I made VS Code follow it. Install the VSCodeVim extension. Note that code-server uses the Open VSX gallery, not Microsoft’s marketplace. Most popular extensions are there, including Claude Code, Red Hat’s Java support and Ruby LSP; the closed-source Microsoft ones, like Live Share and the Remote-* family, are not.
Then map the LazyVim keys onto VS Code commands in the user settings. In
code-server those live at ~/.local/share/code-server/User/settings.json on the
VM, not in ~/.config/Code. Download my
settings.json and save it there.
It maps <Space> as leader, <Space><Space> / <Space>ff for file search,
<Space>/ for grep, H/L to cycle editors, <Space>c* for code actions,
]d/[d for diagnostics, ]h/[h for git hunks, and so on. Here’s a taste:
{
"vim.leader": "<space>",
"vim.normalModeKeyBindingsNonRecursive": [
{ "before": ["<leader>", "<leader>"], "commands": ["workbench.action.quickOpen"] },
{ "before": ["<leader>", "/"], "commands": ["workbench.action.findInFiles"] },
{ "before": ["<S-h>"], "commands": ["workbench.action.previousEditor"] },
{ "before": ["<S-l>"], "commands": ["workbench.action.nextEditor"] },
{ "before": ["<leader>", "c", "a"], "commands": ["editor.action.quickFix"] },
{ "before": ["]", "h"], "commands": ["workbench.action.editor.nextChange"] },
// ...and about 40 more
]
}
A few notes:
vim.handleKeyshandsCtrl+B,Ctrl+PandCtrl+Cback to VS Code, so the sidebar toggle, quick open and copy keep working.- VS Code has no real flash.vim, so
sfalls back to VSCodeVim’s built-in easymotion search. - VSCodeVim can’t do exactly what LazyVim does when a mapping is a prefix of a
longer one (
<leader>wvs<leader>wd,<leader>cvs<leader>cfin visual mode). It waits briefly for the next key, and that’s good enough for me.
Upgrading
There’s no need to keep track of the installed version: dpkg already knows it
(dpkg-query -W code-server). So the upgrade is a small script that compares
it with the latest GitHub release, and if there’s a newer one, downloads the
.deb, checks it and installs it. Download
update-code-server to the
VM, chmod +x it, and run it whenever you feel like it. It needs jq
(sudo apt install jq).
#!/bin/bash
set -euo pipefail
installed=$(dpkg-query -W -f='${Version}' code-server 2>/dev/null || echo none)
release=$(curl -fsSL https://api.github.com/repos/coder/code-server/releases/latest)
latest=$(jq -r .tag_name <<<"$release"); latest=${latest#v}
if [[ $installed == "$latest" ]]; then
echo "code-server $installed is up to date"; exit 0
fi
echo "Updating code-server $installed -> $latest"
echo "Release notes: https://github.com/coder/code-server/releases/tag/v$latest"
deb="code-server_${latest}_amd64.deb"
digest=$(jq -r --arg n "$deb" '.assets[] | select(.name == $n) | .digest' <<<"$release")
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT
curl -fL -o "$tmp/$deb" "https://github.com/coder/code-server/releases/download/v$latest/$deb"
echo "${digest#sha256:} $tmp/$deb" | sha256sum -c -
echo "Installing new code-server from $tmp/$deb via sudo"
sudo dpkg -i "$tmp/$deb"
sudo systemctl daemon-reload
sudo systemctl restart "code-server@$USER"
A few notes:
- The checksum. GitHub’s API lists a sha256
digestfor every release asset. If it’s missing,sha256sum -cfails and nothing gets installed. This catches a broken or tampered download. It doesn’t catch a compromised release, because the hash comes from the same GitHub that served the file. daemon-reload. A new version may ship a changedcode-server@.service, and the package doesn’t tell systemd about it. Without the reload, systemd warns that the unit file changed on disk, and the restart would still use the old unit definition.- Run it by hand, not from cron. The restart drops the open VS Code tabs and their terminals, and code-server moves to a new VS Code often, so I like to skim the release notes first.
Result
Nothing about the VM changed. It’s still headless, and tmux, Claude and LazyVim are still there for when I want them. I just gained a browser tab with a full IDE on the same files: rendered Markdown, a proper diff viewer, a debugger, and LazyVim-ish keybindings so my fingers don’t notice the switch. The terminal machine still needs nothing but ssh and a browser.