avatarJake Krajewski

Summarize

Mounting SSH connections so you can handle remote files as if they were local.

Do you want to edit remote files locally? Try this easy, secure way to mount your remote drives with SSHFS.

This can be you. Just break all your light bulbs and break out the hoodie. Photo by Kevin Horvat on Unsplash

Situation: You’ve got your Pytorch or Tensorflow machine learning instructions on a GPU server, or hardware project connected to the GPIO pins on your Raspberry Pi, or a remote docker container on your secure air-gapped network, and you really want to dig in with an advanced IDE.

In some cases, you can run a remote development environment, but if you’re connected to a lightweight system, or you don’t have full access, you might find yourself faced with using what’s available on the remote system’s command line — usually nano or vim. Great, if you want to get in and out quickly, but they’re not exactly exemplary in the user experience department.

SSHFS —Secure Shell File System

Along comes SSHFS. Pronounced like the sound a ninja star makes as it flies past your head (or you can just say the letters out loud if the pronunciation makes you feel weird). SSHFS is a way to securely mount a remote folder as if it were a folder on your local machine and it’s really simple.

What’s that mean?

It means you can navigate to and operate on your mounted remote files as if they were on your local machine!

And that means you can avoid transferring files back and forth, pushing and pulling commits, editing in tiny, cumbersome command line editors, and it’s secure. Also, did I say it was easy?

macOS:

On your local workstation, install FUSE and SSHFS from the FUSE site or with Homebrew:

brew cask install osxfuse
brew install sshfs

Once installed, make sure ssh is enabled on your remote system and connect to it with your terminal (how to SSH).

Here’s an example:

  1. Say you have a remote machine with a local address of 192.168.68.55 and you connect on port 9876. Your user name is ubuntu and you have your files stored in ~/Documents/MyDir/.
  2. Create a folder on your local workstation that sshfs will mount to, or a mountpoint. For example, you’d make this on your local: ~/Documents/projects/remote.

3. Type the following:

ssh ubuntu@192.168.68.55:/home/ubuntu/Documents/MyDir ~/Documents/projects/remote -p 9876

Here are the base rules:

ssh <user>@<address>:</remote/dir/> </local/mountdir> <options>

You’ll be prompted for a password if it worked correctly (or you can set up passwordless SSH login with keys). When you navigate to your projects folder now, you’ll see a mounted drive, accessible to your local filesystem. Easy peasy, lemon squeezy.

Unmounting

To unmount a folder on your local drive, use:

umount -f /local/mountpoint

Linux

Running is the same as on macOS, but installing is a bit different. Also see unmounting below.

Ubuntu/Debian

sudo apt update
sudo apt install sshfs

Redhat, CentOS

sudo yum install sshfs

Unmounting

fusermount -u /local/mountpoint

Windows

There are a few solutions for windows:

They each have slightly different methods, so I recommend following the instructions given in their documentation, but basically, you’ll use the Windows Explorer to map a network drive on the remote SSH machine.

Profit!

There you have it! This method doesn’t require any heavy lifting on the part of the machine you’re connecting to, and it really makes things easier on the beast of a machine you chose to do your work on. If you want to take it the extra mile (I know you do), then look up how to auto mount your drive so it’s always there!

Happy SSH’ing!

Ssh
Networking
Mount
Remote Development
Remote Filesystem
Recommended from ReadMedium