sudo tar changes extracted files ownership to unknown user
Solution 1
When extracting files as root, tar will use the original ownership. You can override that using the --no-same-owner
option (alternatively, -o
).
Your tar file referred to user/group which do not exist on the system where you extracted it.
If you extract files as yourself (a non-privileged user), you can only create files owned by yourself.
The GNU tar manual says:
--same-owner
When extracting an archive, tar will attempt to preserve the owner specified in the tar archive with this option present. This is the default behavior for the superuser; this option has an effect only for ordinary users. See section Handling File Attributes.
Solution 2
The person who created the tar file had an effective user ID and group ID (UID:GID) of 1001:1001. Since tar
, by default, preserves the ownerships and permissions, when you expand it, you inherit these values. If you have a user with UID:GID 1001:1001 on your system, these files would have been owned by that user.
Related videos on Youtube
raspacorp
Updated on September 18, 2022Comments
-
raspacorp over 1 year
I am running this command:
$ sudo tar xvzf nexus-latest-bundle.tar.gz
The extracted files belong to an unknown (1001) user:
drwxr-xr-x 8 1001 1001 4096 Dec 16 18:37 nexus-2.12.0-01 drwxr-xr-x 3 1001 1001 4096 Dec 16 18:47 sonatype-work
Shouldn't it be root the owner under a normal configuration?
I am working on a linux installation replicated from an AWS AMI.
-
raspacorp over 8 yearsOk so this happens only when being root, because if I run the command without sudo: 'tar xzvf nexus-latest-bundle.tar.gz' then the ownership is set to my current user, is that an expected behavior?
-
Nate Eldredge over 8 years@raspacorp: As a non-root user, you don't have the authority to create files with any ownership other than your own. So by necessity, the files get created with you as the owner.