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.
The
useradd
command will try to add a new user. Since your user already exists this is not what you want.Instead: To modify an existing user, like adding that user to a new group, use the
usermod
command.Try this:
The
-a
(append) switch is essential. Otherwise, the user will be removed from any groups, not in the list.The
-G
switch takes a (comma-separated) list of additional groups to assign the user to.In general (for the GUI, or for already running processes, etc.), the user will need to log out and log back in to see their new group added. For the current shell session, you can use
newgrp
:newgrp
adds the group to the current shell session.Adding a user to a group:
Removing a user from a group:
After adding to a existing user:
You may need to logout and login to get the groups permissions from
/etc/group
.I normally use
I'm posting this as an answer because I don't have enough reputation to comment. As @dpendolino's mentioned, for the effects of this command to persist:
sudo usermod -a -G groupName userName
...you need to logout/login again.
However, if you need a shortcut to start using your new group membership immediately (and you have the correct sudo privileges) I have found this work-around:
Explanation:
sudo su -
will give you a root shellsu [userName]
returns you to a shell with your usergroups
when run now will show the group you added with theusermod -aG
commandIn my case I was trying to add the 'docker' group to my user
Before:
After:
will work just fine, but I had to reboot entirely, just log out and log in again did not do the job...
On Ubuntu, since logging in as
root
is not enabled, users in thesudo
group can elevate privileges for certain restricted commands. Any restricted command must be prepended withsudo
to elevate privilege.will add the existing user
user
to a supplemental group namedgroup
. The user's primary group will remain unchanged.To permanantely add a user to a group, run this command:
Then log out and log in again (or reboot if necessary).
Explanation:
The
usermod
command will modify the/etc/group
file to list the specified username in the line relevant to that group. If you rungrep <groupname> /etc/group
, you should see your username in the output.In Linux, every process is assigned to a user and groups, and any child processes inherit the user and groups of the parent process. So, for this change to take effect and propogate, you need to log out and log in again (at which point
/etc/group
is read and used). On Wayland, I've found that a full reboot is necessary.If you run the command
groups
, you can see if the current process has the expected groups or not.