• How to change ownership of subdirectories under /media

    From Haines Brown@21:1/5 to All on Sat May 3 12:30:02 2025
    I want to enable a user to copy files to a USB key mounted on a directory
    under /media.

    I can change the ownership of that directory to that of the user, but
    when I mount the the key on it the ownsrhip reverts to root. As the
    result a user cannot copy files to the key. I would enable the user to
    copy files to the key and preserve their ownership.

    This must be a common problem, but I have not found a solution on
    line or in man mount.


    --
    Haines Brown

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Frank Guthausen@21:1/5 to Haines Brown on Sat May 3 14:20:02 2025
    On Sat, 3 May 2025 06:22:45 -0400
    Haines Brown <haines@histomat.net> wrote:

    I want to enable a user to copy files to a USB key mounted on a
    directory under /media.

    I can change the ownership of that directory to that of the user, but
    when I mount the the key on it the ownsrhip reverts to root. As the
    result a user cannot copy files to the key. I would enable the user to
    copy files to the key and preserve their ownership.

    Did you change ownership before mounting? In this case the ownership
    of the /media folder on the local filesystem is changed, but not the
    ownership of the filesystem's root folder on the USB which will appear
    below /media folder after mounting the filesystem. During the mount you
    see the ownership and permissions of the mounted filesystem, but not the corresponding information of the mountpoint.
    --
    kind regards
    Frank

    -----BEGIN PGP SIGNATURE-----

    iQGzBAEBCgAdFiEE86z15c6qwvuAkhy+zDIN/uu9BloFAmgWCTIACgkQzDIN/uu9 BlpOUQv/VZNJ1ZWLCMGUgHx9GJ3enKHq74UUOIa3Uj6UhbdYYcIa6hMOkmUay+ED 7KHFnsVmQsuzhHeID0c5MSRIJtVfHywx6JmBrdLs2cPUyyx56gsR2GjuUbUE6WTL FEzVMQWmrt7s+F4Ps/LFQQHYvXXHcyvqY2HNBjmVZuExa9wMOWtB559Pxne6l90k aX5+WdLZSzsyvrQZrxxCrxE2NL+ap9JCeyBBZmDx1gODYOaOcHWQdbtqrz0WqN7o wnX3aZ7k9tTuGaOsnxrtAvdZT2e2lEyyS+pjfBrFQ4OKgbIG/8G2eSDZil+R6Xig dUw+Nx2W6ppaMyfwHdruJgnY1K8yZ/LrvhODBHruF8AM2FRsdCzNDU3HFaxtj8tU uTMMWH54xV3CyMKy+2NNFTCeIhfzpScZw7gH+BOKZrOnejmgwKfGt2WtpTCXxsUW DBv3VmclsQHidCZQlttA9fQ+IWtJoKEARTLt7XQSsOctaDsWxBIIY34h7StOxwQl
    g/EWltpE
    =M1CL
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andy Smith@21:1/5 to Haines Brown on Sat May 3 16:40:01 2025
    Hi,

    On Sat, May 03, 2025 at 06:22:45AM -0400, Haines Brown wrote:
    I want to enable a user to copy files to a USB key mounted on a directory under /media.

    Are you talking about the automatic mounting under /media of a user's
    removable media devices (USB keys etc) under a desktop environment, or
    manual mounting that you are doing with "the "mount" command and/or the /etc/fstab file, possibly outside of a desktop environment?

    I can change the ownership of that directory to that of the user, but
    when I mount the the key on it the ownsrhip reverts to root.

    The reason why I ask the above is that under a mainstream Linux desktop environment you problem doesn't really exist - the current user's media
    will be mounted under /media/$USER/<something> and owned by them. The
    only way you should experience the problem you're describing in that circumstances is if you are trying to do file operations on the
    removable media as a user OTHER than the one logged in to the desktop environment.

    However if you are manually as root using the "mount" command to mount something under /media then yes by default the mount point is usually
    going to be owned by root.

    If the filesystem on the media supports Linux permissions then you could
    change the ownership of the root of it after it is mounted.

    If the filesystem doesn't support Linux permissions, like the common
    range of Microsoft filesystems like fat, exfat, vfat etc that are often
    seen on removable media, then you would need to specify the desired
    owner/group in the mount options either on the "mount" command line or
    in the options field in fstab.

    If your question has not by now been answered by this and other
    responses you've received, please post a transcription of your exact set
    of steps including full command output, "ls -la" of the mount point
    directory before and after your mount, contents of your /etc/fstab, and
    no censored details.

    Thanks,
    Andy

    --
    https://bitfolk.com/ -- No-nonsense VPS hosting

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Hans@21:1/5 to All on Sat May 3 19:30:01 2025
    This is a multi-part message in MIME format.

    Am Samstag, 3. Mai 2025, 12:22:45 CEST schrieb Haines Brown:
    I want to enable a user to copy files to a USB key mounted on a directory under /media.

    I can change the ownership of that directory to that of the user, but
    when I mount the the key on it the ownsrhip reverts to root. As the
    result a user cannot copy files to the key. I would enable the user to
    copy files to the key and preserve their ownership.

    This must be a common problem, but I have not found a solution on
    line or in man mount.

    We need some informations of the environment:

    1. Which filesystem do you want to mount? FAT, FAT32, VFAT and exfat should work without any
    changes. Do they?

    2. Do you want to mount different devices or always the same?

    3. Do you want to allow it only one special user, several or all users?

    I had a similar problem in the future. But I only need to allow it ONE user and always for the
    same device. The solution, was to use ACL`s, which overwrite filesystem settings.

    This is what I did:

    --------------------
    Create a new folder with the username of your user, let us say his username is "miller" wu´ith
    group "miler"

    If exists, delete /media/miller

    rmdir /media/miller

    Then create a new one:

    mkdir /media/miller

    ---------------------

    Now check ACL settings, should look like these:

    getfacl /media/miller/
    getfacl: Removing leading '/' from absolute path names
    # file: media/miller/
    # owner: root
    # group: root
    user::rwx
    group::r-x
    other::r-x
    --------------------

    Now we have to set the correct rights for the user "miller"

    user rights:
    setfacl -m u:miller:rwx /media/miller

    --------------------

    group rights:

    setfacl -m g:miller:--- /media/miller
    --------------------

    Rest of world:

    setfacl -m o::--- /media/miller
    --------------------

    At last set mask:

    setfacl -k --mask /media/miller
    --------------------

    If everything is correct, it should look like this:

    getfacl /media/miller/
    getfacl: Removing leading '/' from absolute path names
    # file: media/miller/
    # owner: root
    # group: root
    user::rwx
    user:miller:rwx
    group::---
    mask::rwx
    other::---

    -------------------

    I hope this helps a litte bit.

    If I described something wrong, please feel free, to correct it! I made this from my
    remembering and my environment is German.

    Best

    Hans




    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    </head>
    <body><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Am Samstag, 3. Mai 2025, 12:22:45 CEST schrieb Haines Brown:</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; I want to enable a user to copy files to a USB key mounted on a directory</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; under /media.</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; </p> <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; I can change the ownership of that directory to that of the user, but</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; when I mount the the key on it the ownsrhip reverts to root. As the</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; result a user cannot copy files to the key. I would enable the user to</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; copy files to the key and preserve their ownership.</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; </p> <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; This must be a common problem, but I have not found a solution on</p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">&gt; line or in man mount.</p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">We need some informations of the environment:</p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">1. Which filesystem do you want to mount? FAT, FAT32, VFAT and exfat should work without any changes. Do they?</p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">2. Do you want to mount different devices or always the same?</p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">3. Do you want to allow it only one special user, several or all users?</p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">I had a similar problem in the future. But I only need to allow it ONE user and always for the same device. The solution, was to use ACL`s, which overwrite filesystem settings.</

    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">This is what I did:</p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;"><span style="font-family:Noto Sans;">-------------------- </span></span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">Create a new folder with the username of your user, let us say his username is &quot;miller&quot; wu´ith group &
    quot;miler&quot;</span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">If exists, delete /media/miller</span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">rmdir /media/miller</span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">Then create a new one:</span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">mkdir /media/miller</span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">---------------------</span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">Now check ACL settings, should look like these:</span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">getfacl /media/miller/ </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">getfacl: </span></span><span style="font-family:monospace;"><span style="color:#000000;"><span style="background-
    color:#ffffff;">Removing leading '/' from absolute path names</span></span></span><span style="color:#31363b;"><span style="background-color:#fafafa;"><span style="font-family:Noto Sans;"> </span></span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;"># file: media/miller/ </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;"># owner: root </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;"># group: root </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">user::rwx  </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">group::r-x  </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">other::r-x </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">-------------------- </span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">Now we have to set the correct rights for the user &quot;miller&quot;</span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">user rights: </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">setfacl -m u:miller:rwx /media/miller</span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">&nbsp;</span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">-------------------- </span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">group rights: </span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">setfacl -m g:miller:--- /media/miller </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">-------------------- </span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">Rest of world: </span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">setfacl -m o::--- /media/miller </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">-------------------- </span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">At last set mask: </span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">setfacl -k --mask /media/miller </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">-------------------- </span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">If everything is correct, it should look like this:</span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">&nbsp;</span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">getfacl /media/miller/ </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">getfacl: </span></span><span style="color:#000000;"><span style="background-color:#ffffff;"><span style="font-
    family:monospace;">Removing leading '/' from absolute path names</span></span></span><br /><span style="color:#31363b;"><span style="background-color:#fafafa;"><span style="font-family:Noto Sans;"># file: media/miller/ </span></span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;"># owner: root </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;"># group: root </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">user::rwx </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">user:miller:rwx </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">group::--- </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">mask::rwx </span></span></p>
    <p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;"><span style="color:#31363b;"><span style="background-color:#fafafa;">other::---</span></span></p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">-------------------</p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">I hope this helps a litte bit. </p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">If I described something wrong, please feel free, to correct it! I made this from my remembering and my environment is German.</p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Best</p>
    <br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Hans</p>
    <br /><br /><br /></body>
    </html>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Wright@21:1/5 to Haines Brown on Sun May 4 06:30:01 2025
    On Sat 03 May 2025 at 06:22:45 (-0400), Haines Brown wrote:
    I want to enable a user to copy files to a USB key mounted on a directory under /media.

    I can change the ownership of that directory to that of the user, but
    when I mount the the key on it the ownsrhip reverts to root.

    There are several answers posted, but after you have finished and
    unmounted all the filesystems in /media, remember to revert the permissions/ownership of /media to drwxr-xr-x root root
    and leave it like that.

    Cheers,
    David.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)