tar without preserving user

Generally .tar.gz is a usable file distribution format. GNU tar allows you to replace owner, group and permissions with other values when adding files to the archive.

$ tar -c -f archive.tar --owner=0 --group=0 .

https://www.gnu.org/software/tar/manual/html_section/tar_33.html#SEC69

If your version of tar does not support the GNU options you can copy your source files to another directory tree and update group and ownership there, prior to creating your tar.gz file for distribution.


With GNU you can use --numeric-owner to prevent tar from storing your username. Alternatively, you can set another userid with --owner=ID. When it's extracted, those user ids will be dropped, unless the extractor is the root user.

A common way used to bundle files is cpio which is typically used with the --no-preserve-owner option. This is how rpm files are built.

But tar with user-ids is rarely an issue. If you want to be paranoid, you use a dedicated account for the final bundling.


You're looking for something like tar --owner=0 --group=0 to set everything owned by root/root.

Tags:

Tar

Users