Force the owner and group for the contents of a tar file?












19















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




















  • 1





    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
















19















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




















  • 1





    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














19












19








19


8






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
















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?







permissions users tar






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 11 '13 at 23:45









Gilles

535k12810811598




535k12810811598










asked Jan 11 '13 at 23:29









DavidDavid

198116




198116








  • 1





    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














  • 1





    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








1




1





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





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










3 Answers
3






active

oldest

votes


















16














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






  • 1





    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











  • Actually with my tar version I can enter any username I'd like and have it stored in the tar file (but with my numeric user id by default). While listing you get the usernames by default but the user ids using the --numeric-owner flag. What's more interesting is that you can set both using --owner=name:1234 or --group=groupname:4711. Source: function parse_owner_group of the tar source code

    – Bluehorn
    Feb 2 '17 at 18:25



















0














Add the params --no-same-owner --no-same-permissions with tar. Take a look at the docs.






share|improve this answer



















  • 1





    Those options are only used when extracting files from a tar archive -- not creating one.

    – Anthony Geoghegan
    Jan 25 at 12:34













  • You are right @AnthonyGeoghegan!

    – Bruno Wego
    Jan 25 at 12:42



















-1














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



















  • 2





    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








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f61004%2fforce-the-owner-and-group-for-the-contents-of-a-tar-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









16














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






  • 1





    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











  • Actually with my tar version I can enter any username I'd like and have it stored in the tar file (but with my numeric user id by default). While listing you get the usernames by default but the user ids using the --numeric-owner flag. What's more interesting is that you can set both using --owner=name:1234 or --group=groupname:4711. Source: function parse_owner_group of the tar source code

    – Bluehorn
    Feb 2 '17 at 18:25
















16














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






  • 1





    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











  • Actually with my tar version I can enter any username I'd like and have it stored in the tar file (but with my numeric user id by default). While listing you get the usernames by default but the user ids using the --numeric-owner flag. What's more interesting is that you can set both using --owner=name:1234 or --group=groupname:4711. Source: function parse_owner_group of the tar source code

    – Bluehorn
    Feb 2 '17 at 18:25














16












16








16







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















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














share|improve this answer



share|improve this answer








edited Jan 12 '13 at 1:06

























answered Jan 12 '13 at 0:27









NykakinNykakin

2,8891114




2,8891114













  • 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






  • 1





    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











  • Actually with my tar version I can enter any username I'd like and have it stored in the tar file (but with my numeric user id by default). While listing you get the usernames by default but the user ids using the --numeric-owner flag. What's more interesting is that you can set both using --owner=name:1234 or --group=groupname:4711. Source: function parse_owner_group of the tar source code

    – Bluehorn
    Feb 2 '17 at 18:25



















  • 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






  • 1





    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











  • Actually with my tar version I can enter any username I'd like and have it stored in the tar file (but with my numeric user id by default). While listing you get the usernames by default but the user ids using the --numeric-owner flag. What's more interesting is that you can set both using --owner=name:1234 or --group=groupname:4711. Source: function parse_owner_group of the tar source code

    – Bluehorn
    Feb 2 '17 at 18:25

















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





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




1




1





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





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













Actually with my tar version I can enter any username I'd like and have it stored in the tar file (but with my numeric user id by default). While listing you get the usernames by default but the user ids using the --numeric-owner flag. What's more interesting is that you can set both using --owner=name:1234 or --group=groupname:4711. Source: function parse_owner_group of the tar source code

– Bluehorn
Feb 2 '17 at 18:25





Actually with my tar version I can enter any username I'd like and have it stored in the tar file (but with my numeric user id by default). While listing you get the usernames by default but the user ids using the --numeric-owner flag. What's more interesting is that you can set both using --owner=name:1234 or --group=groupname:4711. Source: function parse_owner_group of the tar source code

– Bluehorn
Feb 2 '17 at 18:25













0














Add the params --no-same-owner --no-same-permissions with tar. Take a look at the docs.






share|improve this answer



















  • 1





    Those options are only used when extracting files from a tar archive -- not creating one.

    – Anthony Geoghegan
    Jan 25 at 12:34













  • You are right @AnthonyGeoghegan!

    – Bruno Wego
    Jan 25 at 12:42
















0














Add the params --no-same-owner --no-same-permissions with tar. Take a look at the docs.






share|improve this answer



















  • 1





    Those options are only used when extracting files from a tar archive -- not creating one.

    – Anthony Geoghegan
    Jan 25 at 12:34













  • You are right @AnthonyGeoghegan!

    – Bruno Wego
    Jan 25 at 12:42














0












0








0







Add the params --no-same-owner --no-same-permissions with tar. Take a look at the docs.






share|improve this answer













Add the params --no-same-owner --no-same-permissions with tar. Take a look at the docs.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 25 at 11:56









Bruno WegoBruno Wego

1012




1012








  • 1





    Those options are only used when extracting files from a tar archive -- not creating one.

    – Anthony Geoghegan
    Jan 25 at 12:34













  • You are right @AnthonyGeoghegan!

    – Bruno Wego
    Jan 25 at 12:42














  • 1





    Those options are only used when extracting files from a tar archive -- not creating one.

    – Anthony Geoghegan
    Jan 25 at 12:34













  • You are right @AnthonyGeoghegan!

    – Bruno Wego
    Jan 25 at 12:42








1




1





Those options are only used when extracting files from a tar archive -- not creating one.

– Anthony Geoghegan
Jan 25 at 12:34







Those options are only used when extracting files from a tar archive -- not creating one.

– Anthony Geoghegan
Jan 25 at 12:34















You are right @AnthonyGeoghegan!

– Bruno Wego
Jan 25 at 12:42





You are right @AnthonyGeoghegan!

– Bruno Wego
Jan 25 at 12:42











-1














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



















  • 2





    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
















-1














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



















  • 2





    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














-1












-1








-1







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













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












share|improve this answer



share|improve this answer










answered Dec 16 '14 at 8:42









poussmapoussma

992




992








  • 2





    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














  • 2





    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








2




2





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





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


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f61004%2fforce-the-owner-and-group-for-the-contents-of-a-tar-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to make a Squid Proxy server?

第一次世界大戦

Touch on Surface Book