When I "tar" up an archive the files have an owner bob, when I extract that to another machine bob is there also but user number is different. So when I extract bob is no longer the owner of the files but someone else. Is there a good way to account for this ? User ID on one box being different to the next box ? I was expecting to untar and bob still be the owner . Thanks, Jerry
either assign the same UID/GIDs on both boxes to the same user, or do a chown -R after you untar-ed it. (also, it helps to have users use the same 'moniker' cross platforms.) On 3/3/21 7:53 AM, Jerry Geis wrote:> When I "tar" up an archive the files have an owner bob, > when I extract that to another machine bob is there also but user number is > different. > So when I extract bob is no longer the owner of the files but someone else. > > Is there a good way to account for this ? > User ID on one box being different to the next box ? > > I was expecting to untar and bob still be the owner . > > Thanks, > > Jerry > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centos
On 3/3/21 8:53 AM, Jerry Geis wrote:> When I "tar" up an archive the files have an owner bob, > when I extract that to another machine bob is there also but user number is > different.If you pack and extract as root, then numeric UID will be the same. But on different systems there may be different usernames that have that numeric UID. Incidentally: sometimes we enable SGID bit on a directory (to have everything that is created in it inherit the group that directory belongs to). tar will be one of the tools that will break it: extracted archive will have group as it was in the archived original (numeric GID that is, if both archiving and un-archiving was performed by root). I hope, this helps. Valeri> So when I extract bob is no longer the owner of the files but someone else. > > Is there a good way to account for this ? > User ID on one box being different to the next box ? > > I was expecting to untar and bob still be the owner . > > Thanks, > > Jerry > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centos >-- ++++++++++++++++++++++++++++++++++++++++ Valeri Galtsev Sr System Administrator Department of Astronomy and Astrophysics Kavli Institute for Cosmological Physics University of Chicago Phone: 773-702-4247 ++++++++++++++++++++++++++++++++++++++++
Regular users don't have the ability to change file ownership (only group, assuming they're a member of the target group and own the file), so this is mainly a consideration if you're running tar as root. By default, if you're running as root, GNU tar assumes the --same-owner switch, which preserves the ownership in the archive. If the IDs are different, you can use --owner or --owner-map to translate the IDs. If you need to get even trickier, you can use --to-command and pass the stream to your own custom filter. On Wed, Mar 03, 2021 at 09:53:42AM -0500, Jerry Geis wrote:> When I "tar" up an archive the files have an owner bob, > when I extract that to another machine bob is there also but user number is > different. > So when I extract bob is no longer the owner of the files but someone else. > > Is there a good way to account for this ? > User ID on one box being different to the next box ? > > I was expecting to untar and bob still be the owner . > > Thanks, > > Jerry > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centos-- -- Skylar Thompson (skylar2 at u.washington.edu) -- Genome Sciences Department (UW Medicine), System Administrator -- Foege Building S046, (206)-685-7354 -- Pronouns: He/Him/His
On Wed, 3 Mar 2021 at 09:54, Jerry Geis <jerry.geis at gmail.com> wrote:> When I "tar" up an archive the files have an owner bob, > when I extract that to another machine bob is there also but user number is > different. > So when I extract bob is no longer the owner of the files but someone else. > > Is there a good way to account for this ? > User ID on one box being different to the next box ? > > I was expecting to untar and bob still be the owner . > >The system has no way of knowing that bob:uid1 and bob:uid2 are the same person and in fact on a lot of systems they are not (aka if you downloaded a tar ball from my box and it had the user bob on it.. it definitely is not your bob). The ways to do this are any of the following or a list of ones not there. 1. find ./tree_you_untarred -uid <bob1_uid> -print0 | xargs -0 chown bob2 2. su bob2 (cd /tree_place_to_untar; tar xzvf <file you wanted to untar>) 3. use gnu tar's many options to create the tar file with the correct uid/gid you wanted using --owner --group (or a map if there are multiple).> Thanks, > > Jerry > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centos >-- Stephen J Smoogen.
On 3/3/21 6:53 AM, Jerry Geis wrote:> When I "tar" up an archive the files have an owner bob, > when I extract that to another machine bob is there also but user number is > different. > So when I extract bob is no longer the owner of the files but someone else. > > Is there a good way to account for this ?In order to answer that question, we need to know what system is creating the tar file and what system is extracting the file. There are several formats for tar archives (see the --format option to GNU tar for a list), and tar will have different options on different platforms. This process works the way you expect, by default, on CentOS systems. I can demonstrate that by creating a CentOS container, adding a user and creating a tar archive with a file owned by that user.? A new container, with users that have different numeric IDs will extract that archive and preserve the file's ownership by name and not numeric IDs: $ podman run -v $(pwd):$(pwd):z -w $(pwd) -it centos:8 [root at 9d60934a7390 tartest]# useradd user1 [root at 9d60934a7390 tartest]# touch user1file [root at 9d60934a7390 tartest]# chown user1 user1file [root at 9d60934a7390 tartest]# tar cf user1.tar user1file [root at 9d60934a7390 tartest]# exit $ podman run -v $(pwd):$(pwd):z -w $(pwd) -it centos:8 [root at 49a5818ef7a6 tartest]# useradd user2 [root at 49a5818ef7a6 tartest]# useradd user1 [root at 49a5818ef7a6 tartest]# rm user1file rm: remove regular empty file 'user1file'? y [root at 49a5818ef7a6 tartest]# tar xf user1.tar [root at 49a5818ef7a6 tartest]# ls -l total 12 -rw-r--r--. 1 root? root 10240 Mar? 3 19:21 user1.tar -rw-r--r--. 1 user1 root???? 0 Mar? 3 19:21 user1file