Professional Documents
Culture Documents
Linux Hands On Solution
Linux Hands On Solution
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:
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:
ANS:
$ 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:
5.Findandsetpermission_Ex1
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}
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:
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:
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:
ANS:
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:
New 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:
(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:
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
4194304
# touch /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
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
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
:p
:w
# partprobe
# mkfs.ext4 /dev/nvme0n1p5
# mkdir /part1
# blkid
# vi /etc/fstab
Press i
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/
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.
1.wget
2.zip
ANS:
$ sudo su
# cd /etc/yum.repos.d/
# ls
( OracleLinux.repo ScientificLinux.repo )
# vi OracleLinux.repo
Press i
Enable=1
Disable=1
Press esc
Press shift + :
:wq
***************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
Tcpdump
ANS:
$ sudo su
# cd /opt/Software
# 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. Repo-id = "centos"
2. Repo-baseurl = "http://mirror.centos.org/centos-7/7/os/x86_64/"
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.
ANS:
ANS:
$ sudo su
********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.
ANS:
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
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:
ANS:
$ sudo su
# cd /etc/
# vi hosts
Press i
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.
ANS:
Configure the firewall to allow ports 8080, 9443 in the "public" zone. Make this change
permanent.
ANS:
Success
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 .....
Create a directory "/nfsshare" and provide full access to everyone and share it to any
network.
Imagine that the Server host and the Client host are in the same system.
3. Mount the NFS-Share "/nfsshare" on "/nfsmount" directory (MountPoint) in the client host.
ANS:
$ sudo su
# mkdir /nfsshare
# mkdir /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
# mkdir /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
# touch /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...
Now that the DNS service has been enabled, you may proceed to configure the DNS files.
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
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....
From the Client host or from the Server, make sure the webserver is browsable - default
page
ANS:
$ sudo su
*******Evaluate******
36. CheckDefaultPage8080_Ex1
Other than port 80, Configure the webserver to listen on port 8080 additionally.
ANS:
$ sudo su
Press i
Press esc
Press shift + :
:wq
********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 ...
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).
ANS:
$ sudo su
# 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.
- 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
ANS:
$ sudo su
# useradd atuser
# su – atuser
$ at now +2 minutes
$ 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
Create a user named "jobuser" and allow only "jobuser" to execute "at" jobs?
ANS:
$ sudo su
# useradd jobuser
ANS:
$ sudo su
# useradd cuser
# 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
ANS:
$ sudo su
# touch /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 vi /etc/fstab
Press i
Press ecs
Press shift + :
:wq
*******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
:t
: press enter
Hex code : 8E
:p
:w
# partprobe
# mkdir /datalv
# mkfs.ext4 /dev/datavg/LabsLv01
# cp -r /usr/include /datalv/include
# 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
ANS:
$ sudo su
# useradd john
# su - john
$ mkdir data
$ cd data
$ touch 1 2 3 4 5
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}
$ mkdir dir{1..3}
$ chmod 70 dir*
$ exit
Logout
# groupadd sales
# cp -r /home/john/data /home/alex/
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
# useradd acl01
# useradd acl02
# useradd acl03
# useradd acl04
# useradd acl05
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
# mkdir /opt/AclLab/
# mkdir /opt/AclLab/privateinfo
# touch /opt/AclLab/privateinfo/projectdetails
******Evaluate***