Shortcut to mount SSHFS drives using bash functions

February 27th, 2013 by

SSHFS is a super handy tool, but the one-liner necessary to mount a remote drive is lengthy and can be a pain to remember. If you use SSHFS regularly, you probably have a few machines that you routinely connect to and thus can benefit from taking a shortcut.

On Linux (assuming you use bash) you will want to edit the file called .bashrc in your home directory. If it doesn’t exist, you can create it. This is where user created bash functions are stored. If you’re not familiar with bash syntax, it’s beyond the scope of this article but I will provide links for reference at the end. The bash function you want to write will look something like this:

sshmount() {
	if [ $1 = "proliant" ]; then
		sshfs 192.168.1.111:/ /media/proliant -p 3300
	elif [ $1 = "lappy" ]; then
		sshfs 192.168.1.105:/ /media/lappy
	else
		echo "Unknown server!"
	fi
}

Of course, you will want to edit this function and enter your own sshfs parameters and machine names. Once saved in your .bashrc file, you can mount the respective machine with a command such as “sshmount proliant”. This is certainly quicker than the unarbridged syntax!

This is a pretty good intro to bash scripting.

» «


Leave a Reply