Connecting VS Code with a Remote Development Server
Tags: vscode, productivity, devops, tutorial
Published: 2020-02-11 15:41:35

---
title: Connecting VS Code with a Remote Development Server
published: true
date: 2020-01-08 13:54:42 UTC
tags: VSCode,productivity,devops,tutorial
canonical_url: https://engineerworkshop.com/2020/01/08/set-up-vs-code-with-a-remote/
cover_image: https://engineerworkshop.com/content/images/2020/01/kornel-mahl-mV4GwTDD8Tw-unsplash.jpg
---
## Table of Contents

* [Why Use a Remote Development Server?](#why-use-a-remote-development-server)
* [Benefits of Connecting VS Code with Remote SSH to a Remote Development Server](#benefits)
* [Prerequisites](#prerequisites-)
* [VS Code Remote SSH Setup](#vs-code-remote-ssh-setup-)
  - [Install the Remote Development extension pack in VS Code:](#install-the-remote-development-extension-pack-in-vs-code-)
  - [Connect To The Remote Development Server](#connect-to-the-remote-development-server-)
  - [Opening a Terminal in VS Code](#opening-a-terminal-in-vs-code-)

Previously, we discussed [how to set up a remote development server](https://engineerworkshop.com/2019/12/01/how-to-set-up-a-remote-development-server/) that will allow you to work from wherever on whatever hardware (and OS) you choose. It's one of the first steps in a series of improvements that will revolutionize your development workflow, making you more productive. In today's guide, we will continue that work with how to set up remote SSH with Visual Studio Code.

## Why Use a Remote Development Server? <a name="why-use-a-remote-development-server"></a>

For those just joining in, [I highly recommend that you go and read the first article in this series](https://engineerworkshop.com/2019/12/01/how-to-set-up-a-remote-development-server/). But for the sake of completeness, I will offer an abbreviated summary of the advantages of using a remote development server:

1. **Choose Your OS** - Using a remote development server means you get to choose the OS environment you enjoy working in. Like Windows but need to write code for a Linux server? No problem.
2. **Superior/Upgradable Hardware** - A mobile CPU that draws 15 W under load is simply outclassed by a Xeon or a Threadripper. Remote development lets you offload heavy tasks to the servers that handle them best.
3. **Persistence** - Remote development servers keep running even when you close your laptop lid. Have a time-consuming machine learning task? Let the remote development server grind away at it while you drive over to the coffee shop.

In short, using a remote development server means freedom: the freedom to choose your own OS, hardware, and work location. It gives you flexibility in your development workflow.

## Benefits of Connecting VS Code with Remote SSH to a Remote Development Server: <a name="benefits"></a>

In addition to the general benefits of using a remote development server described above, there are other benefits that are specific to using VS Code with Remote SSH. The biggest one is that remote development with VS Code is actually good and allows you to use your extensions.

Elaborating a little more, when you set up remote SSH with VS Code, VS Code does it intelligently. It knows that certain extensions, such as theming, are best applied locally and so it applies those extensions locally. Other extensions, such as IntelliCode, are best run on the server and so it runs those extensions on the remote server. This is all accomplished by the VS Code Server which is installed on the remote host automatically when you first set up VS Code with remote SSH.

## Prerequisites: <a name="prerequisites-"></a>

In order to add a remote development server to VSCode, I will assume you have completed the following:

- **A Running Ubuntu VM** - This will be our remote development server. Mine is called 'skunkworks' (half the fun + stress in creating a new server is naming it) and I run it out of a Proxmox virtualization server. [My remote development server stack can again be found in the previous guide](https://engineerworkshop.com/2019/12/01/how-to-set-up-a-remote-development-server/). An additional benefit of using VMs is that they're easily backed up and restored. Going to add a new service that you've never used before and may potentially ruin your pristine server? Take a snapshot and you can turn back time in seconds.
- **The above server has a running SSH server installed** - Again, simple task described in the above guide.
- **VPN Access to Remote Development Server** - Not strictly necessary if you're always going to be working on the same network as the server, but if that were the case it would hardly be remote now would it? 😉 Some people suggest opening a port on your router and port forwarding your SSH connection across it, but I highly recommend **NOT** to do this; take a look at your firewall logs sometime, there's a reason would-be attackers are always scanning port 22. Instead, I recommend that you set up a real VPN, that way even your connection to your "remote" development server is local from a network perspective. It's all about minimizing attack surfaces. My personal favorite is WireGuard since it's lightweight and can be installed locally on your VM. If you happen to already be [running unRAID in your homelab, the process is even easier](https://engineerworkshop.com/2019/12/11/how-to-set-up-wireguard-on-unraid/).
- **VS Code Installed** - I assume that if you're reading a guide on how to set up remote SSH with VS Code that you actually have said VS Code installed...

## VS Code Remote SSH Setup: <a name="vs-code-remote-ssh-setup-"></a>

With the prerequisites out of the way, let's begin setting up a remote SSH connection to our development server on Visual Studio Code.

### Install the Remote Development extension pack in VS Code: <a name="install-the-remote-development-extension-pack-in-vs-code-"></a>

Navigate to Extensions (Ctrl + Shift + X) > Search for "remote development" > Choose the "Remote Development" extension from Microsoft and install:

![Connecting VS Code with a Remote Development Server](https://engineerworkshop.com/content/images/2020/01/Code_tqfPDYE8wG-1.png)<figcaption>Steps to Install "Remote Development" extension from Microsoft in VS Code</figcaption>

### Connect To The Remote Development Server: <a name="connect-to-the-remote-development-server-"></a>

Launch the command palette (F1) and type "remote ssh". We're after "Remote-SSH: Connect to Host":

![Connecting VS Code with a Remote Development Server](https://engineerworkshop.com/content/images/2020/01/Code_3UJi0OPkaK.png)<figcaption>Remote-SSH: Connect to Host</figcaption>

You will then be prompted to either add a new SSH server or to go ahead and SSH to the remote server. I am going to assume you will want to routinely use this development server, therefore I recommend you select the "Add New SSH Host" option:

![Connecting VS Code with a Remote Development Server](https://engineerworkshop.com/content/images/2020/01/Code_Fqc6CIfNgk.png)

You'll then be prompted to SSH into your remote development server with a command of the form: ssh <user>@<remote development server name or IP address here>:

![Connecting VS Code with a Remote Development Server](https://engineerworkshop.com/content/images/2020/01/Code_mMqQrHTpwi-1.png)

Once you've add your new SSH host, you should get a popup in the bottom right of VS Code. Click on it to connect:

![Connecting VS Code with a Remote Development Server](https://engineerworkshop.com/content/images/2020/01/Code_AW05fmX3dG.png)

If you miss that pop-up, no worries. You won't have it anyway when you need to remote connect from VS Code in the future, so you may as well learn how to connect to SSH for future sessions. In order to initiate the remote SSH connection, again launch the command palette (F1) and type "remote ssh" selecting "Remote-SSH: Connect to Host" just like you did initially above, except this time instead of adding a new host, you'll just select your remote development server:

![Connecting VS Code with a Remote Development Server](https://engineerworkshop.com/content/images/2020/01/image-5.png)

A new window will open and you'll be prompted to enter your SSH password. (It's really easy to miss this prompt because of how VS Code's theme just blends in with the rest of the window, but it's right there at the top):

![Connecting VS Code with a Remote Development Server](https://engineerworkshop.com/content/images/2020/01/Code_u7b3FySPvF.png)

After that, you'll be remoted into your remote development server, which you can confirm by checking the bottom left corner of the window:

![Connecting VS Code with a Remote Development Server](https://engineerworkshop.com/content/images/2020/01/Code_ZVleNdfanC.png)

### Opening a Terminal in VS Code: <a name="opening-a-terminal-in-vs-code-"></a>

If you want to open a terminal within VS Code, you can do so with Terminal > New Terminal (or use the shortcut Ctrl + Shift + `):

![Connecting VS Code with a Remote Development Server](https://engineerworkshop.com/content/images/2020/01/Code_twJg4Au14B.png)<figcaption>Opening a terminal in VS Code</figcaption>

![Connecting VS Code with a Remote Development Server](https://engineerworkshop.com/content/images/2020/01/Code_RWqb2y8rNU.png)<figcaption>Terminal opened in remote development server</figcaption>

That's it! Welcome to the world of remote development. It has transformed my coding workflow. I hope it does the same for you.

* * *

As always, if you have any questions or comments, ask away below [or in the forums](https://forums.engineerworkshop.com/). The forums are also a great way to subscribe to the blog and receive updates when new guides are posted.