7

If I want to open a workspace on a regular local folder under C:\ I can just execute the command:

code.exe C:\the-local-workspace-folder

Is there any equivalent command for opening remote SSH workspaces?

I want to be able to use my keyboard launcher to open them, rather than needing to open them the fiddly way in the internal menus inside vscode.

So I need a regular system command to be able to do this.

I've looked through the command line arguments here: https://code.visualstudio.com/docs/editor/command-line - but can't find anything about remote workspaces at all.

I've also tried commands like:

code.exe username@hostname.example.com:/workspace-folder
code.exe username@hostname.example.com/workspace-folder

...but they don't work for this.

LaVache
  • 2,372
  • 3
  • 24
  • 38

3 Answers3

7

This looks like a recent fix, according to the issue tracking here. I've tested with my own settings, and this works:

"C:\Users\myusername\AppData\Local\Programs\Microsoft VS Code\Code.exe" \
    --remote ssh-remote+myubuntumachine /home/myusername/myprojectdirectory

The myubuntumachine should be the name given in the Host myubuntumachine in the SSH config file on CTRL+SHIFT+P/Remote SSH: Open Configuration File...

(Actually, on my machine I don't have the machine name, but some sort of hash value, although either works.)

Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
  • 1
    This would be a nice add on to the `~/.zshrc`: `function rcode() {code --remote ssh-remote+$1 $2}` https://stackoverflow.com/questions/60144074/how-to-open-a-remote-folder-from-command-line-in-vs-code – p8me Jan 03 '22 at 23:09
  • 1
    Now documented here: https://code.visualstudio.com/docs/remote/troubleshooting#_connect-to-a-remote-host-from-the-terminal – Martin_W Mar 27 '23 at 17:02
2

VSCode 1.63 (Nov. 2021) adds the option -n (issue 137529), to make sure a new window is opened for remote CLI:

The following options got added to the remote CLI:

-n to open a new window of the same remote as the current window -n --remote=wsl+ubuntu to open a new window of a different remote -n --remote=local to open a new local window

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

To get started, you need to:

Install an OpenSSH compatible SSH client if one is not already present.

Install Visual Studio Code or Visual Studio Code Insiders.

Install the Remote Development extension pack.

Read more : https://code.visualstudio.com/docs/remote/ssh

Installations extension :

code.exe --install-extension ms-vscode-remote.remote-ssh

Follow the step-by-step tutorial or if you have a simple SSH host setup, connect to it as follows:

Press F1 and run the Remote-SSH: Open SSH Host... command. Enter your user and host/IP in the following format in the input box that appears and press enter: user@host-or-ip or user@domain@host-or-ip If prompted, enter your password (but we suggest setting up key based authentication). After you are connected, use File > Open Folder to open a folder on the host.

You can press F1 to bring up the Command Palette and type in Remote-SSH for a full list of available commands. command list

You can change the location by launching VS Code with the --extensions-dir command-line option.

Where are extensions installed?# Extensions are installed in a per user extensions folder. Depending on your platform, the location is in the following folder:

Windows %USERPROFILE%.vscode\extensions

Linux ~/.vscode/extensions

macOS ~/.vscode/extensions

To run remote ssh and open the folder in command-line :

code.exe --remote ssh-remote+root@server.com <your-directory>
Zeta
  • 46
  • 7