1752298 Members
4436 Online
108786 Solutions
New Discussion юеВ

changing group

 
Md.Shahabuddin
Advisor

changing group


How to change user group temporarily without making changes in /etc/groups file?

8 REPLIES 8
Dennis Handly
Acclaimed Contributor

Re: changing group

A privileged user can use setgid(2) and see privgrp(4). Also see newgrp(1).

If you are in multiple groups, you don't need to change /etc/groups.

What does id(1) show for your user?
Sunny Jaisinghani
Trusted Contributor

Re: changing group

User's group can be changed by usermod command. See man usermod for more info.


running usermod command will update the group file.

if you want to get access to a directory belonging to some other group then changing the permissions of that directory or file can help instead of changing the user's group temporarily.

Regards
Anshumali
Esteemed Contributor

Re: changing group

newgrp Rest all please do a man newgrp

The newgrp command changes your group ID without changing your user ID
and replaces your current shell with a new one.

If you specify group, the change is successful if group exists and
either your user ID is a member of the new group, or group has a
password and you can supply it from the terminal.

If you omit group, newgroup changes to the group specified in your
entry in the password file, /etc/passwd.

Whether the group is changed successfully or not, or the new group is
the same as the old one or not, newgrp proceeds to replace your
current shell with the one specified in the shell field of your
password file entry. If that field is empty, newgrp uses the POSIX
shell, /usr/bin/sh
Dreams are not which you see while sleeping, Dreams are which doesnt allow you to sleep while you are chasing for them!!
Bill Hassell
Honored Contributor

Re: changing group

Do you need to change the primary group for a user or simply add that user to multiple groups? The newgrp command will change the primary group but it has annoying consequences, not the least of which is the start of a new shell. This means that it cannot be imbedded inside a script (the script stops when newgrp is run).

By simply adding the user's login to other groups, that user will have all the privileges for that group. Use the id command to see what groups are currently enabled for each user.


Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: changing group

>Bill: By simply adding the user's login to other groups

This isn't enough. You need to symlink logingroup to group.
Bill Hassell
Honored Contributor

Re: changing group

> Dennis - [sym]link to logingroup

I believe that requirement disappeared in 11.00. Around the same time I remember that the primary group membership would be determined from /etc/passwd and did not have to be replicated in /etc/group, so /etc/group user lists were only needed for multiple group memberships.


Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: changing group

>Bill: I believe that requirement disappeared in 11.00.

It looks like you are right.
Md.Shahabuddin
Advisor

Re: changing group

Thanks Folk !!!!!!!!!