write access for user in usb mounted disk

Hello,

This is an old problem, but so widely spread on the net than after reading tons of pages I couldn’t find the real solution :frowning:

When I plug in an usb disk (for my last test, formatted ext4), udev mount it to /run/media/<user>, but read only. I want to be able to write to this disk, preferably only for the user.

Of course I can go root and brute force the permissions, but it should be smarter to trick udisk to do this for me, if possible for any file system.

any idea?

thanks
jdd
42.3, kde (dolphin)

I format my usb stick to ext4. Then I mount it using this command (as root):

mount /dev/sdc1 /mnt/sdc1

Then I run this command as root:

chown yourname:users /mnt/sdc1

Then I unmount the stick and take it out. From there on when I plug it into my usb slot it automounts for user yourname.
Of course, use your real name.
Is that what you wanted?

Sorry. It doesn’t actually “automount” by itself. It suggests to mount and I click-accept. (I use KDE.)

yes, I know that, and it’s what I call “brute force” :slight_smile:

But I have lot of USB devices, so this is not that friendly.

even more, I’m pretty sure I have write access on an other computer, but it may be depending of the file susyem. The udev rule set it to read only, rthere should be possible to have one setting it RW?

thanks
jdd

UID not you name is the owner. You can have the same name on two computers but not the same UID

the mount point is built dynamically by udev, so no such problem. It is


/run/media/&lt;username&gt;/&lt;diskID&gt;

jdd

No, it did not.

No, it did not.

“Doctor, it hurts when I stab myself in the eye”.

If you do not want to manage file access on every individual device, do not use filesystem that persistently stores file access information. Use FAT.

?
You know better than me what I have on my disk?

The disk is dynamically mounted on /run/media/<user>/<diskID> which is well under /run/media/…

permissions are drwxr-xr-x, owner root

and how do you manage to backup a linux system on FAT disk?, specially with large files?

but I could use the disk simply changing the folder owner to <user>:users (not what I wanted though)

I made an other test that may explain the problem, at least partially. I mounted an other usb disk and it was mounted with the user owner and rw, but by fuseblk


lsblk -no name,fstype

allowed me to see the filesystem is ntfs

but to backup a linux file system, ntfs is not that good (filename/length problems)

jdd

I know better than you how Linux works, yes.

You cannot bypass user access information on ext4 using normal means. Period. This answers your original question. If you now want to discuss how to backup your installation, that’s fine, but hardly belongs to this thread.

I was answering to you saying I have to use FAT…

the fact is it’s enough to change upper folder owner to solve the problem. In fact the disk was initially written by me with the same UDI, so absolutely no problem.

In place of making unfriendly remarks, could you explain a bit what bypass is there? I don’t ask to overwrite files permissions, only to mount the partition rw… as is done with ntfs, for example. Fuse file system gives me ownership of ntfs disk, why not ext4?

if you have an answer, please explain…

jdd

Mount point may have correct permission but do the files and directories? Remember this is a Linux file system and ALL permissions count :wink:

Le 12/11/2017 à 23:36, gogalthorp a écrit :
>
> Mount point may have correct permission but do the files and
> directories? Remember this is a Linux file system and ALL permissions
> count :wink:
>
>
yes, they have, and it’s not the point, I can’t even write on the root
folder of the disk

in fact I can do whatever I want on the disk as soon as the mount point
is set to <user> ownership. I only wonder why it’s not done on mount
when it’s done for ntfs file system by fuse. The reason may be that it’s
fuse, not ext4

I only seek for a way to mount an ext4 usb drive as <user> (because it’s
effectively mounted by an user mechanism, not really by root). I will
take care of permissions after that

thanks
jdd

Oh I see this thread is still threading along. I must say with all the ups and downs I’m not sure exactly what you want. Do you want this: if you push a usb stick into your openSUSE (or Leap) computer you would like it to mount the stick and present itself to you as an ext4 system with immediately writeable access for yourself (yourself being name:users). Is that what you want? Or do you want writeable access as everyoneintheworldincludingyouandroot:users?

Le 13/11/2017 à 13:46, swerdna a écrit :

> Oh I see this thread is still threading along. I must say with all the
> ups and downs I’m not sure exactly what you want. Do you want this: if
> you push a usb stick into your openSUSE (or Leap) computer you would
> like it to mount the stick and present itself to you with immediately
> writeable access for yourself (yourself being name:users).

exactly, like for any other file system than ext4 mounted by fuse

thanks
jdd

Hi
This is normal for filesystems that use security… if the device is the likes of exfat, vfat then it will let you write at the root of the device.

Remember lost+found needs to be owned by root:root, what about the journal and?

Create a directory owned by your user/group and move on… switch to exfat?

Le 13/11/2017 à 15:16, malcolmlewis a écrit :
>
> jdd;2844799 Wrote:
>> Le 13/11/2017 à 13:46, swerdna a écrit :
>>
>>> Oh I see this thread is still threading along. I must say with all the
>>> ups and downs I’m not sure exactly what you want. Do you want this: if
>>> you push a usb stick into your openSUSE (or Leap) computer you would
>>> like it to mount the stick and present itself to you with immediately
>>> writeable access for yourself (yourself being name:users).
>>
>> exactly, like for any other file system than ext4 mounted by fuse

> This is normal for filesystems that use security… if the device is
> the likes of exfat, vfat then it will let you write at the root of the
> device.

it let me also write on ntfs, that use also security (even if it’s
questionable)
>
> Remember lost+found needs to be owned by root:root, what about the
> journal and?

I only ask for same ownership than /home/<user>, nothing fancy
>
> Create a directory owned by your user/group and move on…

yes, I did, but not that friendly when using many usb disks

switch to
> exfat?
>
>
not possible for large files and linux file names…

I don’t ask for a default behavior, but the ownership is for sure
defined somewhere.

I worked a bit and see there is a solution through bindfs.

https://superuser.com/questions/519824/mounting-ext4-drive-with-specified-user-permission

But still, if there is a “manual” solution, it should be possible to
automate it

thanks
Note:

Le 13/11/2017 à 16:36, jdd a écrit :

> But still, if there is a “manual” solution, it should be possible to
> automate it

well, seems to be hard coded in udisk, I won’t fiddle with this, so I
will stay with the unfriendly but working solution:

  • plug the disk
  • launch Dolphin in root mode
  • change /media/run/<user>/<diskID> to <user>

it’s kept through umounts

thanks
jdd

On Mon 13 Nov 2017 03:36:14 PM CST, jdd wrote:

Le 13/11/2017 à 15:16, malcolmlewis a écrit :
>
> jdd;2844799 Wrote:
>> Le 13/11/2017 à 13:46, swerdna a écrit :
>>
>>> Oh I see this thread is still threading along. I must say with all
>>> the ups and downs I’m not sure exactly what you want. Do you want
>>> this: if you push a usb stick into your openSUSE (or Leap) computer
>>> you would like it to mount the stick and present itself to you with
>>> immediately writeable access for yourself (yourself being
>>> name:users).
>>
>> exactly, like for any other file system than ext4 mounted by fuse

> This is normal for filesystems that use security… if the device is
> the likes of exfat, vfat then it will let you write at the root of the
> device.

it let me also write on ntfs, that use also security (even if it’s
questionable)
>
> Remember lost+found needs to be owned by root:root, what about the
> journal and?

I only ask for same ownership than /home/<user>, nothing fancy
>
> Create a directory owned by your user/group and move on…

yes, I did, but not that friendly when using many usb disks

switch to
> exfat?
>
>
not possible for large files and linux file names…

I don’t ask for a default behavior, but the ownership is for sure
defined somewhere.

I worked a bit and see there is a solution through bindfs.

https://superuser.com/questions/519824/mounting-ext4-drive-with-specified-user-permission

But still, if there is a “manual” solution, it should be possible to
automate it

thanks
Note:

Hi
OK, unix/linux filesystem security :wink: exfat is 255 utf-16 characters,
file size shouldn’t be an issue unless you have a terra byte sized
one …

It is/can all be done via udev rules…

As root user run udevadm monitor and plug in a device, you can then
build up a rule for the device. You could label the disks and use
that format eg my_usb_disk_1 and then use a udev rule for a usb device
with a label my_usb_disk_* and set this. Else you need to change
manually the permissions…

But if you plug into another machine and it’s not the same user/group
then it won’t work… so your between a rock and a hard place…


Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
openSUSE Leap 42.2|GNOME 3.20.2|4.4.92-18.36-default
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below… Thanks!

Le 13/11/2017 à 17:49, malcolmlewis a écrit :

> OK, unix/linux filesystem security :wink: exfat is 255 utf-16 characters,
> file size shouldn’t be an issue unless you have a terra byte sized
> one …

problem is for FAT, ext4 have none that scares me :slight_smile:
>
> It is/can all be done via udev rules…

this is what I wanted to do
>
> As root user run udevadm monitor and plug in a device,

well, thanks, I didn’t know this

udevadm info /dev/sdc give this

ID_USB_DRIVER=usb-storage

that could be used

you can then
> build up a rule for the device. You could label the disks and use
> that format eg my_usb_disk_1 and then use a udev rule for a usb device
> with a label my_usb_disk_* and set this. Else you need to change
> manually the permissions…

I don’t want toi change permissions, only ownership of the mount point

I will have to read

https://wiki.archlinux.org/index.php/udev#Writing_udev_rules

see this tomorrow

thanks!

jdd

Well, I almost found the solution, and it was here from the beginning.

The problem is not “one can’t write because it’s a Linux file system”,
but as said here:

https://unix.stackexchange.com/questions/267008/how-can-i-permanently-change-the-ownership-of-a-mounted-device-under-media-us

“With file-systems having a concept of file-ownership (as ext3 you use),
things are different. As files on this file-systems have explicit
owners, the kernel honors them

witch is largely different from what was said here -or I didn’t read
fully, if so I’m sorry).

It means than as soon as root write a folder with user permissions, this
user can access the files rw

For example, if root made the backup of /home with rsync -av /home
/<mount point>, very user mounting the disk will be able to read and
write his own folders, being understood than users are identified by
UID, not name

I didn’t see this previously, because I tried to write on the root of
the disk (newly formatted for tests)

Thanks all for your patience, I learned much about udev, udisks and so on

jdd