From 81ad56ab9d55f313a9eb578b113bc63a9aacdbea Mon Sep 17 00:00:00 2001 From: Amoda Fernando <101249579+fernand3z@users.noreply.github.com> Date: Mon, 13 Jan 2025 23:45:17 +0000 Subject: [PATCH] Update 101-user-groups.md add examples --- .../107-user-management/101-user-groups.md | 106 +++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/src/data/roadmaps/linux/content/107-user-management/101-user-groups.md b/src/data/roadmaps/linux/content/107-user-management/101-user-groups.md index c97898b59..8af5de38c 100644 --- a/src/data/roadmaps/linux/content/107-user-management/101-user-groups.md +++ b/src/data/roadmaps/linux/content/107-user-management/101-user-groups.md @@ -5,4 +5,108 @@ User management in Linux uses user groups to manage system users and permissions Learn more from the following resources: - [@article@How to create, delete, and modify groups in Linux](https://www.redhat.com/sysadmin/linux-groups) -- [@article@How to manage groups on Linux](https://linuxconfig.org/how-to-manage-groups-on-linux) \ No newline at end of file +- [@article@How to manage groups on Linux](https://linuxconfig.org/how-to-manage-groups-on-linux) + +# Linux User and Group Management Commands + +## Adding a New Group +To create a new group: +```bash +sudo groupadd newgroup +``` + +## Deleting a Group +To remove a group: +```bash +sudo groupdel oldgroup +``` + +## Modifying a Group +To change the name of a group: +```bash +sudo groupmod -n newgroupname oldgroupname +``` + +## Adding a User to a Group +To add an existing user to a group: +```bash +sudo usermod -aG groupname username +``` +- `-aG`: Appends the user to the group without removing them from other groups. + +## Removing a User from a Group +To remove a user from a specific group: +```bash +sudo gpasswd -d username groupname +``` + +## Changing a User's Primary Group +To modify a user's primary group: +```bash +sudo usermod -g groupname username +``` + +## Creating a New User +To create a new user: +```bash +sudo adduser newuser +``` + +## Deleting a User +To delete a user: +```bash +sudo deluser username +``` +Or using the alternative command: +```bash +sudo userdel username +``` + +## Deleting a User and Their Home Directory +To delete a user along with their home directory: +```bash +sudo deluser --remove-home username +``` +Or: +```bash +sudo userdel -r username +``` + +## Locking a User Account +To lock a user's account: +```bash +sudo usermod -L username +``` + +## Unlocking a User Account +To unlock a user's account: +```bash +sudo usermod -U username +``` + +## Changing a Group's Password +To set or change a group password: +```bash +sudo gpasswd groupname +``` + +## Examples in Action +### Create a Group and Add a User +```bash +sudo groupadd developers +sudo usermod -aG developers john +``` + +### Rename a Group +```bash +sudo groupmod -n engineers developers +``` + +### Remove a User from a Group +```bash +sudo gpasswd -d john engineers +``` + +### Delete a Group +```bash +sudo groupdel engineers