How to mount a remote server folder
Background
I wanted to mount a specific remote folder sitting on a Linux-based server (for the purpose of this blog I call it hpc_data
) so that I navigate to it with Finder. More specifically I want to use the macOS c.q. brew
implementation of a little Linux-tool named rename
that for some particular reasons works much better in the brew
implementation.
I thought it would be easy with brew install sshfs
but this is no longer supported on macOS. I couldn’t figure it out with StackExchange and some blogs on Google. So, I turned to ChatGPT and got some great instructions. Yes, I admit it, I use ChatGPT. A lot actually, especially for coding related things; it helps a lot with fixing errors or setting up a well structured script.
Setting up a sshfs
-alternative on macOS
There sshfs
alternative method to mount remote directories on macOS works using macFUSE and FUSE for macOS with a replacement tool for sshfs
called osxfuse
or FUSE-T
.
Here’s how to set this up:
Step 1: Install macFUSE
Go to the macFUSE website and download the latest release of macFUSE.
Install the macFUSE package by following the instructions.
Step 2: Install `FUSE-T` as an `sshfs` Alternative
Once macFUSE is installed, you'll need to use a tool that provides sshfs
-like functionality on macOS. FUSE-T is a suitable replacement.
Install
FUSE-T
via Homebrew - I assume you havebrew
installed:
brew install macfuse
brew install gromgit/fuse/sshfs-mac
Step 3: Mount the Remote Directory
Now, you can mount your remote folder with sshfs
-like functionality using the sshfs-mac
tool:
Create your local mount point (if not already created):
mkdir ~/mnt/hpc_data
Mount the remote directory using `sshfs-mac`:
sshfs -o ssh_command="ssh -Y -i ~/.ssh/location_of_id_rsa_file -l YOUR_USERNAME -L 9999:location.of.server.com:22 location.of.server.com" YOUR_USERNAME@location.of.server.com:/data/location/on/your/favorit/sever ~/mnt/hpc_data
This should work similarly to sshfs
but using the updated macOS-compatible tools.
Step 4: Unmount When Done
When you're done, you can unmount the directory:
umount ~/mnt/hpc_data
or use:
diskutil unmount ~/mnt/hpc_data
This setup allows you to navigate the remote directory in Finder.
Taking it a bit further
However, I’d like to simplify the latter workflow. I’d like to have either a command I could type on the Terminal, for instance mount_hpc_data
.
Option 1: Use a Shell Alias/Function
You can add the `sshfs-mac` command to your shell configuration file (like `.bashrc` or `.zshrc`) to create an easy-to-use function or alias for mounting the directory. Here’s how to do it:
Open your terminal and edit your shell configuration file:
nano ~/.bashrc
I am a
bash
user - call me a Bourne-fan. The standard on macOS is nowadayszsh
, so it would benano ~/.zshrc
in that case. Anyway…Add the following function (or alias) for easy mounting:
function mount_bulkhpt() {
sshfs-mac -o ssh_command="ssh -Y -i ~/.ssh/location_of_id_rsa_file -l YOUR_USERNAME -L 9999:location.of.server.com:22 location.of.server.com" YOUR_USERNAME@location.of.server.com:/data/location/on/your/favorit/sever ~/mnt/hpc_data
}
function unmount_bulkhpt() {
umount ~/mnt/hpc_data
}
You could also replace this part
ssh -Y -i ~/.ssh/location_of_id_rsa_file -l YOUR_USERNAME -L 9999:location.of.server.com:22 location.of.server.com
with something likessh load_hpc_data
and set this SSH configuration to your.ssh/config
. In either case, this function will mount the remote directory to~/mnt/hpc_data
.Save the file (
Ctrl + X
, thenY
, and pressEnter
).Reload your shell configuration:
source ~/.bashrc
(or~/.zshrc
for the common users)Now, to mount the remote directory, simply type the following in your Terminal::
mount_bulkhpt
And when you're done, unmount it with:
unmount_bulkhpt
Option 2: Write a Simple Mounting Script
Of course, you can also dump the above in a dedicated script to handle the mounting process, which you can run anytime.
Create a script file:
nano ~/bin/mount_hpc_data.sh
Add the following content to the script:
bash
#!/bin/bash
sshfs-mac -o ssh_command="ssh -Y -i ~/.ssh/location_of_id_rsa_file -l YOUR_USERNAME -L 9999:location.of.server.com:22 location.of.server.com" YOUR_USERNAME@location.of.server.com:/data/location/on/your/favorit/sever ~/mnt/hpc_data
Make the script executable:
chmod +x ~/bin/mount_hpc_data.sh
Now, whenever you want to mount the folder, simply run:
bash ~/bin/mount_hpc_data.sh
Both of these methods allow you to easily mount remote directories.
In this case ChatGPT made my life a lot easier. It was only 5 minutes work, okay, excluding this blogpost. The amount time I already spend searching on StackExchange and Google was much longer - try 30+ minutes.
You may have to change some macOS security settings for this to work. Just follow the instructions when you first hit mount_bulkhpt
or run your mount_hpc_data.sh
script.
A paid alternative
Of course, the above is the cheep version: it’s free and if you’re an admin of your system you shouldn’t have any issues. There’s is also a great alternative that comes with a price, but it’s a good deal, especially in combination with the free version of it’s twin-buddy. I am talking about Mountain Duck. This little program settles in your menubar and in the Finder and enables you to load a remote disk after you opened a tunnel in Terminal.
In my use-case using Mountain Duck is very handy, as I can use some scripts, slideDupIdentify.py
or slideRename.py
, from the slideToolKit
that require dmtx
and show an image thumbnail. So I open a Terminal, navigate to the right folder, and use slideRename.py
to quickly rename some whole-slide image files on the remote folder. If you’re already using CyberDuck all your bookmarks will be readily available in Mountain Duck.