I want to build a tar file as regular (non-root) user with some prepared binaries and configuration files like this;


that are mean to be extracted into the file system under the / directory.

Like a traditional software package .deb, .rpm etc but I need to be "package manager independent". So probably I will just have a .tar file (maybe some gzip, bzip, lzip should be added to the mix but that's outside).


My problem here is that I don't want to build this tar as the root user, and I want to know if there is a way to build this tar as a regular (non-root) user and then, when the .tar file is distributed to the machines and the real root user extract those binaries, they will be installed as files owned by the root user or the user who extract the binaries ?


Because right now, when I just create the .tar file as a regular (non-root) user with

$ tar cf dist.tar dist/

And then extract the .tar as root user with

# tar xf dist.tar -C /

I see the binaries and the config file with the regular user as owner, not the root user.

$ ls -la /usr/bin/binary1
-rwxr-xr-x 1 user user 30232 jun  20 19:06 /usr/bin/binary1

And I wan to have

$ ls -la /usr/bin/binary1
-rwxr-xr-x 1 root root 30232 jun  20 19:06 /usr/bin/binary1

Just to clarify, this hand made packaging is very specific for some task in a closed infrastructure, so right now, using .deb, .rpm or any other more sophisticated packaging system is not an option.

1 Answer 1


The extraction is what determines the ownership, not the creation of the archive. You can see that by looking at the archive's table of contents, e.,g.,

tar tvf dist.tar

If creating the file as regular user

tar --owner 0 --group 0 dist.tar dist

do the magic

  • Thank you for your quick answer @Thomas Dickey, but when I do that the files are listed with the information of the regular (non-root) user, and I want to have the root user as owner, even if do the extract process (as root) with # tar xvf dist.tar the ownership of the regular user is preserved Commented Jun 22, 2017 at 0:14
  • tar shows the ownership of the files that you archived - your question didn't say that you created them as yourself. If you happen to use GNU tar, you could use the --owner and --group options to pretend that was not the case. Commented Jun 22, 2017 at 0:16
  • Ok, clarified. the --owner and --group did the trick thank you Commented Jun 22, 2017 at 0:21
  • 1
    Yes, and it is a "try" thing (if the UID/GID doesn't exist, etc) and per the man page it is the default action when the root user is extracting... see the --same-owner option
    – ivanivan
    Commented Jun 22, 2017 at 0:27
  • Yes, you could add the owners when extracting as root, which is probably good practice anyway. But for distribution, you should really consider creating the archive with root ownerships. See billauer.co.il/blog/2020/11/tar-create-owner-group
    – Fictional
    Commented Oct 30, 2022 at 18:00

You must log in to answer this question.

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