SSHFS is a powerful tool that allows you to mount remote drives so they appear to be a part of your file system. This can be used to access your own personal account or a course account very easily from a home computer. SSHFS is freely available, and is built on user-space filesystems. It can be retrieved via MacPorts on a Mac machine, or by similar mechanisms on Linux distributions. This script is designed to target MacOS (Leopard, in particular); in addition to mounting the remote account filesystems in a convenient location for the command-line, these mounts will also be visible directly from within the Computer link in the Sidebar (if this is not visible, select it in Finder->Preferences->Sidebar). Unfortunately, instructions for Windows users are not available at this time.
To use this facility, you should have your home computer's ssh key on the remote accounts (see CF.CourseAccountSshKeyAccess); for security purposes, you should password-protect this key.
The following scripts should go in the bin
directory of your home computer, with constants and the connect function call updated as appropriate:
#!/usr/bin/env bash # The directory in which to mount remote filesystems on your local machine readonly basedir="$HOME/student.cs" # The options we'll be using to connect readonly optstart='-oauto_cache,reconnect,volname=' # Fix these paths if they are not correct for your machine readonly cmd_mkdir='/bin/mkdir' readonly cmd_sshfs='/opt/local/bin/sshfs' $(dirname $0)/disconnect eval $(ssh-agent) ssh-add connect () { while [[ $# -gt 0 ]]; do typeset server=fe-solaris.student.cs.uwaterloo.ca echo "Creating connection to $1" "$cmd_mkdir" -p "$basedir/$1" "$cmd_sshfs" "$1"@"$server":/u/"$1" "$basedir"/"$1" "$optstart$1@student.cs" shift done } # Update the following list of accounts to connect to. connect cs115 $(whoami)
This script first disconnects any lingering connections (see below), then launches a program to cache your ssh key locally in the script and connect to the list of accounts provided at the bottom.
#!/usr/bin/env bash readonly basedir="$HOME/student.cs" unmountdir () { if [[ -d "$1" ]]; then pushd "$1" >/dev/null for dir in *; do if [[ -d "$dir" ]]; then echo "Unmounting $1/$dir..." umount "$1/$dir" fi done popd >/dev/null else echo "Directory $1 does not exist" >&2 fi } unmountdir "$HOME/student.cs"
The setting for basedir
in this script must be the same as in the connect
script, and both scripts must be in the same directory for connect to be able to disconnect reliably.