LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

sg

execute a command with a different group ID

TLDR

Start a shell with a different group
$ sg [group]
copy
Execute a specific command with a different group
$ sg [group] -c "[command]"
copy
Run a command as the www-data group
$ sg www-data -c "touch [/var/www/html/file.txt]"
copy
Start a login shell with a different group, reinitializing the environment
$ sg - [group]
copy

SYNOPSIS

sg [-] [group] [[-c] command]

DESCRIPTION

sg executes a command or starts a shell with a different group ID. It is functionally similar to newgrp but allows running a single command rather than starting a new shell session.When called without a command, sg starts a new shell with the specified group as the effective group ID. When called with -c, it executes the given command with the new group and returns.The user must be a member of the target group, or the group must have a password set (via gpasswd) which the user can provide. The root user can switch to any group without restrictions.

PARAMETERS

group

The group name to switch to. The user must be a member of this group (or know its password).
-c command
Execute the specified command with the new group ID rather than starting an interactive shell.
-
Start the shell as a login shell, reinitializing the environment.

INSTALL

sudo apt install login
copy
sudo apk add shadow-login
copy

CAVEATS

The sg command is part of the shadow-utils package. If the user is not a member of the specified group and no group password is set, access will be denied. Environment variables may be reset depending on how the shell is invoked. On some systems, the sg name may conflict with the ast-grep tool alias; use the full path /usr/bin/sg if needed.

SEE ALSO

newgrp(1), groups(1), id(1), gpasswd(1), su(1), chgrp(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid