Skip to content

Changooo/remote_code_dot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Remote code . β€” Open VSCode from Your Server's Terminal

Motivation

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.


How It Works

A. Reach Your Local Machine from the Remote Server

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

B. Remotely Trigger code . on Your Local Machine

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:

  1. The remote server writes vscode_machine.txt and vscode_path.txt, then triggers the task remotely
  2. A scheduled task on Windows reads those files, and automatically runs code -ArgumentList --folder-uri vscode-remote://ssh-remote+$machine$path

Prerequisites

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)

Installation

Your Machine (Windows)

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}
  • 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)

Remote Server (Linux)

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

Usage

# 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

About

Open VSCode from Your Server's Terminal

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors