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 "===========================================" |
I have changed
apt
toapt-get
, which I hope does not conflict with any other packages.