Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

Republic Polytechnic - School of Infocomm

C330 Linux Administration and Virtualisation


AY2022 Semester 2

Problem Statement
LP1: Manage users/groups and control access to files/folders

WORKSHEET

IMPORTANT
Please complete the Lab Safety Acknowledgement for AY22 Semester 2 via this URL:
https://forms.office.com/r/spScG2CKU9

LP1 – Lesson 1 Academic Week 1

LEARNING OBJECTIVES
 Describe the features of a Linux system
 Explain the Linux File-system hierarchy to organize files and directories.
 Perform file operations such as create, view, edit and delete files using Command
Line Interface (CLI) or text editor
 Write simple Bash Scripts

Accessing Lab Resources

 Your lecturer will assign the AIO machine and IP address respectively. Do take note of the IP
address assigned to you.
 You need to use the same AIO machine throughout the semester. For eLearning lessons
(week 2 and week 8) you need to RDP to access the AIO machine. For LOA students, your
lecturer will assign the IP address and need to RDP to access the AIO machine.
 You are not allowed to access the AIO during non-lesson days as the AIO machines will used
by other classes
 For this module you will use Red Hat Enterprise Linux (RHEL) 9.0. You can use the
below ways to access the lab. Refer to “Student Resources” folder for more
information.

During Lesson
- All-In-One Machine (AIO) – Refer to student resources folder “Accessing AIO
Machine.docx”
- Red Hat Academy Learning Portal (RHALP) – Refer the student resources folder to
access RHEL online learning resources. (Refer to the following documents)
o RHN ID creation.pdf
o Accessing Red Hat Platform.pdf

After Lesson
- Your own Virtual Machine – Refer to Lab Guide.docx to install VMware Workstation
and RHEL9.0
- Red Hat Academy Learning Portal (RHALP) – Refer the student resources folder to
access RHEL Labs.
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2
Learning Phase 1

Problem Definition Template (PDT) (20 mins)

 Discuss among your team and start working on the PDT to break down the problem
statement. Use the given template C330_LP01_PDT_Template.docx.

 Upload the PDT into the MS Teams channel which you are assigned to. Do use the MS
Teams channel to collaborate with each other & work on the PDT internally.

 Your input and contribution will be used as part of the assessment for collaborative
learning portion of your CA assessment.

 Each team will be assigned a VM. Use the VM to build your solution for the problem
statement and you need to demonstrate the completion of tasks during week 4.

Prior Knowledge (10 mins)

1. Based on your prior knowledge from C226 and C327, discuss within your team and
answer the following questions
a. What is virtualisation?
b. Explain the role of hypervisor. Give examples of hypervisor.
c. Do you have experience in using VMware Workstation to run multiple
operating systems on multiple virtual machines on your laptop? What are the
advantages of virtualisation?

Why Linux and What Makes Linux Great? (10 mins)

Read RHALP RH124 Chapter 1: Getting Started with Red Hat Enterprise Linux and watch
the video in “C330 Module Overview for Students.pptx” to answer the questions below.

In the modern data center, Linux and Microsoft Windows are the major players, and Linux is
a growing segment in that space. Some of the many reasons to learn Linux include:
 A Windows user needs to interoperate with Linux.
 In application development, Linux hosts the application or its runtime.
 In cloud computing, the cloud instances in the private or public cloud environment
use Linux as the operating system.
 With mobile applications or the Internet of Things (IoT), the chances are high that
the operating system of your device uses Linux.
 If you are looking for new opportunities in IT, Linux skills are in high demand.
 Linux and DevOps share similar philosophies and perspectives such as customization
and scalability
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

2. Refer the link https://opensource.com/resources and the video “Linux History.mp4”


under resources folder, discuss with your team to answer the following questions:
a. What is an open source software? What are the advantages of using open
source software as compared with proprietary software?
b. In what ways does open source technology benefits non-programmers? (Hint:
discuss with your team to explore on open source tools used in
Cloud/DevOps)
c. What are the challenges faced in open source software adoption?

