0% found this document useful (0 votes)
12 views

TP Linux Notion Groupe

Uploaded by

Mariem Arbi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

TP Linux Notion Groupe

Uploaded by

Mariem Arbi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Creating and Managing Groups in Linux

Objective:

Learn how to create groups, add users to groups, and manage group memberships using Linux
commands.

Part 1: Creating a Group

1. Create a group:

o Use the groupadd command to create a new group named team.

bash

sudo groupadd team

2. Verify the group creation:

o Check if the group has been successfully created by listing all groups.

bash

cat /etc/group | grep team

Part 2: Adding Users to a Group

1. Create two new users:

o Add two new users alice and bob using the useradd command (without home
directories for simplicity).

bash

sudo useradd -M alice

sudo useradd -M bob

2. Add alice to the team group:

o Use the usermod command to add alice to the team group.

bash

sudo usermod -aG team alice

3. Add bob to the team group:

o Similarly, add bob to the team group.

bash

Copy code

sudo usermod -aG team bob

4. Verify the users are part of the group:

o Check group membership of both users using the groups command.


bash

groups alice

groups bob

Part 3: Managing Group Membership

1. Remove alice from the team group:

o To remove alice from the team group, use the gpasswd command.

Bash

sudo gpasswd -d alice team

2. Verify removal:

o Check if alice has been removed from the group.

bash

groups alice

Part 4: Setting Group Ownership and Permissions

1. Create a shared directory for the team group:

o Create a directory called shared_folder that will be owned by the team group.

bash

sudo mkdir /shared_folder

2. Set the team group as the owner of the directory:

o Use the chown command to set team as the group owner of the shared_folder.

bashsudo chown :team /shared_folder

3. Set permissions so only the team group can access the directory:

o Use the chmod command to give the team group read, write, and execute
permissions on the folder.

bash

sudo chmod 770 /shared_folder

4. Verify the permissions:

o Check the permissions of the directory to ensure that they are set correctly.

bash

ls -ld /shared_folder
Part 5: Deleting a Group

1. Remove the team group:

o If you no longer need the group, delete it using the groupdel command.

bash

sudo groupdel team

2. Verify group deletion:

o Check if the group has been successfully removed.

bash

cat /etc/group | grep team

Summary of Commands:

• groupadd: Create a new group.

• usermod -aG: Add a user to a group.

• groups: List group memberships of a user.

• gpasswd -d: Remove a user from a group.

• chown: Change file/directory ownership.

• chmod: Set file/directory permissions.

• groupdel: Delete a group.

You might also like