VSCode's Remote Development via SSH is incredibly useful. But to open a remote folder, you either have to run code -ArgumentList --folder-uri vscode-remote://ssh-remote+$machine$path from your local terminal, or click through 2β3 GUI steps. I wanted to simply type code . from the remote server's terminal and have it open instantly.
This repo is my hacky workaround. If there's a better way, please let me know.
To send a command from the remote server to your local machine, your machine needs to be SSH-accessible. Since exposing a desktop or laptop directly is impractical, I use SSH reverse tunneling through a Raspberry Pi as a relay:
Laptop/Desktop ββssh -N -RβββΊ Raspberry Pi βββssh `code .`ββ Remote Server
Three requirements in my setup:
- VSCode must launch with administrator privileges
- The remote server and path should be selected dynamically
- Must work on a laptop (not just a desktop)
I solved this using Windows Task Scheduler:
- The remote server writes
vscode_machine.txtandvscode_path.txt, then triggers the task remotely - A scheduled task on Windows reads those files, and automatically runs
code -ArgumentList --folder-uri vscode-remote://ssh-remote+$machine$path
| Side | OS |
|---|---|
| Your machine | Windows |
| Remote server | Linux |
- You also need a relay server (e.g. a Raspberry Pi) to act as the reverse tunnel middleman.
- Or, you could use other P2P protocols (e.g. iroh)
1. Create a Scheduled Task
Open Task Scheduler and create a new task with the following settings:
- General β Name:
OpenVSCode - General β Run with highest privileges: β checked
- Actions β New:
- Program/script:
powershell.exe - Arguments:
-NoProfile -ExecutionPolicy Bypass -File {PATH of OpenVSCode.ps1}
- Program/script:
- Conditions β Power β Start only if on AC power: β unchecked
2. Update paths in OpenVSCode.ps1
Replace the placeholders with full Windows paths to the text files:
| Placeholder | Replace with |
|---|---|
{PATH of vscode_machine.txt} |
Full path to vscode_machine.txt (e.g., C:\path\to\vscode_machine.txt) |
{PATH of vscode_path.txt} |
Full path to vscode_path.txt (e.g., C:\path\to\vscode_path.txt) |
3. Update placeholders in reverse_tunnel/tunnel.ps1
| Placeholder | Replace with |
|---|---|
{TUNNEL_PORT} |
Port to expose on the relay server (e.g., 2222) |
{RELAY_SSH_HOST} |
SSH host of your relay server (e.g., pi@raspberrypi.local) |
1. Edit remote_side/code
Replace the placeholders:
| Placeholder | Replace with |
|---|---|
{YOUR_WINDOWS_SSH_HOST} |
SSH alias pointing to your Windows machine via the relay (see ~/.ssh/config) |
{PATH of vscode_machine.txt} |
Windows path to vscode_machine.txt (same value as in OpenVSCode.ps1) |
{PATH of vscode_path.txt} |
Windows path to vscode_path.txt (same value as in OpenVSCode.ps1) |
2. Install to PATH
chmod +x remote_side/code
sudo cp remote_side/code /usr/local/bin/code# 1. On your local machine β start the reverse tunnel (run once after booting)
tunnel
# 2. On the remote server β open the current directory in VSCode
code .
# 3. Happy hacking