Ubuntu School – Add an Existing User to a Group

Occasionally you need to grant an existing user some additional permissions to files, directories or applications. This typically means some kind of change in your permissions settings for the object in question. But because you can only have a single owner for a given object you need to be careful making these changes.

Something you can do, though, is extend the permissions on the object to a set of users by way of a group. Logically, a group is nothing more than a named collection of users who all have the same access (by way of that group) to some resource. Users in Ubuntu typically carry one primary, and one or more secondary groups (I won’t get into the differences here).

By adding group permissions to your resources (ie give the ‘payroll’ group read/write access to the ‘HR’ folder) you can simply add users to and remove users from the appropriate groups and be confident that their level of access to the resources on your machine is set correctly.

To add an existing user to an existing group:

“`
sudo usermod -a -G payroll graymond
“`

To remove a user from a group you use the same command. The catch is, you remove a user from a group by re-adding all of their groups and simply omitting the group you wish to remove them from.

“`
sudo usermod -nG mkirkpatrick
“`

The system will show you a list of the user’s groups.

“`
marketing sales vanprinters torprinters
“`

Then you simply run the usermod command as above, removing the group in question (in this case vanprinters)

“`
usermod -G marketing,sales,torprinters mkirkpatrick
“`