17

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.

2 Answers 2

19

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.

3
  • 9
    bash brace expansion {a,b} can be quite confusing. --{owner,group}=root will be expanded to --owner=root --group=root Commented Apr 21, 2016 at 16:09
  • 2
    On macOS the command line options are --uid 0 and --gid 0. Commented Mar 9, 2023 at 14:41
  • 1
    @Utkonos Thanks Commented Mar 9, 2023 at 15:34
13

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

 --numeric-owner
       always use numbers for user/group names
4
  • 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. Commented Apr 21, 2016 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. Commented Apr 21, 2016 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. Commented Apr 21, 2016 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) Commented Apr 21, 2016 at 9:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.