Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a script that runs regularly via cron, that creates a tar.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 resulting tar file can not be moved or deleted by any other user.

So, as part of the script, I want to execute a chown and chmod on the tar 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 the tar? When a user unpacks the tar file, will they be able to act on those files as if they created the files themselves?

share|improve this question
    
"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.) –  poige Jul 29 '12 at 9:10

2 Answers 2

up vote 6 down vote accepted

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)
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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