Module 2 — Assignment

Problem Statement:

You work for XYZ organization, and your work environment is UNIX/Linux-based. Your assignment consists of the following tasks:

  1. Create 3 Users: Create three users who will have access to the server.
  2. Create a Group: Establish a group named “webdev” and add the newly created users to this group.
  3. Folder and File Permissions: Create a folder named “dev” and place a file within it. Set permissions for the file such that it can only be accessed by members of the “webdev” group.
  4. User Removal: Remove one user from the “webdev” group and subsequently delete that user from the system.
  5. File Relocation and Ownership Change: Move the file from the “dev” folder to another folder. Change the file’s group ownership thereafter.
  1. Create 3 Users: Create three users who will have access to the server.
sudo useradd user1
sudo useradd user2
sudo useradd user3

Confirming:

getent passwd | grep 'user1\|user2\|user3'

Set their passwords:

sudo passwd user1
sudo passwd user2
sudo passwd user3

  1. Create a Group: Establish a group named “webdev” and add the newly created users to this group.
sudo groupadd webdev

Adding the users to group dev:

sudo usermod -aG webdev user1
sudo usermod -aG webdev user2
sudo usermod -aG webdev user3

Confirming:

getent group webdev

  1. Folder and File Permissions: Create a folder named “dev” and place a file within it. Set permissions for the file such that it can only be accessed by members of the “webdev” group.
mkdir dev #Create the folder "dev"
cd dev #Change to the "dev" directory:
touch myfile.txt #Create a file inside "dev"
ls -l #To see the permissions and ownership

Changing group ownership of the file to “webdev”:

sudo chown :webdev myfile.txt

Changing the file permissions so that only group members can read the file:

sudo chmod 040 myfile.txt #only group can read

  1. User Removal: Remove one user from the “webdev” group and subsequently delete that user from the system.

Removing user user3 from the group:

sudo gpasswd -d user3 webdev #remove from group

Removal and confirmation:
Deleting the user:

sudo userdel -r user3

Deletion and confirmation:

  1. File Relocation and Ownership Change: Move the file from the “dev” folder to another folder. Change the file’s group ownership thereafter.

Creating “prod” folder:

mkdir ../prod

Moving the file there:

mv myfile.txt ../prod/

Changing the group ownership to “prod”:

sudo chown :newgroup ../prod/myfile.txt

Confirming: