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



Reply via email to