Skip to main content

Command Palette

Search for a command to run...

Write and execute code directly in remote machines using VS Code

Access remote machines, develop and execute code in it, read log files, everything directly from VS Code using the most useful plugin "Remote-SSH"

Published
3 min read
Write and execute code directly in remote machines using VS Code

Access remote machines, develop and execute code in it, read log files, everything directly from VS Code using the most useful plugin "Remote-SSH"

Introduction

Now most of the developers using Visual Studio Code for development. And it provides various plugin to make developers code comfortably. I am writing this blog about one of my favourite plugin Remote - SSH which I am using every time to update code in remote server and check logs by running grep command in large log files and export the required contents in separate file and view easily. All these things can be done directly from the Visual Studio Code instead of connecting through a Putty terminal.

Installation & Configure

Install Remote - SSH from the Microsoft marketplace. After successful installation, You can find the "Remote Explorer" icon in the left navigation.

After Install

After installing the plugin, we need to create a config file with the list of remote server details which you wish to connect.Create a file in the below mentioned path with name sshConfig (without any extension)

Note : If you didn't have .ssh folder create new folder and enter name as .ssh. and save it

C:\Users\<your-username>\.ssh\sshConfig

Provide the remote server details inside the sshConfig file in the below mentioned format

Host dev
    HostName XXX.XX.XX.XXX
    User ubuntu
    IdentityFile "C:/Users/boopathikumar/.ssh/ubuntu.pem"

Host prod
    HostName XXX.XX.XX.XXX
    User ubuntu
    IdentityFile "C:/Users/boopathikumar/.ssh/ubuntu.pem"

Meaning of the terms used in the above format is explained below

  • Host - Provide any name for your remote server for further reference.
  • Hostname - Remote server Ip address
  • User - Username for login into the server
  • IdentityFile - Path of you pem key

Then select the settings icon near SSH TARGETS and add the sshConfig file path which we had created previously.

Add configuration file

After that you can see the list of remote servers configured in the sshConfig file inside the Visual Studio Code as shown below

List servers

Connect server

To connect to any particular server, Click on the folder icon next to the remote server name as highlighted below.

Connect servers

Then, Select the Operating system of the remote server.

Connect servers select OS

Once the server is connected, You can see the name of the host which you provided on sshConfig file on the bottom left corner.

Click on Open folder button to view the folders in the remote server.Select the folder that you need to view as shown below

Connect servers select OS

After that you can view files under selected remote folder on the explorer as shown below.

Connected

Also you can use the integrated terminal to run the commands on connected remote server directly.

Setup "Remote - SSH" and enjoy programming in a remote server directly from Visual Studio Code !!!.

More from this blog

B

Boopathi Kumar Nachimuthu

3 posts

DevOps enthusiast having experience in networking and programming. Working on multi cloud platforms. Giving back my solutions of my day to day problems to the community which helped me to learn.