We help IT Professionals succeed at work.

User and group on files un-tarred

Anony Mous
Anony Mous asked
on
All,

I ssh'd into a server as myself and created a directory called "misc" (for example) in /usr/local/share like this:

sudo mkdir /usr/local/share/misc

Then i cd'd to the /usr/local/share/misc, then i copied a tar file from another directory to the /usr/local/share/misc directory i created.

I then ran sudo tar -xvf mytarfile.tar because the permissions on the tar file were root::root, which extracted all the files in the /usr/local/share/misc.

My question is this, why when i un-tarred the files using sudo, in the directory i created with sudo, was the ownership of every file set to user as "jsmith" (just an example of another user on the system) , and the group was set to "users"?

Why weren't all the files set to root::root or myuserid:myuserid? We are both in sudoers with the same privileges.

Thanks, this one is stumping me.
Comment
Watch Question

Most Valuable Expert 2013
Top Expert 2013
Commented:
The ownership of the tar archive itself might well be "root:root",
but the ownerships of the files inside the tarball are certainly "jsmith:users".
That's because tar would archive ownerships and permissions along with the files themselves.

You can check this with

sudo tar -tvf myfile.tar

(-t means: table of contents).

You will see the ownerships of the archived files in the appropriate columns of the above command's output.

When extracting the archive with "root" privileges these original attributes will be restored.
Top Expert 2007
Commented:
What was the original ownership of the files? Mostly the sudo ran as root and restored files / folders with the original ownership.

Author

Commented:
Running a tar -tvf shows the original ownership as traveller/users. So why would the user "traveller" change to "jsmith" insted of root::root (since i untarred using sudo) or myuserid::myuserid for the same reason? And why would the group stay "users" instead of something else like root or myuserid?

I dont know why it picked the user "jsmith", who is another user on the system as i am, (see original post) and why the group didnt change from "users" to something else. Know the answers to these two questions would help me understand privileges more. I know if could just chown it after wards, but i would still like to know the reasons.

Omarfarid- remember jsmith:users wasnt the original ownership as shown above.
Most Valuable Expert 2013
Top Expert 2013
Commented:
I assume that the tarball came from another machine and that the numeric userid of "traveller" on that machine
is the same as the numeric userid of "jsmith" on the target machine (the one you're extracting the files on).

Run "id jsmith" on your machine and "id traveller" on the originating machine and compare the numeric IDs ("uid=..." in the output of "id").

The same applies to group IDs, of course ("gid=..." in the output of "id").

And again - if you have root privileges when extracting the files then the original numeric IDs found in the archive will be restored and associated with the user/group names corresponding to these IDs on the target system!
Extracting the files as non-root will behave differently - the extracted files will get your user and group IDs (if file permissions allow it, that is!)

By the way, tar has an option "--numeric-owner" which can be used along with "-t" to show numeric IDs instead of names and with "-c" to inhibit archiving the original user/group names along with the IDs.
Top Expert 2007

Commented:
Can you till how the tar file was created and is it from the same system / machine? As woolmilkporc said, if it it is taken from some other system, then the user id / group id could be different on that system.
Top Expert 2015

Commented:
rsync matches users by name, most other tools by numeric UID
So you need the original passwd/group files and chown accordignly (find . -nouser -o - nogoroup)

Author

Commented:
Thanks all for the responses. I am reviewing them now
Most Valuable Expert 2013
Top Expert 2013

Commented:
Why grade C? What's wrong with our answers?