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?

  • 1
    "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, 2012 at 9:10

2 Answers 2


If the user extracting is a "ordinary" user, the files will be owned by that user (by default).

From the manual page of tar

       try extracting files with the same ownership as exists in the archive (default for superuser)

       extract files as yourself (default for ordinary users)

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .