Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to create a tar file with contents belonging to an owner:group pair who do not exist on the system from which the file is being made.

Here's the direction I've tried:

tar ca --owner='otherowner' --group='othergroup' mydata.tgz mydata

And when running this command, I get the following error:

tar: otherowner: Invalid owner
tar: Error is not recoverable: exiting now

Is there a way to force tar to accept the owner:group, even though neither of them exist on the system from which the file is being created?

share|improve this question
Note that --owner is not an option supported by tar. This is a non-portable GNUism. With star, you e.g. use the built-in find and specify -chown username/userid -chgrp groupname/groupid. – schily Aug 27 '15 at 14:50
up vote 11 down vote accepted

Linux doesn't use internally owners and groups names but numbers - UIDs and GIDs. Users and groups names are mapped from contents of /etc/passwd and /etc/group files for convenience of user. Since you don't have 'otherowner' entry in any of those files, Linux doesn't actually know which UID and GID should be assigned to a file. Let's try to pass a number instead:

$ tar cf archive.tar test.c --owner=0 --group=0
$ tar -tvf archive.tar 
-rw-rw-r-- root/root        45 2013-01-10 15:06 test.c
$ tar cf archive.tar test.c --owner=543543 --group=543543
$ tar -tvf archive.tar 
-rw-rw-r-- 543543/543543    45 2013-01-10 15:06 test.c

It seems to work.

share|improve this answer
Interesting! So the tar command must be polling the system for the user and group numbers to match the names I was trying to use. Thanks! – David Jan 14 '13 at 15:10
A note for others coming across this: tar automatically outputs user/group names when using the -tvf flags. To view the current numbers for files in an archive use a command like this: $ tar --numeric-owner -tvf archive.tar – David Jan 14 '13 at 15:23

Here is a piece of code to replace the user/group with ids on the fly:

tar ca --owner="$(id -u ***otherowner***)" --group="$(id -g ***othergroup***)" mydata.tgz mydata
share|improve this answer
No. If id knows how to resolve the name, tar knows too. The question is about a user name unknown to the system. – Daniel S Aug 25 '15 at 11:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.