Skip to content

Instantly share code, notes, and snippets.

@jhamman
Created January 27, 2014 04:40
Show Gist options
  • Save jhamman/8643375 to your computer and use it in GitHub Desktop.
Save jhamman/8643375 to your computer and use it in GitHub Desktop.
Remote mounting of unix file system
# mounting remote file systems
# References:
# http://www.larkinweb.co.uk/computing/mounting_file_systems_over_two_ssh_hops.html
# http://www.neverstopbuilding.com/mount-ssh-on-osx
export MOUNTS=$HOME/mounts
mount_remote() {
echo "Trying to mount to: $1"
if [ "$1" == "1hopmachine" ] ; then
MOUNTDIR=$MOUNTS/$1
if [ ! -d $MOUNTDIR ] ; then
mkdir -p $MOUNTDIR
fi
echo "mounting $1 to $MOUNTDIR"
# only mount home directory on spirit (also compress -C)
sshfs -C $USER@one.hop.machine.org:/path/to/mount $MOUNTDIR
cd $MOUNTDIR
elif [ "$1" == "2hopmachine" ]; then
MOUNTDIR=$MOUNTS/$1
if [ ! -d $MOUNTDIR ] ; then
mkdir -p $MOUNTDIR
fi
# find one that works ...
PORT="shuf -i 2000-65000 -n 1"
# PORT="jot -r 1 2000 65000"
# PORT=$(python -S -c "import random; print random.randrange(2000,63000)")
# PORT="awk 'BEGIN{srand();print int(rand()*(63000-2000))+2000 }'"
echo "mounting $1 to $MOUNTDIR via port $PORT"
ssh -C -f $USER@middlehopmach.my.network.org -L $PORT:$1.my.network.org:22 -N
sshfs -C -p $PORT $USER@localhost:/ $MOUNTDIR
cd $MOUNTDIR
else
echo "Unsupported remote mount, try spirit or a hydro machine (i.e. hydra or thermal) or edit your mount_remote function"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment