Mount with user permissions linux

Mounting ext4 drive with specified user permission

I want to mount a supplementary ext4 data disk drive with specified rwx permission for a certain user. The mount point is inside the home of such a user and it’s owned by the user. I added the new data disk in /etc/fstab in the standard way:

/dev/hda /home/user/new_disk ext4 defaults,errors=remount-ro 0 1 

Anyway when the new partition is mounted, the ownership of the mount point change from user.group to root.root and so the user has no write permissions there. I can change manually the ownership of the mount point so the user can write there, but the problem reappear at each rebooting. I’ve even tried to add the disk in the fstab in the following way:

/dev/hda /home/user/new_disk ext4 umask=0077,uid=1000,gid=1000,errors=remount-ro 0 1 
  • mount the ext4 drive already with specified user permission, or
  • change the ownership of the mount point at each startup after the disk has been mounted.

I think that if I use the words «user,users» in the mounting options of fstab, the user would be able to mount the disk.

5 Answers 5

A FUSE filesystem for mirroring the contents of a directory to another directory. Additionally, one can change the permissions of files in the mirrored directory.

Mount the ext4 filesystem as /media/disk :

sudo mount -o user /dev/sdXN /media/disk 

Bind the mounted filesystem with permissions for the current user (or any other user/group):

sudo bindfs -u $(id -u) -g $(id -g) /media/disk /home/user/new_disk 

Only FAT, vFAT, exFAT support the uid , gid , umask options. You can check this by reading the list of the possible options in the mount man page, section «Mount options for fat».

However, you can change ownership of the existing directory system by using chown on the filesystem’s mount point, like:

# mount /dev/sda* /mnt/your/mountpoint/ # chown user:group 741 /mnt/your/mountpoint/ 

That changes the permissions on the file system permanently. Any user/group differences will be wiped out, and any SUID/SGID bits will be reset.

I’ve just encountered the same problem. What I’ve done is mounted the filesystem first, then changed all the permissions and owner:group on the mount point, subdirectories, and files. Then when I umount the filesystem and remount it these changes appear to be persistent.

15:24@boromir:/media$ cat /etc/fstab UUID=95446ed0-b6a6-42cd-8c37-ea81a0836e98 /media/cavalry1 auto defaults,nofail 0 0 15:26@boromir:/media$ sudo umount cavalry1/ 15:27@boromir:/media$ l total 28 drwxrwxrwx 2 boincuser boincuser 4096 2012-12-17 15:00 cavalry1/ 15:27@boromir:/media$ sudo mount -a 15:28@boromir:/media$ l total 28 drwxr-xr-x 3 boincuser boincuser 4096 2012-12-17 11:05 cavalry1/ 

Here you can see the permissions and owner aren’t reset upon remounting the filesystem.

Читайте также:  Linux мониторинг изменения файлов

When mounting an EXT filesystem, the permissions from the perspective of host filesystem appears to be what ever the guest filesystem already has.

Mount block devices as a user. To add to this topic, if all else fails, try guestmount from the libguestfs package, available in some distros since 2009, but also as source code. guestmount , uses file system in userspace (FUSE) to permit mounting, as a user, with user permissions. As long as said user owns the mount point, and has the appropriate access to the block device or image to be mounted. On some distros, (but for sure not Fedora or RedHat) the user may need to be a member of the fuse group in order to do this.

$ mkdir ~/mnt && guestmount -a /dev/hda -m /dev/hda ~/mnt 

This may also be used to mount any type of media for other platforms and file system images that QEMU knows about, not just linux media and windows flash drives. The operating system, file system type (ext4?) sub-device or partition number (did you mean /dev/hda1?), and logical block offsets are figured out automatically, so you might not even need to specify them in most cases.

Guest images. If you wish to mount drive images as a user, there is no need anymore to run fdisk -l to examine the partition table and multiply by the sector size to obtain the offset, for example, mount -o loop,offset=49152 . Good thing, since in some cases the image isn’t recognizable to fdisk . Something like this might still work though.

mkdir my_disk; guestmount -a my_disk.img -m /dev/sda1 my_disk 

It can even guess the operating system with the -i option and emulate the appropriate processors and drivers. Several examples are in the man page.

Known issues.

  • As with bindfs mentioned in https://superuser.com/a/831316/963137, there is some overhead accessing devices via fuse. So it’s not a permanent solution.
  • The mounted file system will appear to have permissions set to root when examined with ls -l , but, surprisingly, the user can indeed access and write to it. Try it!

Источник

Mount device with specific user rights

How can I mount a device with specific user rights on start up? I still have some problems figuring it out. I would like to mount the divide with uid=1000 and gid=1000 . My current entry to the /etc/fstab/ file looks like this:

dev /var/www vboxsf rw, suid, dev, exec, auto, nouser, async, uid=1000 

@skub: The owner of /var/www/ is root. dev /var/www vboxsf rw, suid, dev, exec, auto, nouser, async, uid=1000 gui=1000 didin’t work so well (Ubuntu removed the entry after a failed restart).

Читайте также:  Astra linux удалить драйвер принтера

@skub: It’s a VirtualBox shared folder, so /dev is is right. I figured it out by now, sudo mount -t vboxsf -o umask=0022,gid=33,uid=33 dev /var/www works just fine.

I’ve been messing around with this problem in vbox for a while now too. From what I’ve gathered, the correct solution (to the question you aren’t asking) is to add your user into the vboxsf group, and then it doesn’t matter who the owner of the files are — you will have permission to edit them. alcobrov.blogspot.com/2012/06/…

1 Answer 1

To mount a device with certain rights, you can use the -o Option directive while mounting the device. To mount the device you described, run:

 mount -t deviceFileFormat -o umask=filePermissions,gid=ownerGroupID,uid=ownerID /device /mountpoint 

For example mounting a VirtualBox shared folder to /var/www with www-data as owner would look like this:

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

If you want to mount the device on startup, you can add the following entry to your /etc/fstab file:

 /device /mountpoint deviceFileFormat umask=filePermissions,gid=ownerGroupID,uid=ownerUserID 

Again, with the same example the entry to the /etc/fstab file would look like this:

dev /var/www vboxsf umask=0022,gid=33,uid=33 

For filesystems that does not support mounting as a specific user (like ext4) the above will give the error

Unrecognized mount option "uid=33" or missing value 

to change the owner of an ext4 mount simply run

chown username /mountpoint 

after it has been mounted.

Источник

Mount USB drive with write permissions for everyone or specific user

Ultimately I need a perma-mount /dev/sdb2 to /home/storage with access right (rw) for the user media .

Using manual mount from command line.

server# sudo mount /dev/sdb2 /home/storage 

It mounts but the /home/storage receives root as owner and group and doesn’t allow media user to write there.

If I use mount command without sudo as the user media — i’m not allowed. Says only root can use mount.

If I use mount with options: server# sudo mount /dev/sdb2 /home/storage -o umask=000 I get what I need. A bit overdone of course, since the storage folder becomes writable for everyone. BUT — that is manually mounted — now i need it to remount on every reboot.

Remounting on reboot — using fstab **

So I thought I’ll be fine if I use fstab to mount this partition ( /dev/sdb2 ) every time i reboot. The fstab line I added:

UUID=8C52-C1CD /home/storage auto user,umask=000,utf8,noauto 0 0 

Got uuid with blkid . The fs type auto I changed a few times. I tried vfat too, but always on the reboot Ubuntu stops when processing fstab (I think) with the message (took from the log):

fsck from util-linux 2.20.1 /dev/sda5: clean, 120559/10969088 files, 19960144/43861504 blocks mount: unknown filesystem type 'static' mountall: mount /etc/fstab: [772] terminated with status 32 mountall: Filesystem could not be mounted: /etc/fstab: Skipping /etc/fstab: at user request 

And also — sudo mount -a never really does anything.

Читайте также:  Change linux mint to ubuntu

What am I doing wrong? I do suspect I messed up something:)

It seems fstab should hold only mounts for static drives, not any sort of usb stuff. I’m puzzled how then this works with all the people posting on the net their success stories.

However. if this is not possible — I would like to know how to remount my USB after every reboot. if not with fstab — then how? 🙂

Источник

Mounting volume/partition with permissions for user

What is the best practice for this situation, and what are the implications of each approach?

3 Answers 3

If it’s in /etc/fstab , then it will mount at boot. As only root has write permissions, you’ll need to modify it so that the user has those permissions. The best way is:

chown -R user /mnt/point

where user represents your user name (or user ID), and, obviously, /mnt/point represents the mount point of your file system. If the root group has write permission as well and you want another group to have it then you can use:

chown -R user:group /mnt/point

If the root group doesn’t have write access, then you can use chmod next:

That will give write permission to the group if it’s not there and read and execute to everyone else. You can modify the 775 to give whatever permissions you want to everyone else as that will be specified by the third number.

To better cover what you asked in your comment below:

You can add the user option to /etc/fstab , but that only allows the file system to be mounted by any user. It won’t change the permissions on the file system, which is why you need chown and/or chmod . You can go ahead and add the user option so that a regular user without sudo can mount it should it be unmounted.

For practicality, the best option here is chown as it gives the user the needed permissions instantly. The chmod command can be used afterwards if the permissions need to be modified for others.

Источник

Оцените статью
Adblock
detector