Programming code on computer screen.

Visual Studio Code SSH Access

BrianSnelgrove - April 6, 2021
Posted Under: Scripting
Use Visual Studio Code and SSH to work directly on your remote systems. Much easier and faster than FTP, SSHFS, SCP, etc.!

 

Unless otherwise noted, all directions are for Debian based systems. Most steps will work for other distributions but some commands may need modifications.
Visual Studio Code and SSH?

Yes, Visual Studio Code and SSH. I have used these together on both Windows and Linux based systems. The Windows systems did seem to take a little more tinkering than the Linux systems did but they both work beautifully once they were set up. I am not going to claim that I am an expert on setting the system up but was VERY easy to do on my Ubuntu 20.04 based system. Lets get started!

Install Visual Studio Code

Simple enough from the command line:

sudo snap install --classic code

Or from the Ubuntu Software center:


Well, that was easy enough. Now onto the SSH step.

Install SSH Extension

There are a lot of REALLY good extensions available for Visual Studio Code. In fact, the number of extensions available makes it one of my favorite development tools. On the left toolbar there is an icon to search extensions, click it and search for SSH. Click the blue Install button by Remote - SSH (not shown since it is already installed on my system):


Now you will have a new icon on the left toolbar (just above the extensions icon in the image above). Click it the click the + icon next to the SSH TARGETS menu:

An input box will open at the top of the screen allowing you to enter your SSH connection information. In my case I am using a pre-shared key and different port to connect, VS Code and the plugin took the additional SSH arguments without any issues. For example (no, this is not real information):

ssh user@server.com -i /home/user/user@server.com -p 80808

Once you have the connection information entered press the Enter key to save it, I selected my /home/user/.ssh/config file to save the connection information. Now you will have a server entry in the SSH TARGETS area, right click and connect. If you are not using a pre-shared key you will be prompted for a password and you should connect to the server.

This is the part where I had an issue with Windows, instead of spending a lot of time troubleshooting I attacked the problem with a sledgehammer and deleted the .ssh/config folder and re-entered the connection information. It was probably just a simple permissions issue that could have easily been fixed but, again, I didn't spend a lot of time troubleshooting.

Once you are connected click the Explorer icon at the top of the left hand menu and you will be browsing, editing, and updating your remote files in no time.

But Wait, There's More!

In addition to remotely editing your code you can use the VS Code built in terminal to run commands on the remote system. Think changing permissions, running your code, restarting processes, etc. 

When you are done, click the green SSH button in the lower left of your screen and select Close Remote Connection to disconnect from the SSH session.

Remember Kids: Work Smarter Not Harder

Whenever possible, you should strive to work smarter not harder. This is a simple plugin that makes remote development much easier. While I still like SSHFS when I need to copy/delete/whatever a bunch of files this solution is great when you are running a Windows system and connecting to remote Linux systems and it is much faster than mounting/un-mounting sshfs file systems on your local Linux workstation. 




Discussion - all postings are moderated