Add a New Group
If you want to create a new group on your system, use the groupadd
command following command, replacing new_group with the name of the group you want to create:
# sudo groupadd new_group
Add an Existing User Account to a Group
To add an existing user account to a group on your system, use the usermod
command, replacing examplegroup
with the name of the group you want to add the user to andexampleusername
with the name of the user you want to add.
# usermod -aG examplegroup exampleusername
For example, to add the user geek
to the group sudo
, use the following command:
# usermod -aG sudo adi
To view the groups another user account is assigned to, run the groups
command and specfy the name of the user account.
# groups exampleusername
Add a User to Multiple Groups
While assigning the secondary groups to a user account, you can easily assign multiple groups at once by separating the list with a comma.
# usermod -a -G group1,group2,group3 exampleusername
For example, to add the user named geek to the ftp, sudo, and example groups, you’d run:
# usermod -a -G ftp,sudo,example adi