1832871 Members
2667 Online
110048 Solutions
New Discussion

Re: change group id

 
SOLVED
Go to solution
A.G.M. Velthof
Valued Contributor

change group id

Hello to All,

I have to change a group id because of a nfs link, and I was testing some things.
The files belonging to the group change to the new group id, so that works fine.
There is something, I think strange, hapening with the tar files.
I make a tar with files belonging to group id, say 102. I change the group id to 120. After that the files in the tar also have group id 120.
Can someone explain this?

Regards, Alfons
7 REPLIES 7
Simon Hargrave
Honored Contributor

Re: change group id

You are saying that if you chgrp a tar file to a different group id then this cascades to all the files contained WITHIN the tar file? This is not right.

I suspect that you are extracting the tar file whilst logged in as a user with GID 120, and since the user is not a "root" user it can only create files owned by itself.

To see the true GID of files in a tar file, preview it with: -

tar tvf file.tar

This will show you the real UID/GID's of the files. However ONLY root can extract the files correctly with the UID/GID of the files within.

You mention also NFS - remember that by default when root mounts filesystems over NFS, it actually has the permissions of the user "nobody" and NOT root, therefore has no special privileges.

If you require to do this over NFS you must export the filesystem with the norootsquash option, such that root is really root when mounted remotely.

Be VERY careful with this though as it can be dangerously insecure. When you export like this make sure you limit it to specific hosts and not *, otherwise anyone can get root access to your files quite easily.
Micky_1
Advisor

Re: change group id

Hi Alfons

tar seems to archive the names of users and groups....but if you do a tar -tvf .. , it converts from names back to ids....
But stop!
That can't be. Because if you extract a tar from a foreign system and you do not have all the accounts on your system, the files will belong to UID/GID instead of names.
So I think, that tar archives the names as well as the IDs and tries to convert it, if there is a chance for it....

Micky
A.G.M. Velthof
Valued Contributor

Re: change group id

Hello Simon,

I am logged in as root, and created the file as root. So the file is owned by root:sys
The files inside the tar however are assigned to group id 102.
After changing the group id 102 into 120 al the files inside the tar get group id 120.

By the way, I am not using nfs as root user.

Reagards, Alfons
Simon Hargrave
Honored Contributor

Re: change group id

I'm struggling to understand exactly what is happening, and what you are doing. Perhaps if you attached a transcript of what you are doing, including the commands you run (tar, chgrp etc) as well as output from tar tvf etc, then we can see exactly what your symptoms are.
A.G.M. Velthof
Valued Contributor

Re: change group id

in the directory /data I have 20 files:
-rw-r----- 1 moq mtusers 1053 1.dat
-rw-r----- 1 moq mtusers 1053 2.dat
etc.

The user id of moq is 204.
The group id of mtusers is 102.

I create the tarfile as user root:
tar cvf all.tar *dat.

After that I look in the tar file:
tar tvf all.tar
and see the following:
rw-r----- 204/102 1053 1.dat
rw-r----- 204/102 1053 2.dat
etc.

With sam I change the goup id of mtusers to 120.

When i look in the tar file with
tar tvf all.tar, I see:
rw-r----- 204/120 1053 1.dat
rw-r----- 204/120 1053 2.dat
etc.

So the group id in the tar file is changed as well.

Regards, Alfons
Simon Hargrave
Honored Contributor
Solution

Re: change group id

OK, now I see.

In the POSIX format of a tar archive (the default in HPUX now), the user and group are actually stored as a string, not a numberic. You can see this if you execute: -

strings file.tar | more

You will see the word "mtusers" embedded within the file.

Therefore when you perform tar tvf, the command is reverse looking mtusers and discovering the new GID.

If you want pre-POSIX format, then you can use the O option with tar.

See the difference: -

tar cvf file1.tar *.dat
tar cvOf file2.dat *.dat

Run them both through "strings" and see the difference.

See the man page for tar for the options N and O for more details.
A.G.M. Velthof
Valued Contributor

Re: change group id

Ok Simon, thanks.