Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

1.

SoftLink_Ex1:

The /home filesystem is nearly full and hence there is hardly any space left in it to
store user files.
You being the system administrator have determined that there’s a lot of free space
available in the "/opt" filesystem. Create a directory named "/opt/userdata" to store
the users data.
To make access simple for all the users, create a soft link "/home/sdata" to
"/opt/userdata".

ANS:

$ sudo mkdir /opt/userdata

$ sudo ln -s /opt/userdata /home/sdata

2.HardLink_Ex2

You are an experienced computer user and therefore have a very good
understanding of how the system stores files. You are very well aware that
managing multiple instances of the very same file is a lot harder than
managing a single file / dir with multiple references to it. Therefore you
have decided to create a hard link to the file.
Your Task: Create a file named "/opt/hdir/sourcefile". Create a hard link
"/opt/hardfile"
pointing to "/opt/hdir/sourcefile".

ANS:

$ sudo mkdir /opt/hdir

$ sudo touch /opt/hdir/sourcefile

$ sudo ln /opt/hdir/sourcefile /opt/hardfile


3.Permission_Ex1

Tom is the Project Manager at XYZ.INC and is in charge of a group of


developers who are about to develop an E-Commerce web application.
Tom would like the developers to make use of a common directory in order
to save their project work. He also wants to ensure that no one but the
developers have access to the directory. Tom has obtained all the
necessary approvals ahead of approaching you, the System Admin.
Your task: Create a common directory named "/opt/common" on the server
as per the
following requirements.
- The directory should be owned by user "prjmgr" and group "developers".
- Make sure the "/opt/common" directory should have only full access to
owner and group. Set the SETGID bit on, so that the same permission will
be replicated from parent directory to all files & Sub-directories.
- For verification, login or su as "prjmgr" user and create a file named
"/opt/common/sgidfile". The file group should be "developers" group.

ANS:

$ sudo mkdir /opt/common

$ sudo chown prjmgr /opt/common

$ sudo chgrp developers /opt/common

$ sudo chmod ug+rwx /opt/common

$ sudo chmod o-rwx /opt/common

$ sudo chmod g+s /opt/common

$ sudo su prjmgr

$ cd /opt/common
$ touch sgidfile

$ ls -ltr

4.ModifyContent_Ex1

Tom created a text document using the vi editor and has shared the
document with you. You are expected to review the same, correct any
errors and send it over to the client.
Your task: Backup the "/opt/Software/vi_ModifyContent_Ex1.txt" as
"/vifile.txt" and Modify the "/vifile.txt" according to the below requirement
and save the file when done with modification.
- Replace "output" word as "printout".
- Convert the entire word "David MacKenzie" into Uppercase.
- Remove the word "leading". If there is multiple occurrence, remove all
words.

ANS:

$ sudo cp /opt/Software/vi_ModifyContent_Ex1.txt /vifile.txt

$ sudo sed -i 's/output/printout/g' /vifile.txt

$ sudo sed -i -e 's/\(David MacKenzie\)/\U\1/g' /vifile.txt


$ sudo sed -i 's/leading//g' /vifile.txt

5.Findandsetpermission_Ex1

In the production environment, you have been asked to change the


permission for few directories located at different paths. The server holds a
very huge volume of sensitive data. Any error may lead to application
failure. So it is always good to practice in the test environment and have a
proper set of commands for production implementation.

Your task:
Execute the following commands.
umask 0022
mkdir -p /tmp/test/dir{1..10}/{depta,deptb,deptc}/{sales,accounts,admin}
touch /tmp/test/dir{1..10}/{filea,fileb}
touch /tmp/test/dir{1..10}/{depta,deptb,deptc}/{fileaa,filebb}
touch
/tmp/test/dir{1..10}/{depta,deptb,deptc}/{sales,accounts,admin}/{fileaaa,fileb
bb}

Find all the directories with 755 permission under /tmp/test/ and set the
permissions to 770 for the directories alone?

ANS:

$ mkdir -p /tmp/test/dir{1..10}

