NEWGRP(1POSIX)

πŸ’– NEWGRP β€” change to a new group πŸ’–

okay bestie, so before we even start: this page lives in the POSIX Programmer's Manual, and ngl the Linux version of this interface might do stuff differently (so like, go read the matching Linux manual page for the tea), or it might not even be implemented on Linux at all. πŸ™ˆ Just so we're clear from the jump.


✨ NAME ✨

newgrp β€” change to a new group. that's it, that's the whole vibe. πŸ‘‘


🌸 SYNOPSIS 🌸

newgrp [-l] [group]

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so newgrp creates a brand new shell execution environment with a new real and effective group identification. slay.

Now, out of all the attributes listed in Section 2.12, Shell Execution Environment, the new shell execution environment shall retain these three from the previous environment:

  • the working directory
  • the file creation mask
  • exported variables

and lowkey everything else might just ghost you β€” that means open files, traps, unexported variables, alias definitions, shell functions, and set options may be lost. πŸ’€

Everything else in the process environment that the exec family of functions preserves (as defined in the System Interfaces volume of POSIX.1‐2017) shall also be preserved by newgrp. Whether anything else survives is unspecified β€” so like, don't count on it, bestie.

✨ important: if assigning the new group identifications fails (say, for security or password-related reasons), that shall not stop the new shell execution environment from being created. the environment still happens. periodt.

how newgrp messes with your supplemental groups 🫢

The newgrp utility shall affect the supplemental groups for the process like this:

  • On systems where the effective group ID is normally in the supplementary group list (or whenever the old effective group ID actually is in the supplementary group list):
    • If the new effective group ID is also in the supplementary group list, newgrp shall change the effective group ID.
    • If the new effective group ID is not in the supplementary group list, newgrp shall add the new effective group ID to the list, if there is room to add it.
  • On systems where the effective group ID is not normally in the supplementary group list (or whenever the old effective group ID is not in the supplementary group list):
    • If the new effective group ID is in the supplementary group list, newgrp shall delete it.
    • If the old effective group ID is not in the supplementary list, newgrp shall add it if there is room.
Note: the System Interfaces volume of POSIX.1‐2017 does not specify whether the effective group ID of a process is included in its supplementary group list. so like… mystery. πŸ•΅οΈβ™€οΈ

With no operands, newgrp shall change the effective group back to the groups identified in the user's user entry, and shall set the list of supplementary groups to that set in the user's group database entries. it's giving "return to factory settings". 🌈

If the first argument is -, the results are unspecified. do not do that. πŸ™ˆ

password drama πŸ”

If a password is required for the specified group, and the user is not listed as a member of that group in the group database, the user shall be prompted to enter the correct password for that group. If the user is listed as a member of that group, no password shall be requested. iconic behavior honestly.

If no password is required for the specified group, it's implementation-defined whether users not listed as members of that group can change to that group. πŸ‘€

And whether or not a password is required, implementation-defined system accounting or security mechanisms may impose additional authorization restrictions that may cause newgrp to write a diagnostic message and suppress the changing of the group identification. so like, the system can just say no. 😭


πŸŽ€ OPTIONS πŸŽ€

The newgrp utility shall conform to the Base Definitions volume of POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines β€” except for the unspecified usage of -. (we don't talk about that.)

The following option shall be supported:

  • -l β€” (that's the letter ell, bestie, not a one.) Change the environment to what would be expected if the user actually logged in again. full main character re-entry. πŸ’…

🌟 OPERANDS 🌟

The following operand shall be supported:

  • group β€” A group name from the group database, or a non-negative numeric group ID. Specifies the group ID to which the real and effective group IDs shall be set. If group is a non-negative numeric string and exists in the group database as a group name (see getgrnam()), the numeric group ID associated with that group name shall be used as the group ID.

πŸ’œ STDIN πŸ’œ

Not used. it's not the moment.


πŸ“ INPUT FILES πŸ“

The file /dev/tty shall be used to read a single line of text for password checking, when one is required. that's the password girlie. 🌸


🌈 ENVIRONMENT VARIABLES 🌈

The following environment variables shall affect the execution of newgrp:

  • LANG β€” Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1‐2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
  • LC_ALL β€” If set to a non-empty string value, override the values of all the other internationalization variables. she overrides everything. πŸ’…
  • LC_CTYPE β€” Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments).
  • LC_MESSAGES β€” Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
  • NLSPATH β€” Determine the location of message catalogs for the processing of LC_MESSAGES.

⚑ ASYNCHRONOUS EVENTS ⚑

Default. no notes. ✨


πŸ¦„ STDOUT πŸ¦„

Not used. she's silent on the way out. 🀫


πŸ’… STDERR πŸ’…

The standard error shall be used for diagnostic messages and a prompt string for a password, if one is required. Diagnostic messages may be written in cases where the exit status is not available. See the EXIT STATUS section. πŸ‘‘


🧚 OUTPUT FILES 🧚

None. zero. nada. πŸŽ€


⭐ EXTENDED DESCRIPTION ⭐

None. nothing extra, bestie. πŸ’–


πŸ”₯ EXIT STATUS πŸ”₯

If newgrp succeeds in creating a new shell execution environment β€” whether or not the group identification was changed successfully β€” the exit status shall be the exit status of the shell.

Otherwise, the following exit value shall be returned:

  • >0 β€” An error occurred. 😭

πŸ’€ CONSEQUENCES OF ERRORS πŸ’€

The invoking shell may terminate. yeah. that's the whole sentence. be careful. πŸ™ˆ

The following sections are informative.


🌸 APPLICATION USAGE 🌸

There is no convenient way to enter a password into the group database. Use of group passwords is not encouraged, because by their very nature they encourage poor security practices. Group passwords may disappear in the future. so like… don't get attached. πŸ’”

A common implementation of newgrp is that the current shell uses exec to overlay itself with newgrp, which in turn overlays itself with a new shell after changing group. On some implementations, however, this may not occur and newgrp may be invoked as a subprocess. different systems, different lore. πŸ¦‹

The newgrp command is intended only for use from an interactive terminal. It does not offer a useful interface for the support of applications. so pls don't build your app on this. 🫢

The exit status of newgrp is generally inapplicable. If newgrp is used in a script, in most cases it successfully invokes a new shell and the rest of the original shell script is bypassed when the new shell exits. Used interactively, newgrp displays diagnostic messages to indicate problems. But usage such as:

newgrp foo
echo $?

is not useful because the new shell might not have access to any status newgrp may have generated (and most historical systems do not provide this status). A zero status echoed here does not necessarily indicate that the user has changed to the new group successfully. Following newgrp with the id command provides a portable means of determining whether the group change was successful or not. so like, use id. that's the tip. πŸ‘‘


πŸŽ€ EXAMPLES πŸŽ€

None. (crying, i know. 😭)


πŸ’œ RATIONALE πŸ’œ

Most historical implementations use one of the exec functions to implement the behavior of newgrp. Errors detected before the exec leave the environment unchanged, while errors detected after the exec leave the user in a changed environment. While it would be useful to have newgrp issue a diagnostic message to tell the user that the environment changed, it would be inappropriate to require this change to some historical implementations. the ancestors said no. πŸ’…

The password mechanism is allowed in the group database, but how this would be implemented is not specified. mystery again. πŸ•΅οΈβ™€οΈ

The newgrp utility was retained in this volume of POSIX.1‐2017, even given the existence of the multiple group permissions feature in the System Interfaces volume of POSIX.1‐2017, for several reasons:

  1. First, in some implementations, the group ownership of a newly created file is determined by the group of the directory in which the file is created, as allowed by the System Interfaces volume of POSIX.1‐2017; on other implementations, the group ownership of a newly created file is determined by the effective group ID. On implementations of the latter type, newgrp allows files to be created with a specific group ownership.
  2. Finally, many implementations use the real group ID in accounting, and on such systems, newgrp allows the accounting identity of the user to be changed.

so yeah she stayed. iconic of her honestly. 🌈


πŸ¦‹ FUTURE DIRECTIONS πŸ¦‹

None. the future is unspecified. slay. ✨


🌟 SEE ALSO 🌟

  • Chapter 2, Shell Command Language, sh
  • The Base Definitions volume of POSIX.1‐2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
  • The System Interfaces volume of POSIX.1‐2017, exec, getgrnam()

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


okay bestie that's the whole page 🫢 this one came to you courtesy of IEEE / The Open Group, 2017 β€” shoutout to the standards girlies, they ate and left no crumbs. πŸ’…βœ¨ go change a group, you got this. 🌸

πŸ“¦ where this page comes from