DEV Community

TJ Kolleh
TJ Kolleh

Posted on

Use local dev tools on remote files with SSHFS

I often have to work with virtual machines or remote hosts. To utilize my local development environment while doing so I configure SSH and SSHFS. Enabling the use of tools on the local host while working with files on the remote, with the security of ssh.

SSHFS (SSH filesystem) enables the mounting of a remote directory over a normal ssh connection to the local filesystem. Prior to installing, make sure SSH is setup with the appropriate keys.

  1. Download & Install FUSE for macOS
  2. Download & Install SSHFS

Mount remote filesystems

The following command mounts the remote directory to a specified mount point.

sshfs username@remotesystem:/remote/path/to/directory ~/mount/point
Enter fullscreen mode Exit fullscreen mode

The rmount and rumount bash scripts facilitate convenient mount and unmounts using sshfs. To begin using the scripts.

  1. Create a folder named mounts in your user home directory, ~/mounts.
  2. Download the scripts and make them executable, chmod u+x <path-to-script>.

The functions reference host named in the local ~/.ssh/config file, configured with a key pair (without a password). See earlier blog post on the subject for reference.

Host ml
  HostName ec2-*
  User ubuntu
  PreferredAuthentications publickey
  IdentitiesOnly yes
  IdentityFile ~/.ssh/aws
  Port 22
Enter fullscreen mode Exit fullscreen mode

Executing rmount ml - will mount the entire filesystem to a local ml (~/mounts/ml) folder. A folder created by the function. The default "mounts" path, created earlier, can be changed by modifying the function. Executing rmount ml:/home/ec2-user mounts the ec2-user directory in ~/mounts/ml/. Running rumount ml, removes the ml folder and unmounts the remote filesystem.

With a remote filesystem mounted locally, local development tools can be used without having to download each file or having to remember to sync files. Its a secure tunnel to your remote filesystem where files behave almost as if they're local.

I'm publishing this as part of 100 Days To Offload. You can learn more by visiting #100DaysToOffload.

Original post...

Top comments (0)