$ sudo find /tmp/test -perm 755

$ sudo chmod 770 /tmp/test/dir{1..10}


6.CreateUser_Ex1:

A new employee named Tom has joined the company. As a linux administrator you
are asked to create a user named "tom" in the Linux Server.

ANS:

$ sudo useradd tom

7.CreateGroup_Ex2

In your organization, all IT linux admin users require access to certain directories. As
a Linux administrator, you are asked to provide access using common group named
"linuxadmin". Create a group as per the requirement.

ANS:

$ sudo groupadd linuxadmin

8.CreateUserNoLogin_Ex4
An installed application requires a user named "appuser1” for ownership of the
application related files as well as for managing the application’s services.
Therefore...
Create a user "appuser1” and restrict the user account from being able to login to
the system.

ANS:

$ sudo useradd -s /sbin/nologin appuser1


9.ModifyUserSecGroup_Ex2:
We have a few fun games scheduled for next weekend’s winter event. Grouping the
participants based on their friendship will make the games a lot more fun and lively wouldn't
it? Create a users named "sam", "beam" with their respective private group. Create a new
group named "friends". Make "friends" as secondary group for "sam and Beam".

ANS:

$ sudo useradd sam

$ sudo useradd beam

$ sudo groupadd friends

$ sudo usermod -G friends sam

$ sudo usermod -G friends beam

10.DeleteUser_Ex3-
Henceforth the user named "Ram" has been asked to work in a newly installed server. You
the admin need to delete the user account "ram" (including the user’s home directory) from
the server he has been working on until now.

ANS:
$ sudo userdel -r ram

11. LockUser_Ex4
Create a user named "nile" with the respective private group and set the password as
"changeit". Few months later, the user "nile" has been reported of suspicious activity in the
server. As an Admin, you are now been asked to lock the nile user account.

ANS:

$ sudo useradd nile

$ sudo passwd nile

New password:changeit

Retype new password: changeit


$ sudo usermod -L nile

12.Creating Users & Groups_Ex1


Assume that you are the admin of a start up IT organization who manages server access of
the employees. Your organization has recruited 2 new sales managers Josh & Guru as a
part of expanding the business. Please create users and groups based on the below
specifications.
manager: gid - 2001, sales: gid - 2002.
josh: Primary group - manager, secondary group - sales, shell - sh, uid - 2001, Password -
changeit.
guru: Primary group - sales, secondary group - manager, shell - bash, uid - 2002, Password
- changeit.

13. UserAccountExp60_Ex3
Two contract workers will be working for our organization temporarily. Both of them will need
login accounts on the Linux server only for the next 2 months (60 days) Your task: Create
users named "user1age60, user2age60". Determine the date from now to 60 days in the
future and set each of the two new user accounts (user1age60 & user2age60) to expire on
the determined date.

ANS:

$ sudo useradd -e 2021-08-20 user1age60

$ sudo useradd -e 2021-08-20 user2age60

(Put the dates after 60 days from the day you are doing…..)
15.PasswdPolicyFirstLogin_Ex5
It has been noticed that most new users usually tend to keep the same old password that
was shared with them by their system administrator during the time their user account was
created. You as their manager realize the potential security risk such shared passwords can
cause if they remain unchanged.
Your task: Create a user named "firstuser" and force the newly created user to change his
password on first login.

ANS:

$ sudo useradd firstuser

$ sudo passwd -e firstuser

16.df_freeinodes_Ex1
The Animation server is being used to store very huge numbers of tiny image and video files.
Each of those files use up an inode as well as harddisk space. Therefore the “/” filesystem
tends to run out of inodes or free disk space quite unexpectedly. The users of the server get
annoyed because they are unable to save their work and end up with unwanted delays and
unhappy customers.
Your task: Keeping an eye on the number of inodes and disk space that are being used up
during regular intervals has become rather important. Therefore you the System admin need
to ....

1. Find the number of allocated inodes of "/" file system and write the number alone in the
file /tmp/inodesallocated.
Eg: 12345

2. What is the total allocated size (in MB) of the "/" file system and write the size alone in the
file /tmp/rootsize.
Eg: 120 ( Do no include MB)

ANS:

$ sudo su
# touch /tmp/inodesallocated

# cat > /tmp/inodesallocated

4194304

# touch /tmp/rootsize

# cat > /tmp/rootsize

8182

17. mount_noexec_Ex2
A user needs to execute a few binary files present on /opt file system. Check and confirm
whether the user has execute permissions to do so or not. Write yes or no in /tmp/optexec
Eg: yes

ANS:

$ sudo su

# touch /tmp/optexec

# echo "yes" >> /tmp/optexec


18. CreatePartition_FstabEntry_Ex1
You have been asked to install and configure an application. For future reference and better
performance it is always good to have a separate partition for the application logs.

Create a 1GB logical partition on the free space available in the disk. Apply ext4 filesystem and
mount it on the mount point /part1.

To make this newly created partition available on every system reboot do the following.

Find the uuid of the newly created logical partition and make an fstab entry with the following
details.

Mount point = /part1, Mount options = defaults, filesystem = ext4, Dump option = 0, fsck
option = 1

NOTE:::Take a backup of /etc/fstab file before editing.

WARNING:: Please be careful in not modifying other entries. Your System may become
unbootable.

ANS:

$ sudo su

# fdisk –l

# fdisk /dev/nvme0n1

:m

:n

:l

First sector: press enter

Last sector: +1G

:p
:w

# partprobe

# mkfs.ext4 /dev/nvme0n1p5

# mkdir /part1

# mount /dev/nvme0n1p5 /part1

# blkid

(Note down UUID)

# vi /etc/fstab

Press i

Paste here : UUID:----------- /part1 ext4 defaults 01

Press esc

Press Shift + :

: wq

************Evaluate************

19. Disabling_ScientificLinux-repository_EX2
List out all the repositories and disable ScientificLinux repository.

ANS:

$ sudo su

# cd /etc /yum.repos.d/

# yum repolist all

# yum-config-manager --disable ScientificLinux

20. Enabling_OracleLinux-repository_InstallationUsing_YUM_EX3
Tom is in need of wget and zip packages from the OracleLinux repository.
Your task: Make sure OracleLinux repository is enabled with GPG Signature Verification.

Then install the following Packages using the yum command.

1.wget

2.zip

ANS:

$ sudo su

# cd /etc/yum.repos.d/

# ls

( OracleLinux.repo ScientificLinux.repo )

# vi OracleLinux.repo

Press i

Edit this parameter:

Enable=1

Disable=1

Press esc

Press shift + :

:wq

# yum install wget

# yum install zip

***************Evaluate************

21. Package_Installation_Using_RPM_Command_EX2
Tom has emailed a software package to you which is in .zip format. In order to install the package,
first of all you need the “unzip” command line utility. At the same time, you have found that the
tcpdump utility that exists on the server is serving absolutely no purpose at all. Therefore your task is
to...

1. Install the following package using the rpm command, the package is available in the
/opt/Software Directory.

unzip-6.0-20.el7.x86_64.rpm

2. Uninstall the following package using the rpm command

Tcpdump
ANS:

$ sudo su

# cd /opt/Software

# rpm -ivh unzip-6.0-20.el7.x86_64.rpm

# rpm -e tcpdump

22.Creating_Repository_Updating_and_Installing_Packages_EX1
A while ago, one of our server users had raised a request for a software package. While
trying to install the package you received the error that the package is not found in any of the
currently configured yum repositories. You did a quick search online and found that this
particular package is available in the Centos repository. Therefore your task is to ...

1. Create a software repository file "/etc/yum.repos.d/centos.repo"

Configure the repository with the following parameters

1. Repo-id = "centos"

2. Repo-baseurl = "http://mirror.centos.org/centos-7/7/os/x86_64/"

3. enable GPG signatures verification.

Hint: Sample repository file example.repo is available in "/opt/Software/" directory.

