-
Notifications
You must be signed in to change notification settings - Fork 0
Linux: Using Groups
Adding new user groups is done using the group add command. To create a group type sudo /usr/sbin/groupadd (group name) replacing the (group name) part with the name of your group in the terminal.
You can use the cut -d: f1 /etc/group or less /etc/group command to verify that the new group was successfully created.
To add a member to the group use the sudo /usr/sbin/usermod -G (group name) (username) command.
You can verify that the user was added to the group by using the group (username) command.
Removing a user from a group using the sudo /usr/sbin/usermod -G (groups) (username) command is kind of tricky. When you use this command you must list out all the groups that you want the user to be a member of. Below is a screen shot of all the groups that the user steven is a part of.
To remove the user steven from the newgroup group you would have have to type sudo /usr/sbin/usermod -G lpadmin, sambashare, cdrom steven
If you ran the usermod command with only the group that you are trying to remove the user from then the user will be removed from all the groups but the you listed in the command. For example if I ran sudo /usr/sbin/usermod -G newgroup steven the user steven would only be left in the newgroup group and will be removed from all other groups.
You can also use sudo deluser (username) (groupname) to remove a user from a group. This command will not delete the user.
Groups can be deleted using the sudo /usr/sbin/groupdel (groupname) command.
Always Learning
- Home
- Websites
- Linux
- Java
- Gradle
- JUnit
- Database