This brief tutorial shows students and new users how to use the newgrp command on Ubuntu to configure a group membership with which users can log in.
The newgrp command changes the current group ID during a login session.
Using the newgrp command on Ubuntu Linux is important for users who want to manage group membership on their Linux systems. The newgrp command allows users to change to a new group ID while logged into their current working directory.
This is useful when a user needs to access files or directories only accessible to members of a specific group.
Using the newgrp command, users can temporarily become members of that group and access the necessary files or directories.
About newgrp command:
The newgrp command lets you change to a new group ID (GID) while logged into your current working directory, but access permissions are calculated according to the new real and effective group IDs.
Syntax:
The syntax is the rule and format of how the newgrp command can be used. These syntax options can be reordered, but a straight format must be followed.,.
Below is an example syntax of how to use the newgrp command.
newgrp [-] [group]
Options:
The command line options are switches or flags that determine how the commands are executed or controlled. They modify the behavior of the commands. They are separated by spaces and followed after the commands.
Below are some options for the newgrp command:
[group] | Replace [group] Replace the group with the group name you want to assume and login with. |
– | If a hyphen [ – ] is used in the command, the user’s current working environment will change, otherwise, the current working environment remains unchanged. |
–help | Display a help message and exit. |
Examples:
Below are some examples of how to run and use the newgrp on Ubuntu Linux.
Simply run the newgrp to invoke it.
If you want to use the newgrp command login to the developer’s group, you simply run the commands below:
Example:
newgrp developers
When you run the above command and are not a member of the developer’s group and not a root, you’ll be prompted for a group password if your account doesn’t have a password assigned.
If you’re listed as a group member, and the group has a password assigned, then you won’t be prompted.
If no group password is set and the user is not listed as a group member, the user will be denied access.
If you’re root, then no prompt is presented.
If you want to use the newgrp command to log in to the group developers and, if successful, re-initialize the user environment.
Example:
newgrp - developers
To test it out, create a new group, add your account, and enable the group password.
sudo groupadd developers sudo usermod -a -G developers richard sudo gpasswd developers
After that, test the newgrp command
That’s it!
Congratulations! You have learned how to use the newgrp command on Ubuntu.
Leave a Reply Cancel reply