Remote-SSH Extension for VS Code

The Remote-SSH extension in VS Code enables you to work on remote projects as if they were on your local machine. With Remote-SSH, you can connect to a remote server, edit files, run commands, and use VS Code’s development features.

Installing the Remote-SSH Extension

  1. Open VS Code.

  2. Go to the Extensions panel (Ctrl+Shift+X on Windows/Linux or Cmd+Shift+X on macOS).

  3. Search for Remote - SSH and click Install.

Connecting to a Remote Machine

After installing the extension, follow these steps to connect to a remote server via SSH:

  1. Press F1 or Ctrl+Shift+P to open the Command Palette.

  2. Type Remote-SSH: Connect to Host and select it.

  3. Enter the SSH connection details, e.g., user@remote-server.com.

  4. Select your preferred remote OS when prompted (Linux, macOS, or Windows).

Once connected, a new VS Code window will open, and you’ll be working within the remote environment.

Using the SSH Config File in VS Code

If you have an SSH config file (located at ~/.ssh/config), VS Code will automatically detect the hostnames you’ve configured.

  1. Press F1 and type "Remote-SSH: Connect to Host."

  2. You should see the hostnames from your SSH config file listed. Select the appropriate one to connect.

Remote-SSH Features

When connected via Remote-SSH, you can:

  • Open and edit files directly on the remote server.

  • Use VS Code’s terminal to run commands on the remote machine.

  • Install extensions specific to the remote environment.

VS Code handles the heavy lifting of syncing your local environment to the remote, making it a seamless experience.

Installing Extensions on the Remote Machine

Some extensions are required to be installed on the remote machine itself. When you attempt to use such an extension, VS Code will prompt you to install the remote version of the extension automatically.

For example, if you try to use the Python extension on a remote server, VS Code will prompt you to install the extension remotely.

# Example of opening a Python file remotely, which triggers extension installation.
code myscript.py

On Linux you may need to add the code command to your PATH environment variable. This can be done by creating a symbolic link to the code binary in a directory that is already in your PATH, such as /usr/share/code/code.

Alternatively, you can add the following line to your ~/.bashrc file:

export PATH=$PATH:/usr/share/code

Or you can create an alias in your ~/.bashrc file:

alias code='/usr/share/code/code'

Disconnecting from Remote-SSH

To disconnect from the remote session, simply close the VS Code window that is connected to the remote server.