9

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.

13

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.

  • 1
    Ok 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? – raspacorp Feb 19 '16 at 23:52
  • 2
    @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. – Nate Eldredge Feb 20 '16 at 4:21
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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