You are not logged in.
I have a Lenny box at home that does various things including serving files and wanted to mount and unmount sshfs shares when my network was up or down so as to not have them stuck in limbo if network goes down, an example being when putting my laptop to sleep or hibernate.
This is how I set it up on my Debian Sid laptop and if anyone has some suggestions on how to improve it then please post, although it's working pretty well at present. It is limited to one mount point though so if you want to mount multiple sshfs locations you will need to rework the script.
The idea is to mount sshfs shares for all users to ~/.ssh/mount/$DIRECTORY if they add a config file called ~/.ssh/sshfs_mount which contains variables the scripts sources if the file exists.
Prerequisites
Before you begin you will need to setup ssh keys for the user/s on your computer to access the server via ssh as the user on the destination server. there are tutorials that you can google to achieve that.
mountsshfs:
As root place the following shell script into /etc/network/if-up.d/mountsshfs and make it executable to mount sshfs when networking comes up.
vi /etc/network/if-up.d/mountsshfs#!/bin/sh
# mount sshfs mount points from users
USERS=$(awk -F":" '$7 ~ /\/bin\/bash/ && $3 >= 1000 {print $1}' /etc/passwd)
for user in $USERS; do
USERHOME=$(awk -F":" '$1 ~ "'$user'" {print $6}' /etc/passwd)
# source the users mounts and mount them
if test -f $USERHOME/.ssh/sshfs_mount; then
. $USERHOME/.ssh/sshfs_mount
su $user -c "cd $USERHOME && sshfs $SSHFSSOURCE $USERHOME/.ssh/mount/$SSHFSMOUNT $SSHFSOPTS"
fi
done
#### END ####chmod +x /etc/network/if-up.d/mountsshfsunmountsshfs
for the reverse when the network goes down, place the following shell script into /etc/network/if-down.d/unmountsshfs and make it executable.
vi /etc/network/if-down.d/unmountsshfs#!/bin/sh
# unmount sshfs mount points from users
USERS=$(awk -F":" '$7 ~ /\/bin\/bash/ && $3 >= 1000 {print $1}' /etc/passwd)
for user in $USERS; do
USERHOME=$(awk -F":" '$1 ~ "'$user'" {print $6}' /etc/passwd)
# source the users mounts and unmount them
if test -f $USERHOME/.ssh/sshfs_mount; then
. $USERHOME/.ssh/sshfs_mount
su $user -c "cd $USERHOME && fusermount -u -z -o force $USERHOME/.ssh/mount/$SSHFSMOUNT"
fi
done
#### END ####chmod +x /etc/network/if-down.d/unmountsshfssshfs_mount
Now logged in as the user/s that you would like to mount sshfs for, create the following file. Be aware that the scripts only use accounts above 1000 which are typically non-system accounts. Change the scripts to suit you needs...
vi ~/.ssh/sshfs_mount# source of the mount point "user@[hostname|IP]:/sourcedir"
SSHFSSOURCE=mythtv@10.39.41.10:/home/media/
# mount to this directory
SSHFSMOUNT=mythtv-myriad
# sshfs options
SSHFSOPTS="-o umask=007"And make the destination directories. N.B. the script relies on ~/.ssh/mount existing so you if you want to change that you'll need to update the scripts.
In my case the command looks like this.
mkdir -p ~/.ssh/mount/mythtv-myriadReboot or down/up interface
At this point you can just reboot or bring down you network interface and up again and it should mount and unmount the sshfs mounts. e.g.
ifdown wlan0 && ifup wlan0#replace wlan0 with your interface obviously.
What I then did was created simlink's to the destination folders on the mount point. and example of what mine looked like is:
ln -s ~/.ssh/mount/mythtv-myriad/Videos/Documentaries ~/Videos/Documentaries
ln -s ~/.ssh/mount/mythtv-myriad/Videos/Educational ~/Videos/Educational
ln -s ~/.ssh/mount/mythtv-myriad/Videos/Movies ~/Videos/Movies
ln -s ~/.ssh/mount/mythtv-myriad/Videos/Television ~/Videos/TelevisionNotes:
I just use a Sidux program called ceni to configure my networking which just configures the correct options directly in /etc/network/interfaces so I have no idea if Wicd, Network Manager or any other network management programs will work with these scripts I'm sorry.
I run Debian Sid on a laptop and had to add the following to get my wireless back online after a suspend or hibernate. This also triggers the sshfs mount scripts. You may or may not need it depending on how your laptop or Linux Distro handles it.
vi /etc/pm/sleep.d/45wlan.shcase "$1" in
hibernate|suspend)
ifdown wlan0
;;
thaw|resume)
ifup wlan0
;;
*)
;;
esac
exit $?This post was done in hindsite so if I have made any mistakes please let me know.
Edit: updated typo of directory path from /etc/network/if-up.d/unmountsshfs to /etc/network/if-down.d/unmountsshfs as per advise from razzamatazz.
Last edited by jelloir (2010-04-23 10:51:12)
Offline
theres an ssh howto on the wiki
http://crunchbanglinux.org/wiki/howto/ssh
doesn't have anything on sshfs so ill link back to this
- - - - - - - - Wiki Pages - - - - - - -
#! install guide *autostart programs, modify the menu & keybindings
configuring Conky *installing scripts
Offline
Wouldn't you want to place unmountsshfs script into the /etc/network/if-down.d/ directory?
Offline
Wouldn't you want to place unmountsshfs script into the /etc/network/if-down.d/ directory?
Yes! Thanks for picking up the mistake I have updated the post. Cheers!
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.