3. What is Linux and what is a Linux distribution? How is RHEL different from other
Linux distributions?
(hint: https://en.wikipedia.org/wiki/List_of_Linux_distributions)

Accessing a Linux System (20 mins)

- Read RHALP RH124 Chapter 2: Accessing the Command Line and Chapter4: Get
Help in Red Hat Enterprise Linux and complete “C330 L1 Lab Guide.doc” to answer
the questions in this section.

4. Explore the features of a Linux system such as navigating around the desktop and
running simple commands to answer questions below (Refer to “C330 L1 Lab
Guide.doc”). Include screenshots from lab guide.

5. What are the different ways to get help in a Linux system? Include a screenshot to
show them. (Hint: man, info, --help, whatis)

6. What are the different ways to access the command line?

7. Refer to the screenshot below to answer the following questions.


Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

a. Notice that there are two different prompts namely $ and #. What is the
difference between them?
b. What is the command to switch between users?
c. To list the contents of a directory, ls command is used. Try different options in ls
command such as -a, -l, etc., Include a screenshot and how do they differ from
each other?
d. A user’s home directory (Do not be confused this with /home directory!) is
represented by the Tilde (~) character. Try the below in your terminal. What does
it do?
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

Learning Phase 2

Read RHALP RH124 Chapter 3: Managing Files From the Command Line to answer the
questions below. Make use of additional resources as needed.

Linux File-System Hierarchy (15 mins)

8. Name any 2 directories and files under /etc and explain the purpose of it.

9. What is the difference between /bin and /usr/bin?

10. What kind of information is stored in /usr directory?


Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

Navigating using Absolute Paths and Relative Paths (20 mins)

11. You are currently in /home/student. Using absolute path, switch to /etc directory.
What is the absolute path to navigate to the /var/log from /etc directory. Include
the commands and screenshot of your answers.

12. You are currently in /home/student. What is the relative path to navigate to /etc
directory? Include the commands and screenshot of your answers.

Managing Files using Command-line Tools (20 mins)

13. Complete the guided exercise on “Managing Files Using Command-line Tools” using
RHALP lab and include a screenshot of your completed work.

(Hint: Refer to the RHALP Lab Guide to access Red Hat labs host on the cloud. You
are given only 60hrs. So, shutdown the VMs once you have completed to optimize
the lab usage)
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

14. Create a new directory <yourname_test> in your home folder. In <yourname_test>, create
another directory <yourclass_test>. (Hint: use man command to explore mkdir options to
create the two directories in a single command). Include a screenshot to showcase your
completed work.

15. From your home directory, what is the command to remove the two directories created in
the above question? (Hint: Use man command to see more options)

16. Try the below commands in command line. (Hint: Use man command to see more options)
Comman Usage Example
d

cat Displays the contents of a file Cat <filename>

more

less

head

tail

file

touch

cp

mkdir

rmdir
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2
mv

touch

Making Links Between Files (15 mins)


In a Linux system, it is possible to create multiple names that point to the same file either by
creating a hard link to a file or by creating a soft link (symbolic link) to a file.

17. Observe screenshot below to answer the following questions

a. How many files are created?


b. What is an inode number and how can you list the files with inode number?
c. What are the limitations of hard links?

18. Complete the following tasks and include a screenshot to show the completion of
your work.
a. Create a file one.txt and include a line “original contents”.
b. Create a soft link named /home/student/sl_one.txt that points to the
one.txt and append a line “testing soft link” to the file
/home/student/sl_one.txt
c. Verify the newly created soft link and its contents.
d. Now delete the file one.txt. Verify the newly created soft link and its
contents. What do you observe?

Matching File Names with Shell Expansions (20 mins)

Globbing is a shell command-parsing operation that expands a wildcard pattern into a list of
matching path names. Command-line metacharacters are replaced by the match list prior to
command execution. Patterns that do not return matches display the original pattern
request as literal text. The following are common metacharacters and pattern classes.
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

19. Do a long listing of all the files in the /var/log/ directory which have at least one
“.”(dot) as part of their filename.

20. Do a list of all the files in the /var/log/ directory which have only a single character
after the “.”(dot) as part of their filenames.

21. Do a list of all the files in the /var/log/ directory which have more than a 3-letter
extension after the first “.” (dot) in their filenames. E.g. test.log file does not match
but test.log.log does.

Command Line Expansions

22. What does the below command do? Include a screenshot to show the output.

23. Complete the guided exercise on “Managing Files from the Command Line” using
RHALP lab and include a screenshot of your completed work.
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2
(Hint: Refer to the RHALP Lab Guide to access Red Hat labs host on the cloud. You
are given only 60hrs. So, shutdown the VMs once you have completed to optimize
the lab usage)

Learning Phase 3

Creating and Executing simple Bash Shell Scripts

Many simple, common system administration tasks are accomplished using command-line
tools. Tasks with greater complexity often require chaining together multiple commands
that pass results between them. Using the Bash shell environment and scripting features,
Linux commands are combined into shell scripts to easily solve repetitive and difficult real-
world problems.

24. What is a shell script? Why do we need to use shell scripts?

25. Below is an example of a shell script. Open the editor and type the lines as per the
below screenshot. Save in a file first.sh and change the permission to executable by
typing the command chomd +x first.sh and type ./first.sh to execute it. What is the
output of first.sh?
(Hint: chmod command will be covered in subsequent lessons)
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

26. A positional parameter is a variable within a shell program; its value is set from an
argument specified on the command line that invokes the program. Positional
parameters are numbered and are referred to with a preceding ``$'': $1, $2, $3, and
so on. Observe the below program and explain how do we input the values of
positional parameters? How many positional parameters are there? What is the
output of the shell script, if we execute as ./pp.sh one two three?

27. Try the below and observe the output. What does a $ used for in the below output?

28. Write a single command to print the output below. (Hint –use --help to find out the
options for the date command and it should print the current date and time while
running the command).

29. Write a shell script to perform the below tasks


 To output your name
 To add two numbers
(Hint: try with/without positional parameters)
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

Scripting using loops

30. Try the below in your command line.

What is the output? What is the purpose of using seq?

31. Using for loop, write a script list.sh that lists all files in the current directory. Run the
script and include the script and the output of list.sh
(Note: You are rewriting the ls command without using it)

CHALLENGE YOURSELF!

You need to perform the following tasks on AIO in your assigned VM using Command Line
Interface (CLI) only. Verify your work after completing each step. (10 mins)
 Use single command to create two directories target and achieve under /tmp/C330
(hint: check whether /tmp/C330 exists. If not, you need create it)
 Create a file named <your-name>_target.sh inside “C330”
 The content of the file <your-name>_targe.sh:
a. Line 1: My target is (Distinction/A/B/C/D/F) (Choose one) for C330 module
 Using single command copy <your-name>_target.sh to <your-name>_achieve.sh
under the folder /tmp/C330
 Without using a text editor, modify the file /tmp/C330/<your-name>_achieve.sh to
append the line “I will achieve my target”
 Execute the following commands
a. ip addr
b. echo “your-name”
c. cat /tmp/C330/<your-name>_target
d. cat /tmp/C330<your-name>_achieve
 Capture the results in a single screen.

Deliverables for Academic Week 1


Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

a) Team to work on individual contribution in MS Teams channel and upload


