Force the owner and group for the contents of a tar file?
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
add a comment |
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
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
add a comment |
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
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
permissions users tar
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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.
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-tvfflags. 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-ownerflag. What's more interesting is that you can set both using--owner=name:1234or--group=groupname:4711. Source: function parse_owner_group of the tar source code
– Bluehorn
Feb 2 '17 at 18:25
add a comment |
Add the params --no-same-owner --no-same-permissions with tar. Take a look at the docs.
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
add a comment |
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
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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-tvfflags. 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-ownerflag. What's more interesting is that you can set both using--owner=name:1234or--group=groupname:4711. Source: function parse_owner_group of the tar source code
– Bluehorn
Feb 2 '17 at 18:25
add a comment |
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.
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-tvfflags. 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-ownerflag. What's more interesting is that you can set both using--owner=name:1234or--group=groupname:4711. Source: function parse_owner_group of the tar source code
– Bluehorn
Feb 2 '17 at 18:25
add a comment |
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.
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.
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-tvfflags. 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-ownerflag. What's more interesting is that you can set both using--owner=name:1234or--group=groupname:4711. Source: function parse_owner_group of the tar source code
– Bluehorn
Feb 2 '17 at 18:25
add a comment |
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-tvfflags. 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-ownerflag. What's more interesting is that you can set both using--owner=name:1234or--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
add a comment |
Add the params --no-same-owner --no-same-permissions with tar. Take a look at the docs.
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
add a comment |
Add the params --no-same-owner --no-same-permissions with tar. Take a look at the docs.
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
add a comment |
Add the params --no-same-owner --no-same-permissions with tar. Take a look at the docs.
Add the params --no-same-owner --no-same-permissions with tar. Take a look at the docs.
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
add a comment |
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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