How to connect to Linux Server via Visual Studio Code

Discover how to seamlessly connect to a Linux server using Visual Studio Code. Enhance your development workflow with our comprehensive guide and tips.

Introduction

Visual Studio Code, commonly referred to as VS Code, is an integrated development environment developed by Microsoft for Windows, Linux, macOS and web browsers.

The VS Code Remote - SSH extension allows you to open a remote folder on any remote machine, virtual machine, or container with a running SSH server and take full advantage of VS Code's feature set. Once connected to a server, you can interact with files and folders anywhere on the remote filesystem. This extension allows you to work on files and folders on the Linux server directly from VS Code.

Features of VS Code Remote - SSH

The Remote - SSH extension lets you use any remote machine with a SSH server as your development environment. This 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.

No source code needs to be on your local machine to gain these benefits since the extension runs commands and other extensions directly on the remote machine. You can open any folder on the remote machine and work with it just as you would if the folder were on your own machine.

SSH Host Requirements

You can connect to a running SSH server on the following platforms:

x86_64 Debian 8+, Ubuntu 16.04+, CentOS / RHEL 7+ Linux.

Windows 10 / Server 2016/2019 (1803+) using the official OpenSSH Server.

macOS 10.14+ (Mojave) SSH hosts with Remote Login enabled.

Visual Studio Code is pre-installed.

How to install Remote - SSH extension and use it?

To connect to a Linux server via Visual Studio Code (VS Code), you can use the Remote - SSH extension. This extension allows you to work on files and folders on the Linux server directly from VS Code. Here’s a step-by-step guide:

Step 1 - Install the Remote - SSH Extension

1. Open VS Code.

2. Go to the Extensions view by clicking the Extensions icon in the Activity Bar on the side (or press Ctrl+Shift+X).

3. Search for Remote - SSH.

4. Click Install to add the extension to VS Code.

install remote-ssh extension
Step 2 - Ensure SSH is Installed on Your System

On Windows:

Open Command Prompt or PowerShell and run ssh to check if SSH is installed.

If not, install OpenSSH from Windows settings (Settings > Apps > Optional Features > Add a Feature > OpenSSH Client).

On macOS/Linux:

SSH is typically pre-installed. Confirm by running ssh in the terminal.

Step 3 - Configuring and Connecting the server

1. Select Remote-SSH: Connect to Host... from the Command Palette (F1, Ctrl+Shift+P)

install remote-ssh extension

2. Add hosting server

install remote-ssh extension

3. Connecting to the Server

install remote-ssh extension

4. Choose Config File (local) to Save SSH Information

install remote-ssh extension

5. Confirm to Connect

install remote-ssh extension

6. Input Server Password

install remote-ssh extension

7. Operate the Server

install remote-ssh extension
Step 4 - Work with Remote Files

1. Once connected, a new window will open with the server's filesystem accessible in the Explorer pane.

2. You can open, edit, and save files directly on the server.

3. Use the integrated terminal to run commands on the remote server.

install remote-ssh extension

With this setup, you can seamlessly develop on your Linux server using VS Code!