Linux newgrp command
On Unix-like operating systems, the newgrp command configures the group membership for a user to log in.
This page covers the GNU/Linux version of newgrp.
Description
The newgrp command is used to change the current GID (group ID) during a login session. If a hyphen ("-") is included as an argument, the user's environment is initialized as though he or she had logged in; otherwise, the current working environment remains unchanged. newgrp changes the current real group ID to the specified group, or, if no group is specified, to the default group listed in the file /etc/passwd. newgrp also tries to add the group to the user groupset.
If the user is root, he or she is not prompted for a password.
If the user is not root, he or she is prompted for a group password if:
- the user does not have a password, but the group does, or if
- the user is not listed as a group member, and the group has a password.
If there is no group password set, and the user is not listed as a member of the group, the user is denied access.
If there is an entry for the group in the shadowed group password file, /etc/gshadow, the list of members and the password for this group is taken from this file. Otherwise, the group entry in /etc/group is used.
Syntax
newgrp [-] [group]
Files
newgrp makes use of the following files:
/etc/passwd | User account information. |
/etc/shadow | Secure user account information. |
/etc/group | Group account information. |
/etc/gshadow | Secure group account information. |
Examples
newgrp developers
Attempts to log in to the group developers.
newgrp - developers
Attempts to log in to the group developers, and, if successful, re-initializes the user environment.
Related commands
gpasswd — Administer /etc/group and /etc/gshadow.
ksh — The Korn shell command interpreter.
login — Begin a session on a system.
set — Set the value of shell options and positional parameters.
sh — The Bourne shell command interpreter.