Running tmux over an SSH connection to a remote machine, then launching code-server within that tmux session, is a surprisingly robust way to get a full VS Code experience on a server without needing X11 forwarding or a complex GUI setup. The trick is realizing that code-server itself is a web application, and tmux is just providing a persistent terminal environment for it to run in, which SSH then tunnels to your local browser.
Let’s say you’ve got a beefy server and want to code on it from your laptop. You’ve already got SSH access, but you want the full VS Code IDE experience, not just a basic terminal.
Here’s how you set it up. First, ensure tmux and code-server are installed on your remote server.
On your remote server:
sudo apt update && sudo apt install tmux -y
curl -fsSL https://code-server.dev/install.sh | sh
Now, SSH into your remote server:
ssh your_user@your_remote_server_ip
Once logged in, start a tmux session:
tmux new -s dev_session
This creates a new tmux session named dev_session. If you detach from this session (Ctrl+b, then d), your tmux session and anything running inside it will continue to run on the server. You can reattach later with tmux attach -t dev_session.
Inside your tmux session, start code-server:
code-server --port 8080
code-server will output something like:
code-server 4.9.1 e60c937
Extension host terminated unexpectedly. Code: 32768
To restart the extension host, try quitting and restarting VS Code.
?
?
INFO [Starting application] ...
INFO [HTTP server listening on http://127.0.0.1:8080] ...
Crucially, it tells you it’s listening on 127.0.0.1:8080. This means it’s only accessible from the remote server itself, not directly from your local machine.
Now, you need to tunnel this. Open another terminal window on your local machine and set up an SSH tunnel. This command forwards traffic from a port on your local machine (e.g., 9000) to the code-server port (8080) on the remote server, via the SSH connection.
ssh -N -L 9000:127.0.0.1:8080 your_user@your_remote_server_ip
-N: Tells SSH not to execute a remote command. Useful for just forwarding ports.-L 9000:127.0.0.1:8080: This is the core of the tunnel. It says "listen onlocalhost:9000on my local machine, and when something connects, forward that traffic through the SSH connection to127.0.0.1:8080on the remote server."
Keep this local terminal window open; closing it breaks the tunnel.
Finally, on your local machine, open a web browser and go to http://localhost:9000. You should see the code-server login page. The default password is your_password (which you’ll be prompted to change on first login).
You’re now interacting with code-server running on the remote server, tunneled through SSH, and managed by tmux for persistence. Any files you open or edit are on the remote server. If your local laptop goes to sleep or your network connection drops, the tmux session and code-server keep running on the server. Just re-establish the SSH tunnel and refresh your browser.
The real power comes from the combination: tmux ensures code-server stays alive even if your SSH connection drops and you reattach. SSH port forwarding makes code-server accessible to your local browser. It’s a seamless way to get a powerful IDE experience on a remote machine without graphical overhead.
When you’re done, you can stop code-server within your tmux session by pressing Ctrl+c on the line where code-server is running. To exit tmux and leave it running in the background, detach with Ctrl+b then d. To stop the tmux session entirely, reattach (tmux attach -t dev_session) and then type exit.
The next hurdle you’ll likely encounter is managing multiple tmux panes and windows for different projects or tasks within your remote development environment.