2. Using the centos repository perform the following activities.


1. Update centos-release package to the latest version

2. Install centos-bookmarks and centos-indexhtml packages.

ANS:
$ sudo su
# touch /etc/yum.repos.d/centos.repo
# cd /etc/yum.repos.d
# vi centos.repo
Press i insert :-
[centos]
baseurl=http://mirror.centos.org/centos-7/7/os/x86_64/ (copy from queue)
enabled=1
gpgcheck=1
press esc
press shift + :
:wq
# yum update centos-release
# yum install centos-bookmarks
# yum install centos-indexhtml
*************evaluate**********

23. FindSetTarget_Ex1
You need to test a GUI application and submit the report for now.
Find the current runlevel target and set the target level, which includes graphical mode.

Do not change the default target.

ANS:

$ sudo systemctl isolate graphical.target


24. ntpd_Ex1
Install ntpd package if not installed, using "yum install ntpd" command and start
the ntpd service and make sure it starts on every system boot.

ANS:

$ sudo su

# yum install ntp

# systemctl start ntpd

# systemctl enable ntpd

********Evaluate*******

25. stopUnwantedServices_Ex2
While performing the usual daily system health check, you have noticed that the server is
slightly under performing.

Based on the data you have collected, you have arrived at the conclusion that a few running
services aren't really necessary and stopping them will certainly free up RAM space and
perhaps improve server performance.

Your task: Stop the unwanted running services

rpcbind, avahi-daemon, iscsi, HelloWorld-Python.service and HelloWorld-PHP.service on


server and make sure the same services are not started automatically on system boot.

ANS:

$ sudo systemctl disable rpcbind.service avahi-daemon.service iscsi.service HelloWorld-


Python.service HelloWorld-PHP.service (copy from queue)

$ sudo systemctl stop rpcbind.service avahi-daemon.service iscsi.service HelloWorld-


Python.service HelloWorld-PHP.service (copy from queue)
******Evaluate******

26. IpAllocation_Ex1
A web server has to be configured. The web service should be mapped with the same IP
always.
Your task:
Find the network address allocation method of the server and store the allocation method in
a file with the name "/tmp/nwfile".

Eg. For manual allocation store the value as "static", For automatic allocation store the value
as "dhcp".

ANS:

$ sudo su

# cd /tmp

# echo "dhcp" > nwfile

27. SetHostname_Ex2
Your request for a new high capacity server has finally been granted. You are thrilled ! The
brand new server has come pre-installed with the Linux operating system and will be utilized
by developers.
Set the host home of the system as "devpc".

ANS:

$ sudo hostnamectl set-hostname devpc


28. etchosts_Ex1
Update /etc/hosts with current IP of the system, mapped with hostname "devpc" and
domainname "devpc.masterone.com".

ANS:

$ sudo su

# ifconfig (Note Down IP Address)

# cd /etc/

# vi hosts

Press i

Enter IP Address(255.255.0.0) devpc devpc.masterone.com

Press esc

Press shift + :

:wq

*************Evaluate**********

29. settimezone_Ex2
Since the users of the server are all located in France, it obviously makes sense to set the
server’s timezone to Europe/Paris.

Update the system timezone to Europe/Paris.

ANS:

$ sudo timedatectl set-timezone Europe/Paris


30. firewallOpenPorts_Ex1
The webserver ports have now been configured to run on the ports 8080 and 9443. You
need to allow all incoming traffic to these ports through the firewall.

Configure the firewall to allow ports 8080, 9443 in the "public" zone. Make this change
permanent.

ANS:

# firewall-cmd --permanent --add-port=9443/tcp --zone=public

Success

# firewall-cmd --permanent --add-port=8080/tcp --zone=public

success

31. Installing_Creating_Mounting_NFS_Share_EX1
Getting a brand new server is great. You get to have all the fun setting up and configuring it
from the very bottom up. In the last exercise you had configured a few network related
settings. And now you are ready to setup the server services one after another. After a bit of
thinking you have decided to begin by configuring the NFS server. Your task is to .....

Install the NFS-Server packages


PackageName = nfs-utils

Create a directory "/nfsshare" and provide full access to everyone and share it to any
network.

Make the service available after every system reboot.

Imagine that the Server host and the Client host are in the same system.

Perform following activities.

1. Create a directory "/nfsmount" in the client host.

2. Install NFS Client Package (PackageName=nfs-utils)

3. Mount the NFS-Share "/nfsshare" on "/nfsmount" directory (MountPoint) in the client host.

ANS:

$ sudo su

# yum install nfs-utils

# mkdir /nfsshare

# chmod 777 /nfsshare

# mkdir /nfsmount

# echo /nfsshare > /etc/exports

# systemctl start nfs

#ifconfig (note down IP address)

# mount -t nfs 192.168.7.109:/nfsshare /nfsmount

*******Evaluate********

32. Create_NFS_Share_With_Options_EX1
You need to enhance the NFS services, Share the directory "/nfssecure" to all available
networks with the following options.
1. Everyone should have only read and execute permissions on /nfssecure Directory.
2. Deny Write Access (readonly)
3. Enable Synchronous writes (sync)
4. Protect root access by configuring the ownership of all root-created files to nfsnobody
(root_squash).

ANS:
$ sudo su

# yum install nfs-utils

# mkdir /nfssecure

# echo "/nfssecure *(ro,sync,root_squash)" > /etc/exports

# systemctl start nfs

# chmod o+rx /nfssecure

******Evaluate*****

33. NameResolve_Ex2
Find the IP of www.teknoturf.com write the IP in /tmp/tekno.

ANS:

$ sudo su

# host www.teknoturf.com

(Note down IP address)

# touch /tmp/tekno

# cat > /tmp/tekno

Enter IP address

Press Ctl + c

****Evaluate***
34. InstallAndConfigureDNS_Ex1
You are a seasoned System Administrator and therefore well aware of the benefits of
running a DNS server on-premise. Being able to access all the network resources by their
device names rather than having to remember their individual IP addresses is worth every
ounce of your effort, be it for resources such as shared storage, LCD projectors, printers or
anything else. Therefore your task is to...

Install the DNS package (bind, bind-utils).

Enable and start the DNS service.

Now that the DNS service has been enabled, you may proceed to configure the DNS files.

Configure the DNS as per the given details.

DNS name: <host>.dnslabs.com

Update zone details in : /etc/named.conf

Forward zone file name: forward-dnslabs.com

Reverse zone file name: reverse-dnslabs.com

Zone file location: /var/named

Hint :: Use the /opt/Software/sample.config if required.

Update DNS server details in the DNS client running in the same system and make sure the
DNS server name www.dnslabs.com is resolvable from the client

####Important Note: Take a backup of the configuration file before editing


#### Hint: The DNS server configured is running in the same system, find the IP of the DNS
Server is bound to and configure that.

ANS:

35. installhttpd_DefaultPageEx1
So far the new server is handling all the tasks with ease. The performance reports you had
gathered earlier clearly indicates that the server is capable of handling a lot more tasks
without any trouble. In order to utilize the server to its fullest you have been asked to host
the corporate Website on the same server. Therefore your current task is to....

Install the Webserver Package (httpd)

From the Client host or from the Server, make sure the webserver is browsable - default
page

ANS:

$ sudo su

# yum install httpd

# systemctl start httpd.service

# systemctl enable httpd.service

*******Evaluate******

36. CheckDefaultPage8080_Ex1
Other than port 80, Configure the webserver to listen on port 8080 additionally.

ANS:

$ sudo su

# yum install httpd

# sudo vim /etc/httpd/conf/httpd.conf

Press i

Go to line where Listen 80

Change it to Listen 8080

Press esc
Press shift + :

:wq

# systemctl restart httpd.service

********Evaluate*******

37. Virtualhost_Ex1
Hosting several websites on the very same web server makes efficient use of the server
doesn’t it? Thus you have decided to host the corporate sales website also on the very same
server as a Virtualhost.
If the webserver is configured to listen on other ports, leave the configuration intact and
additionally configure the web server with the following:
Create a vhost.conf file with following details::
servername - www.mywebhost.com, Port - 8888, Document root -
/var/www/webserver/www, Error and access log path - /var/www/webserver/logs and when
the webserver is browsed, index.html should be created in document root with content "My
Web Server!!!". Make the web service start automatically on system reboot

Eg:vhost.conf
<VirtualHost *:8888>
DocumentRoot <Substitute Document root path here>
ServerName < Substitute servername here>
ServerAlias < Substitute any alias here>
ErrorLog < Substitute Errorlog filepath here>
</VirtualHost>

###Important Note: DNS name resolving is to be taken care. Use the DNS if configured or
use /etc/hosts for name resolving.
###Important Note: Remember DocumentRoot directory should be present and should have
necessary permissions

ANS:

38.Vsftpd_Install_Manage_Share_Ex1
The FTP server that was in use earlier has now been decommissioned since the new server
arrived. When it comes to file sharing, our users are highly dependent on the FTP server.
Therefore it is about time we get the FTP service up and running on the new server before
our users begin to complain. Thus your task is to ...

Install the FTP Package (vsftpd).

Start the vsftpd service and make the service start automatically on system reboot.

Now that you have started the FTP service, you need to determine whether file transfer is
working properly. To do so you may configure the FTP server to permit anonymous logins. So
now your task is to...
Create a directory named "ftpshare" in the FTP default location (/var/ftp/pub) and make it
accessible for anonymous users (downloading files).

Check by using: ftp localhost, username: anonymous, no password required

ANS:

$ sudo su

# yum install vsftpd –y

# systemctl start vsftpd.service

# systemctl enable vsftpd.service

# mkdir /var/ftp/pub/ftpshare

*******Evaluate*****

39. CongfigureFTPServerClient_Ex1
1. Install and configure the FTP server with the following:

- Create a user named "ftpcltuser" with user home directory as "/var/ftp/ftpclient" and set the
password as "changeit".

- Create a file "/var/ftp/ftpclient/downfile" as root user and grant read access to other users
in the system.

- Make the FTP service start automatically on system reboot.

- Deny anonymous access and allow only "ftpcltuser" to access the server.

2. Consider your working in a FTP client system. Login as "devuser" or su as "devuser" and
create a file named "upfile" in the user home directory.

Note:Password for "devuser" is same as username. For transferring files use "put" or "mput"
command.

Establish FTP connection as "ftpcltuser" and do the following. Upload the "upfile" to
"/var/ftp/ftpclient" directory and download the file "/var/ftp/ftpclient/downfile" to "devuser"
home directory.

ANS:

40. TaskUsingAt_Ex1
Tom would like to run a particular task at precisely 2 minutes from the time he deems
appropriate. But he want to be 100% certain that the job really does run exactly 2 minutes
from the time he schedules it. In order to convince Tom, you can...
Create a user "atuser" and as "atuser", schedule a task 2 Minutes from now using "at"
command. The task should write today's date to a file "/tmp/myjob"?
The expected output format in a file is dd/mm/yyyy. Eg. 15/01/2020

Note: Please expect a 90 seconds delay in getting response for evaluation.

ANS:

$ sudo su

# useradd atuser

# echo "atuser" >> /etc/at.allow

# su – atuser

$ at now +2 minutes

at> echo "23/06/2021" > /tmp/myjob (Put current date)

at> <EOT> (ctrl + d)

$ cat /tmp/myjob

23/06/2021

******Evalute******

41. CronServiceStatus_Ex2
Determine the status of the service related to scheduling. Store the status in a file
(/tmp/service).

Eg. If the service is running, store the value as active. If the service is not running, store the
value as inactive.

ANS:

$ sudo su

# systemctl status atd

# systemctl status crond

# echo "active" > /tmp/service


