Low Orbit Flux Logo 2 F

Linux How To Add User To Group

Add a user to a group:


sudo usermod -a -G groupname username

Add a user to multiple groups:


sudo usermod -a -G group1,group2 username

NOTE - Using “-a” appends additional groups. If you leave this out any non-specified groups will be removed.

Set user to be a member of only these groups ( remove from all others ):


sudo usermod -G group1,group2 username

Remove user from this group:


sudo gpasswd -d username groupname     

Use either command to show which groups a user belongs to:


id username
groups username

Create a new group:


sudo groupadd groupname

Delete a group:


sudo groupdel groupname

Edit /etc/group directly

vi /etc/group
test1:x:1001:

Add a single user:


test2:x:1002:user1

Add multiple users:


test2:x:1002:greg,user1,steve,user3

Manually create a group by adding a line like this. Make sure the group name (ex: test5) and group id (ex: 1005) are unique.


test5:x:1005: