Skip to content

Instantly share code, notes, and snippets.

@ibnesayeed
Last active May 1, 2020 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibnesayeed/e5c957a595656861e778e18ea8da0f20 to your computer and use it in GitHub Desktop.
Save ibnesayeed/e5c957a595656861e778e18ea8da0f20 to your computer and use it in GitHub Desktop.
Mount your remote machine's home directory locally over SSHFS

SSHFS Remote Home Mounter

Download the script, make it executable, and run:

$ chmod a+x remotehomemount.sh
$ ./remotehomemount.sh [<REMOTEID> [<MNTDIR> [<REMOTEHOST>]]]
#!/usr/bin/env bash
# Author: Sawood Alam <@ibnesayeed>
# Mount your remote machine's home directory locally over SSHFS
# Usage:
# ./remotehomemount.sh [<REMOTEID> [<MNTDIR> [<REMOTEHOST>]]]
set -e
# Define remote ID, local mount point, and remote host using ARGs
remoteid=${1:-$USER}
mntdir=${2:-/mnt/remotehome/$remoteid}
remotehost=${3:-linux.cs.odu.edu}
# Install sshfs, a FUSE over SSH
if ! [ -x "$(command -v sshfs)" ]; then
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get update
sudo apt-get install -y sshfs
elif [ -x "$(command -v dnf)" ]; then
sudo dnf install -y fuse-sshfs
elif [ -x "$(command -v yum)" ]; then
sudo yum -y install fuse-sshfs
elif [ -x "$(command -v brew)" ]; then
brew cask install osxfuse
brew install sshfs
else
echo "Install SSHFS https://github.com/libfuse/sshfs"
exit 1
fi
fi
# Create mount point directory and change the ownership to the local user
sudo mkdir -p $mntdir
sudo chown $(id -u):$(id -g) $mntdir
# Mount remote HOME folder to local mount point with UIDs mapped
sshfs -o default_permissions -o idmap=user $remoteid@$remotehost:/home/$remoteid $mntdir
# Test the success of mounting by listing remote files
ls -l $mntdir
echo "==========================================="
echo Mounted $remotehost:/home/$remoteid in $mntdir
echo "==========================================="
@machawk1
Copy link

On macOS 10.14.6, I run ./remotehomemount.sh and get the output on the command-line:

No Java runtime present, requesting install.
chown: machawk1: illegal group name

...and an alert box asking me to install Java:
Screen Shot 2020-03-26 at 1 30 51 PM

@ibnesayeed
Copy link
Author

I have changed apt to apt-get, which I hope does not conflict with any other packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment