There are mainly two types of groups – primary and secondary. As we create a user, it would simultaneously create a Primary group – which would have the same name as that of user. Apart from being a part of primary group, a user can also be a part of multiple secondary groups.
Certain resources in the system are restricted to users as per group permissions. And, a user may have to switch his/her group to either access or modify those resources. We can find the current effective group ID of user using id command-line utility. Open a terminal and issue the following –
We consider two scenarios next –
I. A user is already a part of secondary group and,
II. Use gpasswd to make user access secondary group if he/she isn’t a part of that group.
newgrp in Ubuntu
Case I. If a user is already a part of some secondary group and wishes to access/modify system resources from that secondary group then, use newgrp command-line utility –
Again, to check for current effective Group ID – we can use the above command –
It should reflect the changes.
Case II. If a user isn’t a part of secondary group then, in case the user tries to have access through a different group he/she isn’t a part of. Then, the terminal will prompt us for the group password. If you aren’t the System Administrator or don’t have the group password as well. Then, you can’t have access through the group.
Being a System Administrator, we need to set the group password first to let other users connect through it. So, issue the following in terminal –
sudo gpasswd <group_name>
And, then try to connect through newgrp command-line utility –
Enter the group’s password as provided by the System Administrator. To check for current effective group ID –
In conclusion, newgrp command-line utility is used to change the current effective group of a user.