SSHFS support for Custom Desktop Backup
GreenAnt provides a number of custom protocols for data exchange. SSHFS is a file system using the Secure SHell system. It is the preferred protocol for mounting a local share due to it's high security and performance.
How To Use SSHFS to Mount Remote File Systems Over SSH
- this document is adapted from this DigitalOcean Document and is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
In many cases it can become cumbersome to transfer files to and from a droplet. Imagine a development usage scenario where you are coding apps remotely and find yourself uploading a script repeatedly to your virtual server to test. This can become quite a hassle in a very short period of time. Luckily there is a way to mount your VPS file system to your local computer so you can make changes on the fly and treat your droplet as local storage. In this article, we will show you how to do exactly that.
SSHFS is Linux based software that needs to be installed on your local computer. On Ubuntu and Debian based systems it can be installed through apt-get.
sudo apt-get install sshfs
On Mac OSX
You can install SSHFS on Mac OSX. You will need to download FUSE and SSHFS from the osxfuse site.
To install SSHFS in Windows you will need to install some extra software. There are three main alternatives to mount SSHFS shares:
- open source
- a simple SSHFS client which has not been updated since 2012 but works with Win7 and lower
- closed source but free for personal use
- simple to use
- a commercial product
- lot of advanced options but probably overkill for most uses
Out of these three, we recommend SFTP NetDrive for most use cases.
Installing SFTP NetDrive
Please follow the Installation Instructions on the SFTP NetDrive site.
Download the setup file and double click to launch the installer. You may be prompted to download additional files, if so the installer will download the .NET Framework 4.0 and install it for you.
Mounting the Remote File System
The following instructions will work for both Ubuntu/Debian and OSX. Instructions for Windows systems can be found at the bottom of the tutorial.
To start we will need to create a local directory in which to mount the remote file system.
sudo mkdir /mnt/greenant_files <--replace "greenant_files" with whatever you prefer
Now we can use sshfs to mount the file system locally with the following command. Please replace your
sudo sshfs -o allow_other,defer_permissions USERNAME@files.greenant.net:/ /mnt/greenant_files
If your SSH share is configured for login via ssh key authorization, you will need to tell sshfs to use your public keys with the following command. You will be asked to enter the passphrase you used during the creation of your keys with ssh-keygen.
sudo sshfs -o allow_other,defer_permissions,IdentityFile=~/.ssh/id_rsa USERNAME@files.greenant.net:/ /mnt/greenant_files
Now you can work with files on your GreenAnt Storage as if it were a physical device attached to your local machine. For instance, if you move to the
/mnt/greenant_files directory on your local machine you can create a file locally and the file will appear on your GreenAnt Storage. Likewise you can copy files into the
/mnt/greenant_files folder and they will be uploaded to your GreenAnt Storage in the background.
Unmounting the Remote File System
When you no longer need the mount point you can simply unmount it with the command
sudo umount /mnt/greenant_files
Permanently Mounting the Remote File System
SSHFS also allows for setting up permanent mount points to remote file systems. This would set a mount point that would persist through restarts of both your local machine and droplets. In order to set up a permanent mount point, we will need to edit the
/etc/fstab file on the local machine to automatically mount the file system each time the system is booted.
First we need to edit the
/etc/fstab file with a text editor.
sudo nano /etc/fstab
Scroll to the bottom of the file and add the following entry
Save the changes to
/etc/fstab and reboot if necessary.
Using Win-SSHFS to Mount Remote File Systems on Windows
After launching the win-sshfs program, you will be presented with a graphical interface to make the process of mounting a remote file share simple.
- Click the Add button in the lower left corner of the window.
- Enter a name for the file share in the Drive Name field.
- Enter the IP of your droplet in the Host field.
- Enter your SSH port. (Leave as port 22 unless you have changed the SSH port manually).
- Enter your
USERNAMEin the Username field.
- Enter your SSH password in the password field. (Note on Windows you will need to have your droplet configured for password logins rather than ssh-key-authentication).
- Enter your desired mount point in the Directory field. (Enter
~/for your home directory).
- Select the drive letter you would like Windows to use for your droplets file system.
- Click the Mount button to connect to the droplet and mount the file system.
Now your virtual server's file system will be available through My Computer as the drive letter you chose in step 8.
Usage of the Remote Mount Point
The remote mount behaves similarly to locally mounted storage: you are able to create, copy, move, edit, compress or perform any file system operations you would be able to do on the remote files, but you are not able to launch programs or scripts on the remote server.
One typical usage of this would be if you host a website connected to your SSH share and need to make changes to the website on a regular basis. Mounting the file system locally allows you to launch whatever code editor, IDE, or text editor you wish to edit the site, and any changes you make will reflect on the virtual server as soon as they are made on your local machine.