System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Making user member of more than one group

 
SOLVED
Go to solution
panks
Regular Advisor

Making user member of more than one group

Hi,
I have X user member of group a. Now I want to modify it and make the user x member of group a and b. How can I do that.
Thanks
8 REPLIES
Solution

Re: Making user member of more than one group

Edit /etc/group and add X to group b.

Re: Making user member of more than one group

You can also use useradd(1m):
useradd -G b X
panks
Regular Advisor

Re: Making user member of more than one group

Thanks Dennis for reply. One more question on that
If I want to change the uid and gid of existing user and group, how can I achieve that.
As we have copied some data from old server and now running those data on this new hpux server. So the data is having the uid and gid of old server while in new server uid and gid is different than old server.

Re: Making user member of more than one group

>If I want to change the uid and gid of existing user and group, how can I achieve that.

You have a problem. If you really really want to do that, you'll need to find all of the files owned by that user and change to the new UID. Also the same for GID.

>So the data is having the uid and gid of old server while in new server uid and gid is different than old server.

It would have been better to reuse the same UID/GID. But if you have to change, you can use find(1) to find and change them:
find file-system ... -user old-uid -exec chown uid {} +
find file-system ... -group old-gid -exec chgrp gid {} +

(The above two searches are in case not all files have both old-uid old-gid.)
panks
Regular Advisor

Re: Making user member of more than one group

No I doesn't mean that.
Now the user is having uid 102 and group x as 200. So if I want to change the user uid to 109 and group to 201 then how can I achive?
Matti_Kurkela
Honored Contributor

Re: Making user member of more than one group

To change the UID of an existing user:

usermod -u

Example: "usermod -u 109 user"

To change the GID of an existing group:

groupmod -g

Example "groupmod -g 201 x"

If the user/group had created any files/directories on the system before the change, you must then run the find commands described by Dennis, otherwise the file ownerships won't be properly recognized. The files will be listed as belonging to an unnamed user/group (the "ll" command will display the old UID/GID numbers instead of user/group names) and the files and directories can be accessed only by root, unless the permissions are set to world-readable.

Example: when running something like "ll userfile", you will see:

-rw-r--r-- 1 102 200 ...
instead of:

-rw-r--r-- 1 user x ...

Dennis's find commands will fix this.

MK
MK

Re: Making user member of more than one group

>No I doesn't mean that.

Yes basically you did. Changing the IDs would require changing the files. Either you change the IDs on the old server as MK said, then use find(1) to fix them before moving to the new server. Or move them to the new server and use find to fix them there.

Basically UNIX keeps track of IDs and not names. Changing /etc/passwd & /etc/group mappings would require changing all of the files with those old IDs.

panks
Regular Advisor

Re: Making user member of more than one group

Thanks