This is my topology:
My laptop ==> Ubuntu Desktop
| | |
User: root & saeed
My server ==> Ubuntu 20.04
| | |
Users: root & ubuntu (I deleted it as I explain below)
The steps:
- I run
tar zvcf back.tar.gz .
in my laptop with usersaeed
and file is created. - I upload this file via SFTP to my server by using
root
user in path example/home/test
which is not any user's home dir. - I extract
back.tar.gz
in/home/test
but I see all of the files and directories' owner areubuntu:ubuntu
. - I deleted
ubuntu
user and tried the third step but got the same result. - I extracted
back.tar.gz
in my laptop in another path, but all files' owners aresaeed:saeed
.
Why does this happen?
Best Answer
When extracting as root,
tar
by default preserves the original owner ID. Usersaeed
happens to have the same ID asubuntu
on the other computer (and it's probably1000
). You can check IDs by runningid saeed
, or justid
to check the current user.If you don't want to preserve user ID, either don't extract as root or use the
--no-same-owner
option. Relevant fragment from the manual:The opposite can be achieved for regular users with
--same-owner
.Related options
--owner
and--owner-map
can be used when creating an archive: