Skip to content

Instantly share code, notes, and snippets.

@ibnesayeed
Last active May 1, 2020 22:47
Show Gist options
  • 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 "==========================================="
@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