Guide to Using Visual Studio Code's Remote SSH Plugin with Your Server

Introduction

Visual Studio Code (VS Code), through the Remote SSH plugin, allows you to connect to a remote server or virtual machine via SSH directly within your VSCode editor. This enables you to work with code on a remote system as if it were local, with full access to the remote file system and command-line tools.

This guide will walk you through the steps to install, configure, and use the Remote SSH plugin in VS Code.

NOTE: Each time you "Start" your server, it will be given a new IP address. You will have to update your config file with this new IP address each time before connecting with VS Code through the Remote SSH plugin.

Step 0: Install VS Code

Most of you will have VS Code already installed on your computer. If you do not, head to Visual Studio Code and follow the instructions for your operating system.

If you are on Windows, you can also use the Windows Store.

Step 1: Install the Remote SSH Plugin

  1. Open VS Code.
  2. Go to the Extensions view by clicking the Extensions icon in the Activity Bar on the side of the window.
  3. Search for "Remote - SSH" in the Extensions Marketplace.
  4. Click "Install" to install the Remote - SSH plugin.

Installing Remote SSH Plugin

Step 2: Configure SSH Settings

After installing the plugin, you need to configure your SSH settings to connect to a remote server:

  1. Open the Command Palette (Ctrl+Shift+P) and type "Remote-SSH: Open SSH Configuration File".

  2. Select the SSH configuration file to edit from the list provided (e.g., ~/.ssh/config).

  3. Add a new entry for your remote server:

    Host [MY_SERVER]
      HostName [SERVER_IP_ADDRESS]
      User root
      IdentityFile [PATH_TO_KEY_FILE]
    

    Replace [MY_SERVER] with a meaningful name, [PATH_TO_KEY_FILE] with the full path including file name for your SSH private key file, and [SERVER_IP_ADDRESS] with the IP address for the server from your dashboard.

  4. Save the file.

Step 3: Connect to the Remote Server

Now that your SSH configuration is set up, you can connect to the remote server:

  1. Open the Command Palette (Ctrl+Shift+P) and type "Remote-SSH: Connect to Host...".
  2. Select the server you configured from the list.
  3. VS Code will open a new window and connect to the remote server. You will be working directly on the remote machine.

Connecting to Remote Server

Step 4: Open a Remote Folder

Once connected, you can open a folder on the remote server to start working:

  1. Click on the "Open Folder" button in the VS Code window.
  2. Navigate to the directory on the remote server that you want to work in and click "OK".
  3. Your VS Code workspace will now be connected to the remote folder, and you can edit files, run code, and use the terminal as if the files were local.

Conclusion

With the Remote SSH plugin in VS Code, you can easily develop and manage code on remote servers or virtual machines. This setup is particularly useful for working on large codebases or when you need access to specific environments that are not available locally.

Logo

© Copyright 2024. Make Life Great LLC. All rights reserved.

FacebookFeedTwitter