Ramniranjan Jhunjhunwala College (Autonomous) : Certificate
Ramniranjan Jhunjhunwala College (Autonomous) : Certificate
Ramniranjan Jhunjhunwala College (Autonomous) : Certificate
Certificate
This is to certify that Mr. Vimal Tiwari ,Roll No:50 of TY B.Sc. (I.T.) class has completed the
required number of experiments in the subject of Linux System Administration in the
Department of Information Technology during the academic year 2020-2021.
No Practical Remark
1 Installation of RHEL 6.X
1
a Using Query Options
(i) Various query options on RPM command
b Connecting to the Network
9 Web Server
a Configuring Apache on Red Hat Enterprise Linux
b Writing a Script to Monitor Activity on the Apache Web Server
c Using the select Command
Write a simple script that asks the user to enter the name of an RPM or
fi le that
the user wants to query. Write the script to present a menu that
provides different options that allow the user to do queries on the
RPM database
The following options must be presented:
a. Find the RPM from which this file originates.
b. Check that the RPM where the user has provided the name is
installed.
c. Install this RPM.
2
d. Remove this RPM.
10 Shell script
a Writing Shell Scripts
(All Shell programs )
b Configuring Booting with GRUB
3
Practical 1:Installation of RHEL 6.X
3. After clicking on the new virtual machine “Select Typical(recommended)” > Click on Next.
4. After that check the radio button “Select Installer disk image file” and browse the disk file and
After click on I will install the operating system later option > Click on Next.
5. After that select Guest operating system for that click on “Linux” option. > select the version of
Linux that is “Red Hat Enterprise Linux 6 64-bit” > Click on Next.
6. After that Give name to your virtual machine in “Virtual machine name” as TYIT_Liux and set the
Location or you can use Default Location which is theirs > Click on Next.
7. After that Specify Disk Capacity 20.0 GB in which choose the option as “Split virtual disk into
multiple files” > Click on Next.
12. After that click on the Skip button > Click On Next.
13. After that choose the language as English > click on Next.
14. Select the appropriate Keyboard option as U.S. English > click on Next.
15. Select what type of devices will your installation involve? In that you choose Basic Storage
Device option and click next.
4
17. Now here we assign our Hostname change the hostname as you desire or let it be as
localhost.localdomain > click on Next.
19. Enter the root Password > Click on Next > And click on Use Any way.
20. After that select “Create Custom Layout” option > Click on Next
21. (After create a disk partition) After Clicking On Create Custom Layout Option “Please select a
device” window open > Click On Create Button > Create storage window open > Click on radio button
Standard Partition > Click on create button > Add a partition.
1. /(root)Ext4 10000 MB
2. /swap 4000 MB
3. /boot Ext4 2000 MB
4. After that click on Next.And Format Button.
5. After that Click on “Write Changes to disk”.
23. After click on Next > Choose two option from one part choose “Desktop” and for another part
click on Customize Now option > click on Next.
28. Select the option “Yes,I agree to the Licence Agreement” > Click on Forward button.
30. Click on the Forward button > And fill the username and password
31. Set date and time > click on the Forward button.
5
32. Click on the Finish button.
6
Practical 2 Graphical User Interface and Command Line Interface and Processes
1. Use man and man -k to find out how to change the current date on your computer.
.
[root@server Desktop]# cd //Change the directory.
[root@server ~]# man -k time | grep 8 //This gives a command list. Use date command to change
the current date of the computer.
2. Create a directory with the name /tempdir. Copy all files from the /etc directory that start
with an a, b, or c to this directory.
[root@loacalhost ~]# cp /etc/[ijk]* /tempdir/ //This Command Copy all files from the /etc directory that
start with an i, j, or k to this directory.
cp
[root@loacalhost ~]# ls /tempdir //give the list of files of temdir directory.
3. Find out which command and which specific options you will need to show a time sorted
list of the contents of the directory /etc.
[root@loacalhost ~]# ls -t/ etc //sorts the file by modification time, showing the last edited file
first.
4. Find all files on your server that have a size greater than 100 MB
[root@loacalhost ~]# find / size +100M //Find all files on your server that have a size greater than
100 MB
7
Practical 2(b): Managing Processes.
1. Move a job that was started as a foreground job into the background.
Step 1: open a terminal, and from that terminal, start the system-config-users program.
Step 2: You will see that the terminal is now occupied by the graphical program you’ve just started and
that you cannot start any other programs.
Step 3: Click in the terminal where you started system-config-users, and use the Ctrl+Z key sequence.
This temporarily stops the graphical program and returns the prompt on your terminal.
^Z
[1]+ Stopped system-config-users
[root@loacalhost ~]#
Step 4: Use the bg command to move the job you started by entering the system-config-users
command to the background. You can now continue using the graphical user interface and, at the same
time, have access to the terminal where you can start other jobs by entering new commands.
[root@loacalhost ~]# bg
[1]+ system-config-users &
[root@loacalhost ~]#
Step 5: From the terminal window, type the jobs command. This shows a list of all jobs that are started
from this terminal. You should see just the system-config-users command. Every job has a unique
job number in the list displayed by the jobs command. If you have just one job, it will always be job
1.
Step 6: To put a background job back into the foreground, use the fg command. By default, this
command will put the last command you started in the background into the foreground. If you want to
put another background job into the foreground, use fg followed by the job number of the job you
want to manage; for instance,use fg 1.
[root@loacalhost ~]# fg
8
system-config-users
2. Start a few processes to make the parent-child relationship between these processes visible.
Then kill the parent process .
Step 1: Use the bash command to start Bash as a subshell in the current terminal window.
Step 2: Use ssh -X localhost to start ssh as a subshell in the Bash shell you just opened.When asked if
you want to permanently add localhost to the list of known hosts,enter yes. Next enter the password of
the user root.
Step 4: Type ps afx to show a listing of all current processes, including the parent-child relationship
between the commands you just entered.
One of the output lines shows the ssh -X localhost command you just entered. Note the PID that
you see in that output line.
Step 5: Use kill followed by the PID number you just found to close the ssh shell. Because the ssh
environment is the parent of the gedit command, killing ssh will also kill the gedit window.
Step 1: Type the command dd if=/dev/zero of=/dev/null &, and repeat this four times.
9
Step 2: Now start top. You’ll see the four dd commands listed at the top. In the PR column, you can see
that the priority of all of these processes is set to 20. The NI column, which shows the actual
process niceness, indicates a value of 0 for all of the dd processes, and, in the TIME column, you can
see that all of the processes use about the same amount of processor time.
Step 3: Now, from within the top interface, press r. On the PID to renice prompt, type the PID of one of
the four dd processes, and press Enter. When asked Renice PID 2826 to value, type 5, and press Enter.
Step 4: With the previous action, you lowered the priority of one of the dd commands. You should
immediately start seeing the result in top, because one of the dd processes will receive a
significantly lower amount of CPU time.
Step 5: Repeat the procedure to adjust the niceness of one of the other dd processes. Now use a
niceness value of -15. You will notice that this process now tends to consume all of the available
resources on your computer. Thus, you should avoid the extremes when working with nice.
PID to renice: 3642
Renice PID 2827 to value:-15
Step 6: Use the k command from the top interface to stop all processes where you adjusted the
niceness.
//press k enter the pid number
PID to kill: 3641 //press Enter than below msg will show again press enter to exit
msg - Kill PID 3641 with signal [15]:k
//Repeat the process to kill rest PID
PID to kill: 3642
PID to kill: 3643
PID to kill: 3644
10
4. Create a user account to run a cron job that sends an email message to user root on your
system
Step 1: The command su is used to execute commands with the privileges of another user account.
When executed it invokes a shell without changing the current working directory or the user
environment.
//this will help to edit the crontab than type i to enter edit mode insert bellow command after done
typing press esc and type :wq to exit crontab.
Step 3: After that login as root permission. Use mail command to send email.
11
Practical 3: Storage Devices and Links, Backup and Repository
Step 1: Before creating the partition we need to check the current partitions and file systems.
To view all existing disk partitions we use the ‘fdisk –l’ command.
fdisk command helps to create,view,resize,delete,change,copy and move partitions on a hard drive.
It allows creating four new primary partitions, and number of logical partitions(extended partitions)
based on the size of the hard disk by dividing from one of the primary partitions.
12
[root@loacalhost ~]# partx –a /dev/sda
Step 6: To check whether the 4th partition is successfully added use fdisk –l command
Step 7: Inform the Hard Disk about the file system of partition
Command to make the file system is #mkfs.ext4 /dev/sda4
Step 1: To unmount the created 4th partition i.e /dev/sda4 use “umount” command
13
[root@loacalhost ~]# umount /dev/sda4
[root@loacalhost ~]# df -h
Step 2: Create one physical volume /dev/sda5 and one volume group as tybscit-A then create one
logical
volume user1 and finally mount this volume to directory /user1.
Extend partition
A] Press ‘n’ for new partition
B] Press ‘e’ to extended partition
C] Press ‘Enter’ on first and last sector
14
D] Press ‘p’ to print the partition
Step 3: Once you have completed all the steps reboot the system by using init 6 command
And print the partition table by using fdisk /dev/sda Command p
After this press ctrl+c
Create Physical Volume(pv),Volume Group(vg),Logical Volume(lv):
15
Create Volume group name of tybscit-A by using vgcreate command
To check your volume groups name,size and free space use vgs command
Create logical volume name of user1 with 2GB space from tybscit-A group by using lvcreate
command
[root@loacalhost mapper]# df -h
16
[root@loacalhost mapper]# umount /dev /mapper //tybscit--A-user1
3. Create a hard link as well as a symbolic link to a file to demonstrate the differences
Step 1: Create a hard link as well as a symbolic link to the file /etc/hosts, and you will see how both
behave differently.
Open a terminal and make sure you have root permissions.
Using the command ln –s /etc/hosts ~/symhosts. This creates a symbolic link with the name
symhosts in your home directory.
Step 2: Using the command ln /etc/hosts ~/hardhosts. This creates a hard link with the name hardhosts
in your home directory.
Step 3: Using the command ls –il /etc/hosts ~/symhosts ~/hardhosts .The option –I shows the inode
number.You can see the inode number is same for /etc/hosts and ~/hardhosts like all other properties
of a file.
Step 4: Use rm /etc/hosts.Try to read the contents of ~/symhosts and ~/hardhosts.You will see the
difference.
17
Step 5: Restore the original situation by recreating the /etc/hosts file.You can do that easily by making a
new hardlink using ln ~/hardhosts /etc/hosts
[root@loacalhost ~]# ln ~/hardhosts /etc/hosts
Create a repository for Yum and install httpd package using yum
Check the folder RHEL6 to see whether the packages have been copied properly by using ls
command
[root@localhost RHEL6]# ls
Go to /etc/yum/pluginconf.d directory
If error comes install createrepo using rpm and install all the dependency packages until no
dependency is found
Now the command for creating repository will work by changing the directory to pluginconf.d
The directory /etc/yum.repos.d/ contains two .repo files which should be removed or moved to
other directory,so that YUM server will check default.repo file it self.If you don’t move or remove
the default .repo files from /etc/yum.repos.d/ folder then every time when you try to install
packages through YUM,your yum will check all these files for repositories for getting packages
which will or will not work and most probably delay is increased in getting those packages from
online servers.
[rhel]
name=rhel6
baseurl=file:///RHEL6/Packages
[root@localhost yum.repos.d]# cd
[root@localhost ~]# yum clean all
19
[root@localhost ~]# cd/etc/yum.repos.d/
[root@localhost yum.repos.d] yum search firefox
As the httpd package is already install therefore the package is not been installed.You can try with
20
nmap package
21
Practical 4:Working with RPMsm Storage and Networking
Step 13: How to Query a file that belongs to the RPM Package.
Using -qf option with file name.
24
Practical 4(b):Connecting to Network
[root@server Desktop]# cd
[root@server ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=linux
[root@linux Desktop]# cd
[root@linux ~]# ifconfig
DEVICE=eth0
HWADDR=00:0c:29:fc:9c:27
NM_CONTROLLED=yes
ONBOOT=yes
DNS1=192.168.205.128
IPADDR=192.168.1.3
BOOTPROTO=none
NETMASK=255.255.255.0
TYPE=Ethernet
IPV6INIT=no
USERCTL=no
25
Practical 5:Working with Users, Groups, and Permissions
1.We create a user account “linda” to grant her the privilege of super user.
[root@localhost~]# vi /etc/sudoers
[root@localhost~]# visudo
4.Test the configuration by making “jay to login and perform any administrative activity as shown below:
D. Administrative Commands
1. Useradd
[root@localhost ~]# useradd -c “This is Jisha’s account” -u 601 -o -s /sbin/bash jisha
#cat /etc/passwd
2.chage
3.passwd
4.chsh
chsh command is used to change the shell of user:
5.groupadd
27
groupadd command is used to create a new group and gpasswd command to add members and
administrators in the group.
6.userdel
userdel command is used to delete the user.
[root@localhost~]# userdel shreya
You can check in /etc/passwd file, the user named ‘shreya’, no longer exists
7.groupdel
8.newusers
4. Verifying entry in the password file that users are created or not.
28
#cat /etc/passwd
9. Chattr
[root@localhost ~]# cd ..
[root@localhost /]# pwd
/
[root@localhost /]# cd /home/
[root@localhost home]#pwd
/home
[root@localhost home]#
30
Allow all incoming ssh connection.
[root@server ~]# iptables -A INPUT -i eth0 -p tcp --dport 22 -m --state NEW,ESTABLISH -j ACCEPT
[root@server ~]# iptables -A INPUT -A OUTPUT -p tcp -d 192.168.1.3 --sport ssh -j ACCEPT
Allowing outgoing ssh connection which is established for incoming ssh connection request, once
the incoming connection is allow we also need to allow response back for that incoming ssh
connection
[root@server ~]# iptables -A OUTPUT -o eth0 -p tcp --sports 22 -m state --state NEW,ESTABLISH -j
ACCEPT
(i)Creating and exchanging gpg key for encrypting and decrypting file
Step 1: Login as root permission and add two user first “linda” nd second “lisa”
[root@localhost Desktop]# cd
[root@localhost ~]# useradd linda
[root@localhost ~]# passwd linda
31
Step 2: Login into linda account and generate gpg key
[linda@server Desktop]$ cd
[linda@server ~]$ gpg --gen - key
[lisa@server Desktop]$ cd
[lisa@server ~]$ gpg --gen - key
[linda@localhost Desktop]$ cd
[linda@localhost ~]$ gpg --list- key
32
Practical 7: Configuring Server for File Sharing
Step 3: Make a directory to be exported,create few files into it and give full permission.
33
Step 4: Open the configuration file of NFS,i.e, /etc/exports .
Step 7: stop the Firewall and check the status wheather it is stopped.
Step 8: Showmount command shows you all shared directions in given IP address.
[root@server servernfs]# ls
Step 13: As NFS Client make a directory /clientnfs and mount the server exported directory on it.
Step 14: To unmount the file from the client machine, use the unmount command.
● Samba is basically used for establishing connection among linux to windows, with help of samba
file sharing can be done using Windows file-sharing protocol and connect your Red Hat
Enterprise network to a windows network to share files and printers.
● Windows use a protocol called Server Message Block (SMB) to communicate with each other and
to share services such as file and print sharing.
● With Samba, the Linux PC icon appears in the Windows Network Places window and the files on
the Linux PC can be browsed using Windows Explorer.
● The Windows File system can be mounted on your Linux System , and you can browse
theWindows files from your Linux PC. Before using Samba to connect to the Windows computers,
it must first be installed on the Linux PC.
● All current distributions of Linux include three Samba packages:
- Samba
- Samba-client
- Samba-common
Step 2: Create a directory /data on the Linux file system on the Samba server.
Step 4: Set directory with the samba_share_t type, if you want to treat the files as samba share data
Step 5: Create a Samba user account that has access to the share.
And make the following changes by going to end of the file->Press Esc->:$
1. System->Administration->firewall
2. Press close and disable
3. Click on apply and yes
Step 11: Go to windows and Run command Type ping 192.168.214.128 >click on ok.
Step 1: Verify the package vsftpd for FTP. If installed, create few files in the pub. it is shown below.
This command returns the version of vsftpd.If package vsftpd is not installed then install using
following command.
#rpm – ivh vsftpd*
#rpm –ivh ftp*
Step 2: Check whether the package is install or not with #rpm –qa | grep ftp command
Step 3: Now use the following command to start vsftpd services at boot time using chkconfig command.
38
Use ctrl+d to save and exit
[root@server pub]# cd
[root@server ~]# ftp 192.168.21.129
Step 11: By default /var/ftp is ftp user Home directory. Check the context of file
/var/ftp/pub and change to ftp
Step 12: Create a file in the pub directory and create one file.
#cd /var/ftp/pub
#touch T1 T2 T3
#cat > ftptest
Welcome to ftp server
To save the document use ctrl+d
Step 13: Restart the service of vsftpd and enable it from root
Also give full permission to the directory /var/ftp/pub. service vsftpd start
#service vsftpd restart
#chkconfig vsftpd on
#chkconfig –list | grep vsftpd
Step 14: Now FTP is configure.Test as FTP client from another machine. Use the following command.
#ftp:192.168.21.129/pub/
40
Practical 8: DNS, DHCP and Mail Server
Name address resolution is simply the conversion of people friendly names into computer friendly
numbers.
● It means that every interface on the network has a unique group of numbers
called as IP address.
● These groups of numbers are present to the computers in the network but it is difficult for the
users to by heart, learn or remember them.
● DNS makes it possible for the users to enter the names and then these names get converted into
numbers.
● The main function of name address resolution is to create an efficient user and computer
interaction.
● For this name address resolution there is a need for how to install and configure the Domain
Name System.
● To understand, take a look at the domain and understand its working. For eg. example.com.
41
● In the above eg: The first part of the domain name is the name of the company or institution or
an organization. The next part after the period/dot is called a top-level domain (TLD).
Also called as named.empty, used for the purpose of caching of reverse zone.
It is found in /var/named/
The 2 additional files required for the master domain server are:
(i) zone – This file contains the names and addresses of hosts in the local domain and maps names
to the IP address.
(ii) reverse.zone – This file provides information to map ip-address to names Hence reverse.
DNS Configuration:
DEVICE=”eth0”
HWADDR=”00:0C:29:A6:A0:E9”
NM_CONTROLLED=”yes”
ONBOOT=”yes”
TYPE=Ethernet
DNS1=192.168.21.129
IPADDR=192.168.21.129
42
Step 3: #vim /etc/hosts
NETWORK=yes
HOSTNAME=server.tyit.com
# Generated by NetworkManager
search tyit.com
nameserver 192.168.21.129
#cd
Include “/etc/named.rfc1912.zones”;
44
Step 10: Go to named directory present in var
#cd /var/named
OR
We will configure a dhcp server and will lease ip addresses to clients. We are using two systems:
one linux server and one linux client. dhcp rpm is required to configure the dhcp server.
Step 1: First we have to check whether DHCP is available on our machine or not that we can check with
rpm command.
[root@server Packages]#setup
Step 5: DHCP server have a static a IP address.First configure the IP address 192.168.43.243 with
46
netmask255.255.255.0 on server.
Step 8: Select your LAN card(If you don’t see any LAN card here means you haven’t installed the driver)
Step 9: Select Use DHCP option and remove the[*] dhcpd option.
To remove [*]press Spacebar
Now Enter static IP Address
Static IP 192.168.43.252
Netmask 255.255.255.0
Step 10: Click on ok,Quit and again Quit to come back on root prompt.
Step 13: Open the configuration file dhcpd.conf which represents in /etc/dhcpd directory.
47
Step 16: The final output is that IP address which is given as a range.
#inet_intefaces = all
#inet_intefaces = $myhostname
#inet_intefaces = $myhostname, localhost
#inet_intefaces = localhost
[root@server Packages]# cd
[root@server ~]# mail [email protected]
Subject: to check mail through postfix
Hii lisa
EOT
49
Practical 9:Web Server
● When you view a web page over the Internet, the code to create that page must be retrieved from
a server somewhere on the Internet.
50
● The server that sends your web browser the code to display a web page is called a web server.
There are countless web servers all over the Internet serving countless websites to people all over
the world.
● Whether you need a web server to host a website on the Internet a Red Hat Enterprise Linux
server can function as a web server using the Apache HTTP server.
● The Apache HTTP server is a popular, open source server application that runs on many UNIX-
based systems as well as Microsoft Windows.
● Since we had created DNS named as server.tyit.com but on Linux browser it is showing unable to
connect because we need to configure apache web server , so that we can display out html page
on web browser with the help of our own DNS server.tyit.com
[root@localhost Desktop]# cd
[root@localhost ~]# rpm –qa | grep httpd
<html>
<head>Linux Apache Website</head>
<body>
Apache web server practical
</body>
</html>
[root@localhost named]# cd
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
You have done necessary configuration now restart the httpd service and test this configuration run
links command.
#service httpd restart
#chmod –R 777 /var/www/virtual/www.tyit.com/html/
Practical 9(b): Writing a Script to Monitor Activity on the Apache Web Server
[root@localhost Desktop]# cd
52
[root@localhost ~]# gedit test.sh
#!bin/bash
#Monitoring process httpd
COUNTER=0
While ps aux | grep httpd | grep -v grep > /dev/null
do
COUNTER=$((COUNTER+1))
sleep 1
echo COUNTER is $CONUTER
done
logger HTTPMONITOR: http stopped at ‘date’
service httpd start
mail -s Apache server just stopped root
Step 5 : After stopping httpd service the script will start the httpd service automatically
Practical 9(c): Using the select Command, Write a simple script that asks the user to enter
the name of an RPMor file that the user wants to query. Write the script to present a menu
that provides different
options that allow the user to do queries on the RPM database
The following options must be presented:
53
a. Find the RPM from which this file originates.
b. Check that the RPM where the user has provided the name is installed.
c. General info of this RPM.
d. Remove this RPM.
[root@server Desktop]# cd
[root@server ~]# vi smapel1.sh
#!bin/bash
echo Enter the name of RPM or file
read RPM
echo Select a task from menu
Select Task in ‘check from which RPM this file comes’ ‘check if this RPM installed’ ‘General info of this
RPM’ ‘Remove this RPM’
do
case $REPLY in
1) TASK =” rpm -q $RPM”;;
2) TASK= ” rpm -qa | grep $RPM”;;
3) TASK =” rpm -qi $RPM”;;
*) echo error&& exit 1;;
esac
if [-n TASK ]
then
clear
echo you have selected TASK
$TASK
else
echo invalid choice
fi
done
#? 3
error
[root@server ~]#
[root@server~]# vi operation.sh
#!bin/bash
echo “Enter the first number :”
read n1
echo “Enter the second number:”
read n2
echo “Enter the third number:”
read n3
sum =$(($n1 + $n2))
echo Addition is =$sum
product =$(($n1 * $n2))
echo Product is =$product
div =$(($n1 / $n2))
echo Division is =$div
ans=$(($n1 + $n2 -$n3))
echo Answer is =$ans
[root@server~]# vi days.sh
[root@server~]# vi no.sh
[root@server~]# vi file.sh
[root@server~]# vi str.sh
58
Step 2: write a code and save it.
[root@server~]# vi sum.sh
i=1
sum=0
while [ $i -le 10 ]
do
echo $i
sum=`expr $sum + $i`
i=`expr $i + 1`
done
echo The sum is: $sum
59
1
2
3
4
5
6
7
8
9
10
The sum is: 55
[root@server~]# vi table.sh
Print table
Input number
5
5
10
15
20
60
Practical 10(b): Configuring Booting with GRUB.
Step 1:
Step 2: Change From Red Hat Enterprise Linux to Red Hat Recovery in grub.conf file
61