Visual Studio Code has become my default tool for almost everything I do these days when tinkering with automation and Infrastructure as Code. It’s also my default PowerShell editor and I have learnt to use the powerful plugins/modules that are made available through the Visual Studio Market Place Extension Library. It has come a long way from the Visual Studio that I used to host as Teams for customers back in the 2000’s while working at YOURasp and it took a while for me to work out it’s value. This was more because I always considered it a developer tool… and I am certainly no developer! However the more and more I have gotten into IaC the more I have realised its value as an all in one tool. I have even worked out how to Commit, Push and Pull projects too and from GitHub.

All that is cool, but the latest discovery might be the most useful of the lot! While working on Markus Kraus’s latest Ansible Roles for Veeam, he mentioned a change in his local Ansible dev environment. He started using the Remote Development Extension which includes a number of remote connectivity plugins in the one install. As soon as I installed it and connected to my first Linux server I knew it was going to make things that much more simpler when it comes to SSH connectivity to Linux systems and the editing and transfer of files.

The great thing about using Visual Studio Code to connect into and manage file modifications on Linux systems via SSH is that everything is there for you in the one Window. You not only have connectivity to the remote terminal session, but you have the ability to browse the partition for files and then edit those files right in the main window pane. The benefit of that is that you get to take advantage of the other extensions that make coding in Visual Studio a lot more streamlined. What is also saves you is time and effort to upload and transfer files as they are saved right there and then from the editor.

What it Looks Like:

Another great feature of this Extension is being able to maintain multiple sessions to the server which allows you to easily monitor systems while executed code or performing task. Shown above is a screen grab of me editing an Ansible playbook which I can then execute in the Terminal pane in the connected session, while the below screen grab shows another terminal session running TOP.

Setting it Up:

In terms of what you need to do to set it up and configure connections, it’s pretty straight forward and there is some great resources online already here.

In a nutshell once you have installed the Remote Development Extension

Press F1 and then get to the Command Short Cut Bar. In there type in SSH and chose Remote-SSH: Add New SSH Host… 

From there, enter in the command as you see below as you would connect to a host with ssh from the command line. If you want to edit the file directly, the format is pretty basic and can be easily worked out by opening the configuration file.

It then asks you to save it to a file location. Note that if you don’t have at least \.ssh\ present as a real directory you will get an error.

Connecting to Host:

From a New or Existing Visual Studio Code Window, Click on the Remote Connection Icon in the sidebar and then right click to get the options seen below that allow you to connect in a new window, or in the current window.

Like a normal SSH connection, on first connect it will ask you to verify and accept the server foot print. After that, if Certificate Authentication hasn’t been configured, you are prompted for the ssh user password.

From there you are connected and have an active session view via the Terminal pane. Once connected you can now open Folders or Files and edit at your hearts content right from within Visual Studio Code! With this in play, I probably won’t look to open another Putty window ever again! … that might be a stretch, but I know that moving forward, if I am doing any development or config work on a Linux system, I might skip the joys of VI or NANO and leverage the Power of Visual Studio Code!