Signup/Sign In
LAST UPDATED: APRIL 9, 2023

How to use VS Code for Remote Development via Remote SSH Plugin

    Suppose you have a Windows workstation but you want to run your code on a Linux machine, then how will you do it?

    In this tutorial, we are going to learn how you can execute your local programs on a remote server with the help of Visual Studio Code.

    Visual Studio Code is s popular Integrated Developer Environment (IDE) for software developers. It has a large collection of various plugins and it is a cross-platform IDE. VS Code has a plugin called Remote-SSH plugin which helps developers to enable software development.

    After this tutorial, you'll be able to enable the Remote-SSH plugin and configure VS Code to execute programs on a remote server.

    Remote Development with Visual Studio Code and Remote SSH Plugin

    Prerequisites to use VS Code

    • A local development machine running Windows, MacOSX, or Linux.

    • Visual Studio Code, which you can download and install from the official website.

    • An SSH key pair generated

    Add Remote-SSH plugin to VS Code

    Press Ctrl+Shift+P which will open the command palette then type "Install". A sidebar will be opened from where you can search for Extensions. Search for "Remote-SSH" and install the first extension. It's published by Microsoft.

    Remote SSH Plugin

    This extension supports Windows, macOS, Ubuntu, Debian, CentOS, RHEL, and Raspbian. If you are using macOS, you need to enable the Remote Login feature.

    Now, copy your SSH public key over to your server’s authorized_keys file. VS Code does not fully support password-based authentication, you'll need to enter your password every time you run a command.

    Now, Press Ctrl+Shift+P again to open the command palette. Search for “remote explorer” and you will see the command “View: Show Remote Explorer”, click on it. It will open a remote side panel, if "SSH Targets" is not selected then select it from the dropdown.

    SSH Targets

    You can see "SSH Targets" in the side panel, hover over it and click on the plus button. It will create a new connection. A popup window will be opened, enter your server details in that window. This needs to be a complete SSH connection command where -A flag is used to enable agent forwarding. It will allow you to use your local keys when running SSH commands on the server.

    ssh user@example.com -A

    You'll then need to choose an SSH configuration file. You can choose it from your default user file, system settings file, or a custom location.

    Now, your new host is added to the Remote Explorer Sidebar. The first run setup can take some time while VS Code is configuring the remote host and its server component. Click on the folder icon next to the sidebar's name to open a connection in a new VS Code window.

    Using Remote Connections

    After this, you'll see a regular VS Code window. Click on the "Open Folder" button in the top-left of the sidebar. A prompt may be open to acknowledge a Workspace trust Prompt, click "yes" and enable all editor features.

    Alright, now you can see the directories in your VS Code window. You can now open files, and edit them. if you’re working in a Git repository, you can use the built-in source control features to stage and commit changes as usual.

    Remote SSH Plugin

    If you have .vscode files in the directory then it enables features like builds and debugging. You can press F5 to start your app if a build system is defined. You can execute files in the remote directories with VS Code.

    You can execute commands on your remote server using the terminal of VS Code. The terminal will connect to the selected host too.

    If you open a directory, it will always show up in the Remote Explorer sidebar. Click on its name and a new VS Code window will be opened to that remote directory.

    Configuring the Extension

    You can specify the path to a custom SSH configuration file and you can add a default connection prompt too. This will stop the Visual Studio Code to wait for the remote host if it goes unresponsive. You can access the extension setting using the "Remote-SSH: Settings" command.

    Remote SSH Plugin Default settings

    "Default extensions" settings allow VS Code to install the extensions on all remote SSH hosts. If you've not added these extensions to your projects .vscode file, still the extensions will be available.

    The Checkfobes control automatic agent forwarding which will correspond to default SSH client settings in your SSH configuration file.

    The rest of the settings will allow you to customize how Visual Studio code exposes and connects to the remote server. You can use either a socket or a port. You can use pool connections and a custom SSH binary path.

    Conclusion

    You can easily work on remote hosts using this extension. You do not need to synchronize files between machines. VS Code is a powerful editor to work on the remote server than mount the remote file system locally or using remote access software.

    VS Code also supports Docker containers, Windows Subsystem for Linux, and GitHub Codespaces. You can have a first-class development experience using VS Code.

    Frequently Asked Questions

    1. How can I add the Remote-SSH plugin to VS Code?

    To add the Remote-SSH plugin to VS Code, Press Ctrl+Shift+P to open the command palette, type "Install", and search for "Remote-SSH" in the Extensions sidebar. Install the first extension published by Microsoft.

    2. What are the prerequisites to using VS Code for remote development via Remote SSH Plugin?

    Prerequisites to using VS Code for remote development via Remote SSH Plugin is that you need a local development machine running Windows, MacOSX, or Linux, Visual Studio Code, and an SSH key pair generated.

    3. What types of operating systems are supported by the Remote-SSH plugin?

    Operating systems supported by the Remote-SSH plugin are Windows, macOS, Ubuntu, Debian, CentOS, RHEL, and Raspbian.

    4. How can I customise the Visual Studio Code that connects to the remote server?

    You can customise the Visual Studio Code that connects to the remote server using the settings available in the Remote-SSH plugin.

    Proficient in Java, Python, and web development; has a knack for writing clearly about complex topics. Dedicated to giving readers the tools they need to learn more about computer science and technology.
    IF YOU LIKE IT, THEN SHARE IT
    Advertisement

    RELATED POSTS