8

With the ssh extension of vscode I can open remotedir in remotehost via the UI. Similarly to how you can invoke code localdir in the command line, is it possible to do something like code remotedir --host remotehost? If not, would there be a way to write a script to achieve something like that?

Mei Zhang
  • 1,434
  • 13
  • 29

5 Answers5

9

Use:

code --folder-uri "vscode-remote://ssh-remote+remote_server/folder/on/remote/host/here

To also specify the user:

code --folder-uri "vscode-remote://ssh-remote+remote_user@remote_server/folder/on/remote/host/here
Kyle F Hartzenberg
  • 2,567
  • 3
  • 6
  • 24
Xeon-J
  • 162
  • 1
  • 7
  • 3
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Jeroen Steenbeeke May 21 '21 at 06:40
  • 1
    I _am_ one of those readers in the future, and this is exactly the answer I need. Further explanation would be clutter. – Peter Wone Jul 08 '22 at 00:34
  • 2
    Thanks. Works for me. But first, it was not obvious to me what should I replace. My example: `code --folder-uri "vscode-remote://ssh-remote+john_doe@my.server.com/home/john_doe/workdir/myproject` – Ivan_a_bit_Ukrainivan Aug 15 '23 at 08:28
0

One way has been described in the link below: Remote Development using SSH.

As you can see in the middle of the page, "Opening a terminal on a remote host", it points out you have to establish an ssh connection first then when you write code . will automatically run on the remote host rather than locally.

Hope it works.

Milad Sikaroudi
  • 677
  • 6
  • 16
  • 1
    That doesn't answer the question of how to open vscode in remote mode from the command line in the first place. The link you shared assumes that you are already inside vscode's terminal with the ssh connection established. – Mei Zhang Jul 18 '20 at 05:34
0

I am not completely sure if this is what you are looking for, but can you check Code Server.

It runs VS Code remotely and you can access its UI using a Browser.

Abhik Sarkar
  • 901
  • 3
  • 12
  • 32
0

You can start a GUI on your remote pc from your local display here check this out or you can configure a VNC server tutorial and connect to your remote machine via a VNC client real vnc after all of this, you can either view the remote screen from SSH or from VNC. I recommend using VNC. so you can have full control of your remote host.

after the screen share is done you can either use terminal code . to open the vs code inside your project folder or use application to open the folder directly.

Viroj Fernando
  • 461
  • 4
  • 8
  • 1
    vscode already has ssh functionality, I just want to be able to open it from the command line. VNC is unnecessary. – Mei Zhang Jul 18 '20 at 05:36
0

If what you're actually wanting to do is automatically connect to a Remote Explorer ssh target directory from the command line, a way to do this would be to connect normally in vscode, save the workspace, then open the workspace from the command line, it should autoconnect back to the same ssh host and directory.

R. StackUser
  • 2,005
  • 4
  • 17
  • 24