42. RestrictUsers_Ex1
If anyone and everybody is allowed to schedule and run jobs whenever they please, it could
at times turn out to be a risky affair. Thus it is better to be wise and allow only certain users
to schedule and run jobs on the server.

Create a user named "jobuser" and allow only "jobuser" to execute "at" jobs?

ANS:

$ sudo su

# useradd jobuser

# echo "jobuser" > /etc/at.allow


43. CronTasks_Ex1
Pre-requirement: Create a user "cuser" and schedule the task.
Note: Use double digits on all cron timestamps and all characters in lower case. Eg. 1 as 01,
Mon as mon.
- Schedule a task using "echo" command that writes "backup started" message to a file
"/tmp/decbackup" on 31st dec at 11.55pm of every year .

ANS:

$ sudo su

# useradd cuser

# echo "cuser" >> /etc/cron.allow

# su – cuser

$ crontab -l | { cat; echo '55 23 31 12 * /bin/echo "backup started" > /tmp/decbackup'; } | crontab –

*******Evaluate*******

44. DenyCronUser_Ex4
Pre-requirement: Create an user named "cuser".
- Deny the user from executing cron jobs.

ANS:

$ sudo su

# useradd cuser

# echo "cuser" > /etc/cron.deny


45. allocatedSwap_Ex1
What is the allocated swap size in the server in MB. Write your output in /tmp/swapalloc.
Sample file:
1024

ANS:

$ sudo su

# touch /tmp/swapalloc

# cat /tmp/swapalloc

# cat > /tmp/swapalloc

Enter : 0

Press ctrl + c

*******Evaluate*******

46. Swapfile_Ex1
Although our brand new server has tons of RAM, it is still advisable to allocate swap space.
One of the most compelling reason to do so is the fact that the kernel will swap out memory
pages that are rarely used into swap space to ensure that RAM space is made available for
more frequently used memory pages.
Create a file for swap with the name 'swapfile' under / with the size 100MB. Add the swapfile
to existing system swap and make the necessary changes to load the swapfile every-time
the system boots
Hint::dd if=/dev/zero of=/swapfile count=100 bs=1MiB

ANS:

$ sudo dd if=/dev/zero of=/swapfile count=100 bs=1MiB (Copy from queuq)

$ sudo touch /swapfile


$ sudo mkswap /swapfile

$ sudo vi /etc/fstab

Press i

/swapfile swap swap defaults 00

Press ecs

Press shift + :

:wq

$ sudo swapon /swapfile

*******Evaluate********

47. CreateAndResizeLv_Ex1
You are creating a separate partition for a development project. The data size of the project
might grow in future. So you have thought of leveraging the benefits of LVM. As per your
plan you have to:

 Create a logical partition with partition id 7 of size 2 GB, and make it as physical volume.
Allocate it to volume group "datavg".
 Create a 1GB logical volume "LabsLv01" on the volume group datavg.
 Format LabsLv01 with ext4 file system.
 Mount the logical volume on /datalv.
 Copy the contents from /usr/include directory to /datalv/include.

If the above is created, Increase the /datalv by 500MB without any data loss. Make the
mount point permanent on system reboot

ANS:

$ sudo su

# fdisk –l

# fdisk /dev/nvme0n1

:n

:l

First sector : press enter

Last sector : +2G

:t
: press enter

Hex code : 8E

:p

:w

# partprobe

# vgcreate datavg /dev/nvme0n1p5

# lvcreate -n LabsLv01 -L 1GB datavg

# mkdir /datalv

# mkfs.ext4 /dev/datavg/LabsLv01

# mount /dev/datavg/LabsLv01 /datalv

# cp -r /usr/include /datalv/include

# lvextend --size +500MB /dev/datavg/LabsLv01

# resize2fs /dev/datavg/LabsLv01

********Evaluate********

48. chmod_dirs_Ex1
A new employee called John has joined the development team. Therefore Tom has sent you
an email requesting you to ....
Create a user account for john. Then login as john and create a "data" directory within his
home directory.
Create directories dir1 dir2 dir3 inside the data directory
Change the permissions of all the directories inside the data directory as drwxrwxr-x

