Is there any way to archive a folder and keep the owners and permissions intact? I'm doing a backup of some files, which I want to move using a usb-stick, which has a FAT filesystem. So the idea was to keep all this information and file setting within an archive.

I know that the -p option for tar keeps the permissions, but still not the ownership.

  • 4
    tar should do this by default. If you extract as superuser (required to be able to set file ownership at all), it will set the owners to data stored in the archive unless you tell it not to. – Tom Hunt Sep 1 '15 at 22:16
  • By a little bit more thinking I could have come to this … Thank you very much. I guess this is actually the answer, do you want to post it as such? – white_gecko Sep 2 '15 at 9:47

tar's default mode is to preserve ownership and permissions on archive creation; I don't believe there's even an option not to store the data. When you extract an archive, if you're a normal user, the default is to use stored permissions minus the umask and set the owner to whoever's extracting; if you're superuser, the default is to use stored permissions and ownership verbatim. There are options to control how these metadata are restored on extraction (see the man page).


Whether a file can be assigned a different user id (e.g. while extracting a tararchive) does not depend on whether you are superuser but on whether you have the permission to do so. There are several possible reasons why you may have this permission:

1) you are on HP-UX where this is generally permitted. This is seen to be a security risk.

2) you have the fine grained permission to change the owner of local files and you are working on a local filesystem. See e.g. man privileges and the typical fine grained permission PRIV_FILE_CHOWN and PRIV_FILE_CHOWN_SELF

3) The directory where the files are extracted has an inheritable ACL write_owner set.

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.