Monday, July 16, 2018

Visual Studio Code over SFTP/SSH SOLUTION: sshfs

So, here I am trying to use Visual Studio Code to do some real work, when it's ability to connect to my remote sftp server through gnome's gvfs connection randomly fails.  How dissapointing... Not having hours to figure out why its failing all of a sudden (although a reboot fixes the issue), I decided to look for another option.

Let me give you a quick background of what I'm doing:

OS: Fedora 28

I write Drupal (PHP) code with MS Visual Studio Code IDE which is lightweight and fast.

I use Gnome's nautilus remote folder location integration to mount the folders, which can then 'normally' be accessed by other applications, like vscode.  

Option #1: vscode extensions... I looked at these briefly but I was never really interested in using such an extension when I may need to connect to remote servers securely.  I am simply a bit paranoid that the extension code could be either malicious or buggy and render my connections insecure... So I discarded this option.  If I had more time, I might be inclined to double check the extension's code and functionality.

I'm hoping for a solution that's more or less standard, well supported, well documented, and included in the official Fedora packages.... granted vscode itself isn't part of the official packages, but my paranoia has limits.

Option #2: Looking for a tool to create a local mount of a remote SFTP server.  This would be the closest thing to a real filesystem, and it would take Gnome, Nautilus and vscode right out of the equation... leaving the OS to take care of providing me the remote files.

... And I found sshfs...

It's part of the official Fedora repo.

It's easy to use.

It's available for other OS'es  (Mac and Windows - seriously!).

Some will ask why not use vagrant's own sync folder... because, once again I don't want to be tied down to a particular technology.  If the remote server is not vagrant, then what?

Ok, here's how it works:

Step 1: Create a mount folder for the instance I would like to work on:

$ sudo mkdir /mnt/d8-vagrant

Mount the remote sftp folder:

$ sudo sshfs -p 2222 -o allow_other vagrant@127.0.0.1:/var/www/html/drupal /mnt/d8-vagrant/

That's it.  Now I can open /mnt/d8-vagrant whichever way I like... Brilliant!

Thanks for DigitalOcean's excellent docs for pointing me in that direction: https://www.digitalocean.com/community/tutorials/how-to-use-sshfs-to-mount-remote-file-systems-over-ssh

By the way, the DO docs/tutorials are nothing short of GREAT!  They are not always perfect, and they tend to have a lot of Ubuntu based articles, but for the most part it ports nicely to Fedora or RPM based systems.  They have very neat and creative ideas too.


No comments:

Post a Comment