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.

Petr Skocik
  • 28,176
  • 14
  • 81
  • 141

2 Answers2

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.

Petr Skocik
  • 28,176
  • 14
  • 81
  • 141
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
Anthon
  • 78,313
  • 42
  • 165
  • 222
  • 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. – Petr Skocik Apr 21 '16 at 07: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 07: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. – Petr Skocik Apr 21 '16 at 07: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 09:24