User and group on files un-tarred


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.
Anony MousAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
What was the original ownership of the files? Mostly the sudo ran as root and restored files / folders with the original ownership.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anony MousAuthor 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.
Redefining Cyber Security w/ AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Join our webinar on Sept. 21st to learn more about leveraging AI and machine learning to protect your business.

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.
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.
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)
Anony MousAuthor Commented:
Thanks all for the responses. I am reviewing them now
Why grade C? What's wrong with our answers?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.