Use VSCode explorer with remote server (using SSH)

Viewed 10027

I need to code / edit files in a remote server using SSH, and I would like to access it with VSCode.

I'm on Windows 10, using "Git Bash" as integrated terminal in VSCode, which means I can connect to the server using VSCode's terminal.
What I'm missing is a way to open files from the terminal to the editor, and even better - interacting with the files using the explorer.

How can this be done?

5 Answers

Since the May, 2nd 2019 announcement of "Remote Development with VS Code", you now officially have:

Visual Studio Code Remote - SSH

https://microsoft.github.io/vscode-remote-release/images/ssh-readme.gif

The Remote - SSH extension lets you use any remote machine with a SSH server as your development environment.
Since nearly every desktop and server operating system has a SSH server that can be configured, the extension can greatly simplify development and troubleshooting in a wide variety of situations.

You can:

  • Develop on the same operating system you deploy to or use larger, faster, or more specialized hardware than your local machine.
  • Quickly swap between different, remote development environments and safely make updates without worrying about impacting your local machine.
  • Access an existing development environment from multiple machines or locations.
  • Debug an application running somewhere else such as a customer site or in the cloud.

Q1 2020: VSCode 1.42 improves support for Windows servers, including automatic OS detection.

Install extensions Code Runner and SSH-FS. Add config into your user setting like this:

"code-runner.runInTerminal":true,
"code-runner.fileDirectoryAsCwd": true,
"code-runner.ignoreSelection": true,
"code-runner.saveFileBeforeRun": true,
"files.eol": "\n",
"sshfs.configs": [
    {
        "label": "label",
        //Must use the root direction "/"
        "root": "/",
        "host": "host",
        "port": port,
        "username": "name",
        "password": "password"
        "name": "name"
    }]

Login your server account over ssh by the vscode terminal. Then you can edit and run your code on remote server.

Try disabling it and re-enabling it. It works for me.

I was able to log in via putty and ssh from terminal, so it wasn't that. It's just the configuration gets hung up or something.

All of the previous answers require installing a package from the VS Code Marketplace. Here is a solution, that won't even require you to install VS Code.

The Web Based VS Code Editor: Run VS Code on any machine anywhere and access it in the browser.

All you need to do is, first install code-server using:

$ curl -fsSL https://code-server.dev/install.sh | sh

Start code-server using:

$ code-server

After running this you can log on to https://127.0.0.1:8080 and view the web-based VS code.

To keep the service running in the background, use:

$ sudo systemctl restart code-server@$USER

You might also want to edit the configurations, for e.g., run it on 0.0.0.0:8080 instead of 127.0.0.1:8080 or to change the password - use:

$ nano ~/.config/code-server/config.yaml

I have used nano as my text editor, feel free to use your preferred text editor.

For in-depth setup and configuration guide: Setup Guide

Original GitHub repo for more info: code-server

Related