PDT (team)  MS Teams channel for your own team by 23:59.

b) Individual Worksheet (completed up to this point)  individual submission folder in


LEO 2.0 by 23:59, uploaded in DOC format.
Note: This is mainly to track your progress and advise you if needed. Worksheet will
not be marked until FINAL submission in week 3.
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

Instructions for Week 2 Briefing

LEARNING OBJECTIVES
 Perform file operations such as create, view, edit and delete files using Command
Line Interface (CLI) or text editor
 Differentiate the types of users and types of groups.
 Create, modify and delete users and groups using CLI

Lesson 2 (from 25th to 31st Oct), will be conducted using Asynchronous E-Learning mode.
You will NOT be required to come to RP campus on the day of your Lesson 2

You will be given 3 days (including Sat, Sun & Public Holidays) to attempt and complete all
deliverables.

Attendance will be marked present and if you miss to submit the deliverables, your attend
will be marked as “ABSENT”

Read RHALP RH124 Chapter 5: Creating, Viewing, and Editing Text Files and Chapter 6:
Managing Local Users and Groups to complete week 2 worksheet.
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

LP1 – Lesson 2 Academic Week 2 (Asynchronous E-learning)

LEARNING OBJECTIVES
 Perform file operations such as create, view, edit and delete files using Command
Line Interface (CLI) or text editor
 Differentiate the types of users and types of groups.
 Create, modify and delete users and groups using CLI

Lesson 2 (from 25th to 31st Oct), will be conducted using Asynchronous E-Learning mode.
You will NOT be required to come to RP campus on the day of your Lesson 2
You will be given 3 days (including Sat, Sun & Public Holidays) to attempt and complete all
deliverables.

