Mounting SSH with sshfs

You can mount an SSH connection with sshfs.

sshfs <user>@<server>:<remote_path> <local_mount_point>

You can unmount it with:

fusermount -u <local_mount_point>

Here's a shell script I use to mount and unmount several servers that I connect to frequently.

#!/bin/bash

# Get a count of files on the stage server
dirCount=`ls /mnt/Stage/ -a -1 | wc -l`

# If unmount was specified
if [ "$1" == "-u" ] ; then

	# Check if there are more files than an empty directory
	if [ $dirCount == 2 ]; then
		echo KSL servers are not currently mounted.
		exit
	fi

	# Unmount the volumes
	echo Unmounting KSL servers
	fusermount -u /mnt/Data
	fusermount -u /mnt/Pandora
	fusermount -u /mnt/Stage
	fusermount -u /mnt/Nest

else

	# Check if there are more files than an empty directory
	if [ $dirCount != 2 ]; then
		echo KSL servers are already mounted.
		exit
	fi

 	# Mount the systems
	echo Mounting servers
	sshfs root@data.example.net:/ /mnt/Data
	sshfs root@pandora.example.net:/ /mnt/Pandora
	sshfs root@stage.example.net:/ /mnt/Stage
	sshfs root@nest.example.com:/ /mnt/Nest

fi

exit
comments powered by Disqus
mounting_ssh_with_sshfs.txt · Last modified: 2020/06/01 22:53 (external edit)