ANS:

$ sudo su

# useradd john

# su – john

$ mkdir data

$ cd data

$ mkdir dir1 dir2 dir3

$ chmod 775 /home/john/data/*


49. chmod_files_Ex2
Create a user john if not created.
Login as john and create a directory "data" in his home directory.
Create five files namely 1 2 3 4 5 inside data directory
Change the permissions of all files as -rw-rw-r--

ANS:

$ sudo su

# useradd john

# su - john

$ mkdir data

$ cd data

$ touch 1 2 3 4 5

$ chmod g+w,o=r /home/john/data/*


50. chgrp-chown_Ex3
John has generated some data that’s meant specifically for the Sales team. You have been
instructed to segregate this data and store them into specific directories as outlined below.
Alex belongs to the sales team. The above data is to be copied from john’s home directory
and into Alex’s home directory so that Alex can utilize the data for marketing purposes.
Perform the task as "root" user.
Prerequisite:: if not already done so, as root create a user named john.
Login as john and create a directory "data" in his home directory.
Create five files namely 1 2 3 4 5 inside data directory
Create directories dir1 dir2 dir3 inside data directory
Change the permissions of all dirs inside data directory as drwxr-x---
Change the permissions of all files inside data directory as -rw-r-----
----------------------

Question::
Perform the task as root user
Create a user named alex with primary group as sales.
As an administrator, you have been asked to copy the "data" directory created in john's
home directory to alex's home directory.
Change the owner and group of the data directory as alex and his primary group.

ANS:

$ sudo su

# useradd john

# su - john

$ mkdir data
$ cd data/

$ touch {1..5}

$ chmod 640 {1..5}

$ mkdir dir{1..3}

$ chmod 70 dir*

$ exit

Logout

# groupadd sales

# useradd -g sales alex

# cp -r /home/john/data /home/alex/

# chown -R alex:sales /home/alex/data/

51. acl_File_Ex1
You have come to understand that applying ACL permissions to files and directories allows
for a much more fine grained access control when compared to the more commonly used
Posix permissions. Therefore you wish to test it and find out how it works.
Create a file named "aclfile" in /opt/AclLab directory with the following content "This file is for
ACL testing".
Create acl users - acl01, acl02, acl03, acl04, acl05.
Grant rw- access to acl01, acl03 users on aclfile
Deny access to acl02 user on aclfile
Click the Evaluate button after completion.

ANS:

$ sudo su

# mkdir /opt/AclLab

# echo "This file is for ACL testing" > /opt/AclLab/aclfile

# useradd acl01

# useradd acl02

# useradd acl03

# useradd acl04

# useradd acl05

# setfacl -m u:acl01:rw /opt/AclLab/aclfile

# setfacl -m u:acl03:rw /opt/AclLab/aclfile

# setfacl -m u:acl02:000 /opt/AclLab/aclfile

52. chmod-chgrp-acl_Ex1
Create users "tl01, tl02" with the primary group as "teamlead".
Create a directory "/opt/AclLab/privateinfo" with the following characteristics.
The owner of the directory as "root" and groupownership as "teamlead" group.
The directory should have full permission to all members of "teamlead" group, but not to
any other users except "root".
Create a file named "/opt/AclLab/privateinfo/projectdetails", this files should inherit ACL
entries (u:rwx g:rwx o:---) from the parent directory (privateinfo).

ANS:

$ sudo su

# groupadd teamlead

# useradd -g teamlead tl01

# useradd -g teamlead tl02

# mkdir /opt/AclLab/

# mkdir /opt/AclLab/privateinfo

# chown root:teamlead /opt/AclLab/privateinfo

# chmod 770 /opt/AclLab/privateinfo

# setfacl -dm u::rwx,g::rwx,o::--- /opt/AclLab/privateinfo/

# touch /opt/AclLab/privateinfo/projectdetails

******Evaluate***

You might also like