0

TL;DR: Is there a way to connect to a SSH project with VS Code and Remote SSH extension from command line?

I'm searching for a way to open a Remote SSH project in VS Code using command line. I used to open local projects in VS Code by running:

# to open new window
code /path/to/my/project

# or to reuse some window
code -r /path/to/my/project

I have Remote SSH and Project Manager extensions installed and I have a lot of projects configured in my projects.json and ~/.ssh/config e.g.:

~/.ssh/config
Host project-ssh-alias
  HostName 0.1.2.3  # A valid IP of course
  IdentityFile ~/.ssh/my-key
  User remote-user
~/.config/Code/User/projects.json
{
  "name": "My Remote Project",
  "rootPath": "vscode-remote://ssh-remote+project-ssh-alias/path/to/my/remote-project",
  "paths": [],
  "tags": [],
  "enabled": true
}

The question: Is it possible to connect to a Remote SSH project in VS Code from command line? I've tried something like the command below, but it didn't work:

code vscode-remote://ssh-remote+project-ssh-alias/path/to/my/remote-project

I expect to VS Code open and connect to my SSH project using Remote SSH extension from command line.

starball
  • 20,030
  • 7
  • 43
  • 238
thiagobraga
  • 1,519
  • 2
  • 15
  • 29

1 Answers1

2

You do it like this:

code --remote ssh-remote+remote_server /code/my_project

Quoting from the docs (which got added in response to this answer post!):

We need to do some guessing on whether the input path is a file or a folder. If it has a file extension, it is considered a file.

To force that a folder is opened, add slash to the path or use:

code --folder-uri vscode-remote://ssh-remote+remote_server/code/folder.with.dot

To force that a file is opened, add --goto or use:

code --file-uri vscode-remote://ssh-remote+remote_server/code/fileWithoutExtension

You might need to quote the paths for your shell if the paths have spaces in them.

Related GitHub issue tickets:

For your reference, I found this by googling "github vscode issues commandline connect to remote ssh"

starball
  • 20,030
  • 7
  • 43
  • 238