Mount device with r/w access to specific user

How can I mount some device with read-write access for a given user?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can use the -o option, that will let you set up umask, owner and group owner for the mounted device.

For example :

mount -t vfat -o umask=0022,gid=33,uid=33 dev /var/www

That will mount a vfat device in /var/www with umask 0022, owner: user with ID 33, and group: group with ID 33.

Method 2

There’s no generic way to do exactly that. If the filesystem doesn’t have a notion of file ownership, it probably has a mount option (uid) to decide which user the files will belong to. If the filesystem does have a notion of file ownership, mount it read-write, and users will be able to write every file they have permission to.

If you only want a specific user to access the filesystem, and there is a FUSE driver for it, then arrange for the user to have read-write access to the device and mount it through FUSE as that user.

Another way to only let a specific user (or a specific group, or better fine-tuning through an ACL) is to place the mount point underneath a restricted-access directory:

mkdir -p /media/restricted/joe/somedisk
chown joe /media/restricted/joe/somedisk
chmod 700 /media/restricted/joe/somedisk
mount /dev/sdz42 /media/restricted/joe/somedisk

If you want some users to have read-write access and others to have read-only access regardless of file permissions, mount the filesystem read-write under a restricted access directory and use bindfs to make a read-only view of that filesystem.

bindfs -o perms=a-w /media/private/somedisk /media/public-read-only/somedisk

You can also make a bindfs view read-write to some users and read-only for others; see the -m and -M options in the bindfs man page. Remember to put the primary mount point under a directory that only root can access.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x