Tar encodes my user name into the tarball. Can I force it to make a fully anonymous tarball?

--owner root replaces only some instances of my user name. Adding USER=root: USER=root tar c --owner root data has no effect.

In short, I wish for:

echo hello world > data; tar c --owner root data | grep "$USER"

to not match.


What I was missing was --group=root in addition to --owner=root.

tar -c --{owner,group}=root

(possibly with an optional --numeric-owner) fully anonymizes the archive.

  • 7
    bash brace expansion {a,b} can be quite confusing. --{owner,group}=root will be expanded to --owner=root --group=root – Sanya_Zol Apr 21 '16 at 16:09

You can use --numeric-owner, that will just put your UID (1000 or something similar on most systems) in the file. From man tar:

       always use numbers for user/group names
  • Thanks. It does the job, though only partly. Looks like cpio (which seems to always encode uids numerically) can anonymize its archives fully via the --owner switch. – PSkocik Apr 21 '16 at 7:38
  • 1
    IIRC --owner only works on extraction/pass-through. If I am wrong you can use cpio's -H option to directly write tar files. – Anthon Apr 21 '16 at 7:44
  • It appears to work for -o too. I tried creating a simple archive with and without --owner root:root and then diffed their respective hexdumps. What changed were two two-byte sequence that little-endian-decoded to 0 and my $UID respectively. – PSkocik Apr 21 '16 at 7:51
  • 1
    @PSkocik That is interesting, I just checked man cpio and cpio --help and they both confirm what I commented before. Probably the source was updated, but the documentation wasn't (GNU cpio 2.11) – Anthon Apr 21 '16 at 9:24

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.