Remote Filesystem Mounting¶
Introduction¶
For users who prefer GUI file management, relying on editing your files using CLI text editors like vim, emacs, nano, etc. may be an inconvenient way to modify files. Alternatively, one could modify a file locally and then use SCP to transfer it to the CCI but this is also inconvenient and time consuming.
If you are one of those users, then there is a better solution: SSHFS: mounting CCI directories to your local machine. In other words, creating a directory that appears as if it were a natural folder on your computer but is constantly synchronized with a directory at the CCI. This synched directory includes all subdirectories and files within it as well. We can, for example, mount our CCI Home directory on our local machine over SSH and then edit the files locally using any text editor we'd like, CLI or otherwise! This includes vim, emacs, VSCode, Sublime, you name it.
Installation¶
The tool we'll use to mount a networked filesystem over SSH is called sshfs
. Some linux distros might include it already but it may need to be installed on your local machine. For Ubuntu/Debian as an example, it can be installed with:
sudo apt-get install sshfs
Setup¶
First, for convenience and simplicity of this tutorial, we'll create a main directory that will contain all of our mount points and subdirectories in it for each of the directories we want to mount. It's also good practice to have this directory of mount points should you ever want to apply this technique to other network accessible servers.
mkdir ~/mounts
cd ~/mounts
mkdir home
Usage¶
Now that we've got the SSHFS tool installed and our mount point created, let's actually create the connection. The tool's usage pattern is as such:
sshfs <USERNAME>@<HOSTNAME>:/path/to/desired/directory /path/to/mount/point -o <OPTIONS>
For our example we're going to be mounting our home directory, this will allow us to navigate all of our immediately accessible files and directories such as barn
, scratch
, and similar. Let's say your CCI project and username are EXPL and EXPLname respectively, the command to mount your home directory to the mount point we created above is as follows:
sshfs EXPLname@blp01.ccni.rpi.edu:/gpfs/u/home/EXPL/EXPLname ~/mounts/home -o follow_symlinks
The -o follow_symlinks
part is very important. Barn, Scratch, Barn-Shared, and Scratch-Shared appear as subdirectories within your home directory on the CCI systems, but they are actually symbolic links (symlinks in Linux lingo). Essentially they are shortcuts to where the directories are actually located within the CCI. Without this additional option provided to SSHFS, these shortcuts will appear as blank files to you on your local machine. With this option, SSHFS knows to keep an eye out for the shortcuts and populate them to their actual location when you try to access them locally.
To disconnect, close any windows or editors accessing the mounted directories and execute the following command:
sudo umount ~/mounts/home
You will be prompted for your local machine's sudo password. If this is unsuccessful and closing all windows and editors still doesn't work, rebooting the system will do the trick.
Creating (semi)permanent SSH connections¶
You'll notice that when you executed that sshfs command to mount your home directory locally, it asked for a DUO authentication and password. But what if we had set up SSH multiplexing?.
This sshfs tool mounts the networked filesystem and synchronizes it all over SSH, which means if we had an established SSH control socket, we could direct sshfs to use that existing connection and not require another CCI authentication!
Assuming that you have set up your SSH configuration as specified in the above examples on SSH Multiplexing, we could instead make our sshfs command as follows:
sshfs cci01:/gpfs/u/home/EXPL/EXPLname ~/mounts/home -o follow_symlinks
If the control socket for cci01 exists, then it will use that; otherwise it will ask for authentication via DUO and password.