10

I can start VS Code to open a local folder using code /path/to/folder. Is it possible to open a folder on a remote machine (via the Remote SSH extension) by specifying the machine and folder on the command line?

Ambroz Bizjak
  • 7,809
  • 1
  • 38
  • 49
  • you can't do that because it will be violated the security. – Khanh Le Tran Feb 10 '20 at 04:34
  • Does this answer your question? [Vscode (code.exe) command line arguments to immediately open a remote workspace folder over SSH](https://stackoverflow.com/questions/64710228/vscode-code-exe-command-line-arguments-to-immediately-open-a-remote-workspace) – Jacob Stern Apr 13 '21 at 15:16

2 Answers2

12

From the cli on linux or mac terminal:

code --folder-uri=vscode-remote://ssh-remote+<HOSTNAME><ABSOLUTE_PATH>

Something like:

code --folder-uri=vscode-remote://ssh-remote+centos8stream.local/home/guillaume/workspace/


In my ~/.ssh/config file I have:

Host centos8stream.local
    Hostname 10.41.11.69
    User guillaume

In my terminal I can ssh to my server doing ssh centos8stream.local

Then I can open vscode on my remote server directly:

code --folder-uri=vscode-remote://ssh-remote+centos8stream.local/home/guillaume/workspace/

I even created an alias function in my ~/.zshrc file

function rcode() { code --folder-uri=vscode-remote://ssh-remote+$1/home/guillaume/$2 }

Then I just type

rcode centos8stream.local workspace/my_project

Guillaume Vincent
  • 13,355
  • 13
  • 76
  • 103
  • 3
    A little bit cleaner version of the function is: `function rcode() {code --remote ssh-remote+$1 $2}` based on https://stackoverflow.com/questions/64710228/vscode-code-exe-command-line-arguments-to-immediately-open-a-remote-workspace – p8me Jan 03 '22 at 23:07
0

Mount the remote folder in your dev box and open it in VSCode.

BHP
  • 443
  • 4
  • 13