OVERVIEW
 Use this worksheet as a guide to attempt indicated courses in RHALP learning
resources.
 Include all required evidence of completion in your worksheet.
 Ask your lecturer questions via chat or email.
 Upload your completed (for Week 2) worksheet to LEO 2.0 Individual File
submission.
 Deadline for submission is 23.59hrs, 3 days AFTER the day of your Lesson. 2
 Ensure you are able to access RH124 materials and lab resources in RHALP
 If you have any issues with the account, refer to LP1 Student Resources folder or
contact sharmila_kanna@rp.edu.sg for assistance.

Read RHALP RH124 Chapter 5: Creating, Viewing, and Editing Text Files and Chapter 6:
Managing Local Users and Groups to answer the questions below. Make use of additional
resources as needed.

1. View the contents of the below files and explain what information is stored in each
file.
/etc/passwd
/etc/group
/etc/shadow

2. You have used the two users accounts namely root and student frequently. What is
the difference between the two users?
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2
3. Create a new user kelvin using useradd command and answer the following
questions.
a. What is the userid and groupid for kelvin?
b. Is there any passwd created for kelvin?
c. Is the home directory created for kelvin? (hint: /home)
d. What is the default shell prompt for kelvin?

4. Create a random password for user kelvin (hint: store the password in a text file) and
set the expiry date for the password to be one month later. (hint: chage command)

5. What is the command to force the user hakim to change the password at next login?

6. State the COMPLETE commands to create a new group teamX with groupid 4000 and
add your team members in into the group. Upon completion, include a screenshot to
verify your work. (Note: replace X in teamX with your team number)

7. Modify the user kelvin so that the primary group of user kelvin is group teamX.

8. With great power comes great responsibility! Root user is capable of doing everything
to the system, which also includes destroying the whole system! It is recommended
that for daily use, we do not use the root to log in. Then how do we run some
commands that only root user can run? Such as ls /root. Do a search online to find a
solution for this. (Hint: run command as root in Linux)

9. You may encounter the word “sudoers” by now. How can a “sudoer” run the
commands that only root user can run? (Hint: sudo command)

10. How do you make an existing user to have “sudoer” rights?


Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

CHALLENG YOURSELF!

In a real-life environment, system administrators need to add quite a number or


users/groups. Is there a better way to do it? (Hint: remember shell scripting you learned last
week?)

Create a bash scripts so that when the script run as below:


./week2_challenge_<your-name>.sh e62a Republic

 It creates XX students' accounts e62astudent01 to e62astudentXX on the system


with their respective home folders created.
 It creates a group called e62a
 It adds e62astudent01 to e62astudent25 to the group e62a
 The initial password for all the accounts is set to republic@!

Hint:
 XX is the total number of students in your class
 use seq command to generate a sequence of numbers.

Deliverables for Academic Week 2

a) Individual Worksheet (completed up to this point)  individual submission folder in


LEO 2.0 by 23:59, uploaded in DOC format.
Note: This is mainly to track your progress and advise you if needed. Worksheet will
not be marked until FINAL submission in week 3.

Academic Week 3

LEARNING OBJECTIVES

 Set up file-system permissions on files and folders using CLI


 Demonstrate the tasks of managing users to groups, and the setting of files and
folders permissions using CLI, for a given scenario
 Write bash scripts to automate Users and Groups management tasks to access files
and directories using loops for a given scenario

Learning Phase 1

Revisit eLearning Concepts


Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

 Presentation by Lecturer on week 2 concepts

 Your lecturer will share an activity and complete the activity individually in your
assigned AIO machine. Students are randomly selected to demonstrate the tasks.

Learning Phase 2

Watch the video https://www.youtube.com/watch?v=DAhlwb7Hw2M.

1. Who is the owner and group of the file at.deny?

2. What are the permissions for the file /etc/passwd? Can anyone else other than the
root user views this file?

3. The actual hashed and salted passwords are stored in /etc/shadow. Based on the
screenshot below. What are its permissions? Can anyone else other than the user
root views this file?

4. What is the reason for storing hashed and salted passwords in a file /etc/shadow?

5. Create a file called script.sh using touch command. What is its default permission?
(Note this!)

6. Type chmod 755 script.sh


