I have recently begun using Visual Studio Code for development on linux. It is a fine Editor, and it seems as there is an extension for almost every development or dev-ops related task.
Although I am far from being an expert and for the most part use only a very small part of the available functionality, I must admit it makes my job much easier.
Something that makes VS-Code specially interesting for me is the possibility to edit (and debug) code on a remote machine. I still hold a special place in my heart for VIM, but I find myself using VS-Code more and more frequently to do things that I use to do with VIM and TMUX.
I have an office PC running Windows 10 so to work remotely on one of our RHLE or Debian servers I use the Remote Development extension pack.
Install the Open-SSH client
Installing the pack is surprisingly easy, and there is a very good article on the Visual Studio Code webpage: https://code.visualstudio.com/docs/remote/ssh.
It basically requires you to install an Open-SSH client. Since my local machine runs Windows I just followed the instructions to install the Windows 10 Open-SSH client using PowerShell:
First check what is installed by running:
PS C:\WINDOWS\system32 > Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
Name : OpenSSH.Client~~~~0.0.1.0
State : Installed
Name : OpenSSH.Server~~~~0.0.1.0
State : Installed
If you get
State: Installed
Then you are good to go. If you get:
State: NotPresent
It means you need to install the required component:
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
After that, you can test the installation by running:
ssh user@hostname
And making sure you can connect to the remote server using the Open-SSH client.
Install Remote Development extension pack
If you follow the instructions from the site below, you may have no problems.
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack
I don’t know for sure because I did not read all that. Instead, I looked in the available extensions until I found Remote-SSH and installed it. That worked for me, it may or may not work for you.
You will also need an SSH-Server running on the remote host.
Connecting to the Remote Host
Bring up your Command Palette (F1, Ctrl+Shift+P) and type:
Remote-SSH: Connect to Host...
Then the name of your server and Enter.
You may have to provide a username and password. After that, you should be able to open a folder on the Host and work as if it was a local directory.
There is quite a lot more detailed information on the VS-Code page I linked above, but for the most part that is all there is to it.
Happy coding!