Department of IT & CS
Course Instructor: ____________________ Dated: ________________
Semester: __________________________ Section: ________________
COMP-262L: Operating Systems
Lab 04: User Management in Linux, File Permissions
Utilities: bash, chmod, gcc, groupadd, mkhomedir_helper, passwd, us, useradd
CLO1 CLO2 CLO3
Name Reg. No. Lab Tasks Report Viva Total
Marks Marks Marks Marks
20 5 5 30
Objectives:
User management in Linux environment.
File permissions in Linux environment
Use following Linux utilities: bash, chmod, gcc, groupadd, mkhomedir_helper, passwd, us,
useradd
COMP-262L: Operating Systems Page 1
Lab 04: User Management in Linux, File Permissions
Utilities: bash, chmod, gcc, groupadd, mkhomedir_helper, passwd, us, useradd
Write and explain the commands used to perform each task. Also attach the output response.
Lab Task 1: [4 Marks]
a. List all the normal users in the system using the alias created from Lab 03.
b. Add the following users to the system. user01 must have the home directory
created at the time of the creation of the user.
User ID Group ID
user00 1010 GroupA 1010
user01 1011 GroupB 1011
user02 1012 GroupB 1011
c. Create the home directories for user00 and user02.
d. Verify that the users have created by listing the normal users again.
Lab Task 2: [4 Marks]
a. Try to login as user01 without setting the password for user01.
b. Create the passwords for all the users.
c. Login as user01 and create the file user01.txt in the home directory. Use ls
command to check the default permission of that file.
d. Login as user02 and try to read the file user01.txt.
e. Login as user00 and try to read the file user01.txt.
f. Restrict the permissions of the file such that neither user00 nor user02 can read
the file.
g. After that change the permission (use either symbolic mode or Absolute mode) of
the file as following: user01 has the permission to read, write and execute the file,
group has the permission read and write the file. Other can also have the
permission to read and write the file.
Lab Task 3: [4 Marks]
a. setuid is a Linux file permission setting that allows a user to execute that file or
program with the permission of the owner of that file. Create a testfile.txt that
cannot be read by user00. Compile the given code that reads the testfile.txt and
displays it. setuid for the executable file.
b. Try to read testfile.txt as user00.
c. Try to read testfile.txt by running the executable file created in a).
Lab Task 4: [4 Marks]
a. Restrict the home directory of user01 such that no other user can modify it.
b. Restrict the home directory of user01 such that no other user can access (navigate
to) it.
COMP-262L: Operating Systems Page 2
Lab Task 5: [4 Marks]
a. List all the commands you have used in this lab in a table with one line
description of each.
Code Listing for Lab Task 3
COMP-262L: Operating Systems Page 3
#include <stdio.h>
#include <stdlib.h>
int main() {
char c[1000];
FILE *fptr;
if ((fptr = fopen("testfile.txt", "r")) == NULL) {
printf("Error! File cannot be opened.");
exit(1);
sleep(5);
// reads text until newline is encountered
fscanf(fptr, "%[^\n]", c);
printf("Data from the file:\n%s", c);
fclose(fptr);
return 0;
COMP-262L: Operating Systems Page 4