Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a folder ~/nas which I usually use sshfs to mount a network drive on. Today, I didn't realize the share hadn't been mounted yet, and copied some data into it. It took me a bit to realize that I'd just copied data into my own local drive rather than the network share. Is there some way to mark in the system that this folder is supposed to be a mount point, and to not let anyone copy data into it?

I tried the permissions solution here: How to only allow a program to write to a directory if it is mounted?, but if I don't have write access I also can't mount anything to it.

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

As long as you are not root, you simply could revoke the write permission for the ~/nas directory for yourself and use sudo for elevated mounting:

$ chmod u-w ~/nas
$ cd ~/nas
$ touch test
touch: cannot touch `test': Permission denied
$ cd ..
$ sudo mount -t fuse -o <options> sshfs#<user>@<host>:/mount/path/ ~/nas
$ cd ~/nas
$ touch test
$

The idea behind all that: ~/nas as the mount path would have the permissions assigned to it while the destination is not mounted, thus preventing modifications by you (as long as your user does not have root privileges). The mount command (needs root privileges to run) temporarily modifies the folder's permissions to whatever the destination's permissions are set to, allowing write access for your user.

share|improve this answer
1  
sshfs is a FUSE filesystem, which doesn't work with mount. Part of the purpose is so I don't have to be root to mount the nas (since I'm using my ssh credentials to mount it anyway) –  Collin Jun 28 '12 at 15:33
    
IIRC there are issues without mounting SSHFS as root. –  zebediah49 Jun 28 '12 at 15:36
    
I've never had any issues with an SSHFS mount, and I've never done it as root. –  Rob Jun 28 '12 at 17:18
    
@collin so even using sudo is not an option? –  syneticon-dj Jun 28 '12 at 22:37
    
@rob the problem is not the mount itself but the requirement to remove the user's write permission for the mountpoint. As the OP already found out, this would not work with fusermount. But it would work with mount.fuse –  syneticon-dj Jun 28 '12 at 22:41
show 3 more comments

We used the immutable-flag to protect the directory even for root-access.

chattr +i /vmdata/backup

This way even root is not allowed to write there when nothing is mounted. After mounting the disk, everything works as expected.

share|improve this answer
add comment

You can use the later suggested answer there:

1st: Check the with the mount command, if the directory is mounted

mount | grep <mountpoint> will tell you if there's anything mounted there. If you really want to make sure the right thing is mounted there you can use a more complex regex, but I don't think there's a need to.

share|improve this answer
    
It would be nice if I could prevent anything from writing to it, but I do mostly interact with the NAS though scripts, so this could be added to the common ones. –  Collin Jun 28 '12 at 15:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.