I want to add the Apache user (www-data
) to the audio
group. I've read the man page for useradd
, but I'm not having any luck. I'm running xubuntu 11.10. Here's what I'm doing:
$ sudo useradd -G audio www-data
useradd: user 'www-data' already exists
If I leave out the -G
option, bash, prints the help info for useradd
:
$ sudo useradd audio www-data
Usage: useradd [options] LOGIN
Options: -b, --base-dir BASE_DIR base directory for the home directory...
It's not clear to me from the man page what options I should use to make this work.
sudo usermod -a -G [group-name] [user-name]
: Just a quickie for those who only glance at the answer after reading the headline – Programster Nov 11 '13 at 14:50sudo adduser user group
. It is simpler and cleaner syntax. See the response from @Bai. – ctbrown Aug 14 '14 at 14:20man usermod
: "-a, --append - Add the user to the supplementary group(s). Use only with the -G option.; -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] [...] If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list." – Adam Michalik Jan 26 '16 at 15:03sudo login -f YOURUSERNAME
, it will start a new shell session. Use theid
command to verify that the new session is in the correct set of groups. However, this isn't "global" - it doesn't apply to terminals that are already open. So, really, logging out is the best option, where possible – Aaron McDaid Mar 31 '17 at 14:57newgrp [group-name]
command to add a new group to the user of the current session without logging out and in again. Only the current session will be affected though. – stenix Nov 21 '17 at 10:17su - USERNAME
will directly activate a new shell with the new groups settings available. From the docs: SYNOPSYS: su [options] [-] [user [argument...]] DESCRIPTION su allows commands to be run with a substitute user and group ID. The-
is a short form for thelogin
parameter. – klaas Nov 25 '20 at 21:23newgrp
does not add the group to the current shell session.newgrp
sets the user's primary group for the current session. Logging out and logging back in again updates the list of secondary groups - it does not modify the primary group at all, hence using newgrp is not an alternative to logging out and logging back in again. If you want an alternative to logging out and logging back in again, tryexec sg <groupName> newgrp
i.e.exec sg audio newgrp
. More info here. HTH. – jaimet Aug 12 '23 at 16:44