If I change permissions on a tar file, will that apply to the files inside it?
Solution 1
If the user extracting is a "ordinary" user, the files will be owned by that user (by default).
From the manual page of tar
--same-owner
try extracting files with the same ownership as exists in the archive (default for superuser)
--no-same-owner
extract files as yourself (default for ordinary users)
Solution 2
Short answer: No.
The tar
utility is made specially for archiving directory structures under unix-like systems. It preserves all the ownership and permission information of the files/directories included¹. Regardless of the user running the tar
command.
At least this is case of standard invocation. But I presume that if you were to exercise any advanced tar
options that might change permission handling, you wouldn't have asked this question :)
¹ One exception: regular tar
does not preserve SELinux settings or acls. You need star
or a recent version of tar
to preserve those.
See also http://magazine.redhat.com/2007/07/02/tips-from-an-rhce-tar-vs-star-the-battle-of-xattrs/.
You may need to take that into consideration if the files backed up have any extended attributes.
Related videos on Youtube
ADAM
Updated on September 18, 2022Comments
-
ADAM almost 2 years
I have a script that runs regularly via
cron
, that creates atar.gz
file for the purpose of backing up a directory.For reasons beyond my control, the only user who can execute the script via
cron
is a root user. So the resultingtar
file can not be moved or deleted by any other user.So, as part of the script, I want to execute a
chown
andchmod
on thetar
file so that other users can manipulate it.But is it good enough to just change permissions on the
tar
file, or will the root user permissions also be saved to the files inside thetar
? When a user unpacks thetar
file, will they be able to act on those files as if they created the files themselves?-
Admin almost 12 years"So the resulting tar file can not be moved or deleted by any other user." — not true. Un-linking is possible when a user has Write permission set for directory (unless it has setuid bit set as well like
/tmp
for e. g.)
-