What permission did the command set for script.sh? Complete the table below:
Read Write Execute (Yes/No)
(Yes/No) (Yes/No)
User
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2
Group
Others

7. Type chmod 640 script.sh


What permission did the command set for script.sh? Complete the table below:
Read Write (Yes/No) Execute (Yes/No)
(Yes/No)
User
Group
Others

8. Show who is the owner and group for the file script.sh

9. Change both the owner and group to student for the file script.sh

10. Using the symbolic method, remove write permissions for owner, and all permissions
for group and other users for the file script.sh

11. Using the numeric method, allow only read+execute for all others, except the owner
who should have read+write+execute permissions for the file script.sh.

12. Using the numeric method, allow only read+write for owner, while all others do not
have any access to the file script.sh.
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

13. In root home directory, use touch to create a new file. Note down its default
permission.

14. In another terminal window, change to the student user to try and access the file.

15. Use chmod to allow the student user to access the file, and test it using the other
terminal window.

16. Use chown to allow the student user to access the file, and test it using the other
terminal window.

Default permissions – umask


17. Type in umask and as root user, what is the umask value?

18. Now change to a non-privileged user su student and type in umask. What is the
umask now?

Calculating permissions from umask


19. You have logged in as student user. What would the allowed permissions for a newly
created file and folder be as both root user and student user, if the umask is
changed to 0055? (Try it yourself!)

Default permissions – Setting up of umask

20. What is the umask value so that newly created directories are RWX only to the
owner? Newly created files/directories should not be accessible to others. Test it
out by creating a new directory and file.
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2
21. Now use the umask command to set all created files having only read/write
permissions for the owner, read permissions for group while no permissions for all
other users. Test it by doing a touch on a new file and viewing the permissions in a
new Terminal. Include a screenshot to verify your work.

22. Match the following items to their counterparts in the table

Description ACL Operation


Display the ACL on a directory.
Named user with read and execute permissions for a file.
File owner with read and execute permissions for a file.
Read and write permissions for a directory granted to the directory
group owner.
Read and write permissions for a file granted to the
file group owner.

23. Complete the “RHALP RH134 Chapter 4: Controlling Access to Files with ACLs” lab in
Red Hat lab portal and include a screenshot on the completion of your work
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2

Deliverables for Academic Week 3

a) Team to work on individual contribution in MS Teams channel and upload


PDT (team) –> MS Teams channel for your own team by 23:59.

b) Individual Worksheet (fully completed) –> individual submission folder in LEO 2.0 by
23:59, uploaded in DOC format.

c) Individual Reflection Journal -> LEO 2.0 by 23:59.


Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2
Academic Week 4

Deliverables for academic week 4

a) Team presentation slides –> team submission folder in LEO 2.0 by 10.15am
b) Team Demonstration using Team VM  do not delete any work done in your VM
c) Peer Evaluation (in LEO)
d) Self-Evaluation (in LEO)

 The work done in Team VM will be deleted by end of the day. So, capture
screenshots to include in the team presentation slides.
 Include the following in your presentation
a) PDT indicating breakdown & analysis of problem from MS Teams
b) A slide to elaborate the individual contribution percentage within the team
should be included. Below shows an example of the slide. This should be
mutually agreed by each of the members in the team.
c) Solution to the Problem Statement
d) Challenges faced

Example:
Member Name Individual Contribution within the team
to the solution(s) for the problem
statement
Member 1 50%
Member 2 30%
Member 3 15%
Member 4 5%
Member 5 0%

Learning Phase 1

PPT Upload (Team) - 30 minutes

 Teams MUST do their own research and are NOT to use any media (images/videos) provided in
this worksheet.
 Ensure that the delivered PPT solution for the team includes the PDT, as well as details on
individual contribution percentage.

1st Team Presentation – 30 minutes

Learning Phase 2
Republic Polytechnic - School of Infocomm
C330 Linux Administration and Virtualisation
AY2022 Semester 2
2nd/3rd/4th Team Presentation – 1 hour 30 minutes

Learning Phase 3

5th Team Presentation – 30 minutes

Class Discussion (Lecturer-Led) – 30 minutes

In-class paper quiz – 30/40 minutes

 Open-book (laptop allowed with network/Wi-Fi access disabled)


 Lecturer to ensure students do NOT communicate with others during quiz

You might also like