3

I'm using a Centos 8 Linux with multiple user belonging to the same group accessing a number ff folder/subfolder and files in the same FS (xfs). I want all files and folders have write permission for the group setting umask to 0002 allow new file created from user to have the right permission, but I have tar and other compressed files being extracted by users the extracted files maintain the permission they had in origin and are not changing resulting with some files being with permission only for the owner and not the group I'm trying to find a way to set the permission automatically without need of user to run a chmod to allow write for group I tried assign g+s on themain folder but I can only get the new folder inherit the group permission not the single files. I tried enabling ACL but again I don't get files to inherit parent folder permission. This how it look my main folder

drwxrwsr-x+ 4 owner group 4.0K Mar 6 10:26 test

And the content after extracting a tgz file in it

drwxrwsr-x+ 8 owner group 202 Mar 6 09:56 folder1 
drwxrwsr-x+ 8 owner group 202 Mar 6 10:12 folder2

but then when i reach the first folder with files, files permission are just for owner

ll test/folder1
-rwx------. 1 owner group 195K Jun 6 2018 file1
-rwx------. 1 owner group 225K Aug 4 2018 file2
-rwx------. 1 owner group 211K Aug 20 2018 file3
-rwx------. 1 owner group 100K Sep 9 2018 file4
-rwx------. 1 owner group 200K Oct 24 2018 file5
-rwx------. 1 owner group 199K Nov 9 2018 file6

even after executing

setfacl -R -m d:o:rwx test

files are not changing their permission

Is there a way to force all files created or extracted from a compressed archive to inherit the permission from the main folder?

0

You could use the star implementation of tar and its -chmod option to set the permissions of files upon extraction:

star -x -o -f file.tar -find -chmod ug+rwX
| improve this answer | |
  • I tried that and make no difference, files are still extracted with original permission 600 ignoring the umask set for the user (0002) – Cris Mar 9 at 5:35
  • @Cris, you're right. It seems it works for directories but not for other types of files. I've changed the answer to use -chmod instead. – Stéphane Chazelas Mar 9 at 7:19
  • yes this works, similar to the solution i found piping the tar output to xargs. Still hoping to find a simpler solution for user but for now this will do – Cris Mar 9 at 7:49
0

I'm still looking for a better solution, but for now I created a a script that pipe tar output to chmod command

#!/bin/bash -
set -o pipefail
tar xvf "$@" | xargs -rd '\n' chmod 770 --

I don't like it so much because instruct 100 and more user to use a different command will be tricky but if won't find better solution I'll keep this. just for info from man page tar seems to have an option which should ignore the file permission

--no-same-permissions

but seems working only if umask permission are more restrictive than the one on the extracted files, wonder if it's a bug

| improve this answer | |
  • Also not that it gives execute permissions to non-directory files. – Stéphane Chazelas Mar 9 at 9:40
  • It's also a bit dangerous in that chmod follows symlinks. So if a user is tricked into unpacking an archive that contains a symlink to ~/.profile for instance, that would have bad consequences. – Stéphane Chazelas Mar 9 at 9:41
  • I've added the (GNU-specific) -d '\n' so it doesn't fail with archive members that contain whitespace or quoting characters, but newline characters are still a problem. – Stéphane Chazelas Mar 9 at 9:42
  • Nice one. In our case the tar we have to extract are safe on that point of view but it is a valid point and nice update. Just as info I tried both tar with xargs and star the first seems more performant – Cris Mar 9 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.