newgrp Command with Examples in Linux


This tutorial explains Linux “newgrp” command, options and its usage with examples.

newgrp – log in to a new group

Description :

The newgrp command is used to change the current group ID (GID) during a login session. If a hyphen (“-“) is included as an argument, then the user’s environment is initialized as though he or she had just 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 will not be prompted for a password.

If the user is not root, he or she will be 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 will be denied access.


If there is an entry for the group in the shadowed group password file, /etc/gshadow, then the list of members and the password for this group will be taken from this file. Otherwise, the group entry in /etc/group is used.

Usage :

newgrp [-] [group]

Examples :

1. Basic Example

$ newgrp abc

Attempts to log in to the group abc.

2. Use of hyphen

$ newgrp - abc

Attempts to log in to the group abc, and, if successful, re-initializes the user environment.


3. To change the real group ID back to your original login group, enter:

$ newgrp

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.