Visual Studio Code Remote - SSH

3 min read 1 year ago
Published on Aug 18, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through using Visual Studio Code's Remote - SSH feature. This powerful tool allows you to connect to a remote server and edit files directly from your local VS Code environment. It's particularly useful for developers working on remote machines, enabling seamless code editing and debugging without the need for constant file transfers.

Step 1: Install Visual Studio Code and Extensions

  1. Download and Install Visual Studio Code

    • Visit the official Visual Studio Code website and download the installer for your operating system.
    • Follow the installation prompts to set up the application on your machine.
  2. Install the Remote - SSH Extension

    • Open Visual Studio Code.
    • Navigate to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side or pressing Ctrl+Shift+X.
    • Search for "Remote - SSH" in the Extensions Marketplace.
    • Click "Install" to add the extension to your VS Code environment.

Step 2: Configure SSH Connection

  1. Open the Command Palette

    • Press Ctrl+Shift+P to open the Command Palette.
  2. Add a New SSH Host

    • Type "Remote-SSH: Add New SSH Host" and select it.
    • Enter the SSH connection string in the format user@hostname, where user is your username and hostname is the IP address or domain of your remote server.
    • Choose the SSH configuration file to update (usually ~/.ssh/config).
  3. Configure SSH Options

    • You can specify additional options in the SSH config file, such as port number or identity file. For example:
      Host myserver
          HostName example.com
          User myusername
          Port 22
          IdentityFile ~/.ssh/my_key.pem
      

Step 3: Connect to the Remote Server

  1. Open the Command Palette Again

    • Press Ctrl+Shift+P.
  2. Connect Using SSH

    • Type "Remote-SSH: Connect to Host" and select it.
    • Choose the host you configured earlier from the list.
    • If prompted, enter your SSH password or passphrase.
  3. Verify Successful Connection

    • Once connected, the bottom-left corner of VS Code will display the name of your remote host.
    • You can now open files and folders from the remote server in your local VS Code window.

Step 4: Edit and Manage Remote Files

  1. Open Remote Explorer

    • Click on the Remote Explorer icon in the Activity Bar to view files on the remote server.
  2. Navigate and Edit Files

    • Browse through the directories and click on files to open them.
    • You can edit files directly, save changes, and even run terminal commands using the integrated terminal.
  3. Common Commands

    • Use the terminal to execute commands on the remote server as if you were working locally.
    • Remember to save files (Ctrl+S) after making changes.

Conclusion

You have now learned how to set up and use Visual Studio Code with the Remote - SSH feature. This allows you to work efficiently on remote servers while using the powerful editing capabilities of VS Code. For further exploration, consider looking into additional extensions or features that enhance your remote development experience, such as debugging tools or source control integrations. Happy coding!