Practical Linux

You might also like

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

PILLAI’S COLLEGE OF ARTS COMMERCE

AND SCIENCE

Linux System Administration


“ Practical File ”

Name:Suraj Malap
Roll No:8624
Std:TYIT
Div:D

INDEX
Practical  Details Date Remark
No.

1.  Graphical User Interface and Command Line


Interface and   Processes 
      1. Installation of RHEL 6.X 
2. Exploring the Graphical Desktop 
3. The Command Line Interface 
4. Managing Processes.

2.  Storage Devices and Links, Backup and Repository 


1. Working with Storage Devices and Links 
2. Making a Backup 
3. Creating a Repository

3.  Working with RPMsm Storage and Networking 


1. Using Query Options. 
2. Extracting Files From RPMs 
3. Configuring and Managing Storage 

4.  Working with Users, Groups, and Permissions 

5. Working with  Firewall


1. Securing Server with iptables 

6.  Working with Web Server


1. Configuring Apache on Red Hat Enterprise Linux.
2. Writing a Script to Monitor Activity on the
Apache Web Server 
3. Using the select Command

7. Working with shell scripting.


a)Write a shell script to the user name and age from input and
print the year when the user would become 50 years of age.
 b) Write a shell script to create a directory called demo1
inside /tmp and three blank file file1,file2,file3 inside it and
list them.
  c) Write the shell script to delete the file3 created in the
question 2 above and also print the time after deletion of the
file.
   d)Writing Shell Scripts for following:  Find Factorial
Number, Palindrome Number,Palindrome String,Reverse
Number, Armstrong Number,Count of Digit.

8. Working with advance shell script.


1. Write a shell script to perform numeric comparison in
Linux.
2.  Write a shell script to find out unique word in a file
and also count the occurrence of each of the word
3.   Write a shell script to validate password strength .
4.   Write a shell script to get the current date time
username and working directory.
5.  Write a shell script that adds two numbers if provided
as the command line argument and if the two numbers
are not entered it outputs error message

PRACTICAL 1

Aim : Graphical User Interface and Command Line Interface and Processes
1. Installation of RHEL 6.X 

- step 1: Install the Vmware Workstation Pro 16 Setup from the internet. Download and extract it ,
then open it and click next
- step 2 : Then Click next option and then proceed.

- step 3 : select the path where you wanted the fiel to be located.
- step 4: click next and then proceed.

- step 5: click on install and then proceed further.


- step 6: It will start Downloading

- step 7 : After fully install the workstation see the interface.


- step 8 : click on the file option , and then click on the “New virtual Machine”.

- step 9 : After then , the installation process start’s , select Typical(recommanded) and then click
next.
- step 10 : select the image file that you have downloaded from the internet and click the next button.

- step 11: set the full name , username, password and set confirm password then click next.
- step 12: after that we can rename the virtual machine then click next

- step 13: Give the disk size (30GB) or less and select “strore virtual disk as a single file” then click
next
- step 14: Then click on the “Customize hardware” and set the properties.

- step 15: then Memory upto “8gb”, processor should be “2” for both the cores and set the iso file ,
which is been already downloaded from internet.
- step 16: Then set the language thet you want and click “continue”
- step 17: Then select the region and time zone , set the GUI mode and choose the disk.

- step 18: then create a linux profile and set the usernamae and password.
- step 19: after installing all the files , the GUI interface will get displayed

PRACTICAL 1

Aim : Graphical User Interface and Command Line Interface and Processes
2. Exploring the Graphical Desktop 
PRACTICAL 1

Aim : Graphical User Interface and Command Line Interface and Processes
3. The Command Line Interface 
i. Pwd,cd commands :
ii. Mkdir commands
iii. Rmdir commands
 Cat commnads
 -b ( for numbering but it does not number the space)

 -n ( for numbering but it does number the space as well)

 Now to shrink the extra space between the lines in the terminal which takes extra space we
use -s cmd :
 For getting the list of files in new file

4) Managing Processes.
Shows the processes running in the background

Top:

Kill :

PRACTICAL 2
Aim : Storage Devices and Links, Backup and Repository 
1. Working with Storage Devices and Links 

A) How to work with storage device and links in red hat linux

● Dev is under root , however we are in student. Hence we need permission from th root using su
command
● It then ask for roots password (roots)
● Now we are in root directory(#),
● df command gives info of external devices connected to software
● When pendrive is attached space is created in dev directory.
● Now select 1) virtual machine 2)red hat linux.(second one ,)
● Now again type df now new line is generated at the end , its our pendrive stored in devfolder.sda1
● Now we create a folder using mkdir /mnt/test123
● Now we mount using mount -t vfat /dev/sda1 /mnt/test123 (sda can change checkurs always)
● Now we can find this data in test123 so we go in this folder using cd /mnt/test123
● Now ls the content of test123
● Now if we remove the pendrive and reattach it then we need to use su command again, now if we df
we can see all files(last one is sdb1)

B) LINKS(soft/symbolic link)

➔ 2 types of links -soft and hard.


➔ Files from pendrive get stored in linknode
➔ Symbolic link means shortcut file
➔ We now start by creating folder named mkdir Aryaa
➔ Cd suraj
➔ cat > test123 (hello hope u all ok)
➔ Above is an original file
➔ ls -li (does long form listing)
➔ To create link of the above file we use command ln -s test123 mytest123 command
➔ Now if we ls we can see two files where mytest123 is link of test123
➔ ls -li (lrwrw and -> symbol means link file)
➔ cat mytest123 ( shows content of test 123 hence it acts as a pointer to text123)
➔ mv test123 to retest123(move contend of test123 to file retest123)
➔ ls -li (now mytest123 is in red cuz our main file test123 is gone or moved)
➔ cat mytest123 wont work now( as test is empty)
➔ cat retest123 will work as data is moved here
➔ cat >test123 ( here we enter the data again as before the data was moved from test to
retest)
➔ ls -li ( now lists mytest123 in green)
➔ cat mytest123 (Shows suraj)
C ) Hard link
● ln test123 hardtest (now hardlink is created)
● ls -li (no arrow is seen here , hence this shows this is not a dependent file , stores same
file with different name)
● In symbolic when main file is removed the pointer file then points to null hence its
dependent, however in hard if the main file is removed then the other file mytest123
is not removed as it is an independent file)
● rm test123
● ls -li
● cat hardtest
● cat mytest123

PRACTICAL 2

Aim : Storage Devices and Links, Backup and Repository 


2. Making a Backup 
PRACTICAL 2
Aim : Storage Devices and Links, Backup and Repository 
3. Creating a Repository
PRACTICAL 3a
Aim : Working with RPMsm Storage and Networking
1. Using Query Options.
2. Extracting Files From RPMs
3. Configuring and Managing Storage

1. Using Query Options.


PRACTICAL 3b

Aim : 2.Extracting Files From RPMs


Step1 :
change to the root directory by “su”.

Step2:
after installing yum install the rpm
“ yum install rpm-build”

Step 3:
Run the command “ yum repolist all ”

Stepp 4:
After that change the directory to repos.d
“ cd /etc/yum.repos.d”

PRACTICAL 3c

Aim : Configuring and Managing Storage.


Step 1 :

Attach pendrive
fdisk -l : to check the connected pendrive (gives location )

Step 2 :
Type the Command :
fdisk –l /dev/sda1

To check partition
-fdisk -l /dev/sda1
fdisk -c /dev/sda1 

Step 3 :
For manual press m which’ll open up the manual for fdisk.
Step 4:
Press n to add a new partition and p to print the partition table, give the value of 19865252 which is
the default size.

PRACTICAL 4

Aim : Working with Users, Groups, and Permissions 

 To create a new user


 To list information of user

 Default settings for creating a user

 Giving password

 -l (to lock a user)

 -u (unlock)

 -S (to check status of a password of a user)

 -e (to force password at every next login)


 Change status if home creation

 Modifying user account

 Deleting user account

 The group folder in etc gives all information folders


RELATIVE PERMISSION

 To give permission to a directory

 To give permission to a file

ABSOLUTE PERMISSION
 To give execute permission to user in file 1

 To give more than 1 permission in file 2

PRACTICAL 5

Aim : Working with  Firewall


1. Securing Server with iptables
iptables -L -v
iptables v1.8.2 (nf_tables)
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

: flushing the rules


iptables -F

iptables -L -v
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -m multiport -p tcp --port 21,80 -j ACCEPT

: To Check if all the rules are applied or not -


iptables -L –v

OUTPUT :
PRACTICAL 6a

Aim : Working with Web Server


1. Configuring Apache on Red Hat Enterprise Linux.
2. Writing a Script to Monitor Activity on the Apache Web Server
3. Using the select Command

1. Configuring Apache on Red Hat Enterprise Linux.

Step 1:
Use the commad “httpd” for Configuring Apache
If not available then install the httpd from yum.

Step 2:
To restart the httpd
“service httpd restart”
Step 3:
To chack the configuration
“chkconfig httpd list”

Step 4:
To create file
“cd /var/www/html

Step 5:
After that open the gedit editor with example.html
To create html file.

Step 6:
Write the html code in the file.

Step 7:
After that save and close the html file and restart it by using command :
“service httpd restart”

Step 8:
Check the file location in var->www->html and open it .

Step 9:
run on the browser : http://locallost/example.html\
Step 10 :
if the network is close then go in setting then turned on the wired .

PRACTICAL 6b

Aim : Working with Web Server

2. Writing a Script to Monitor Activity on the Apache Web Server

Step 1 :
Create shell script by gedit :
gedit example.sh
Step 2:
Write the script in example.sh file

Shell script :

#!/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 $COUNTER
done
logger HTTPMONITOR: httpd stopped at 'date'
service httpd start
mail -s Apache server just stopped root

Give rights : chmod -R 777 example.sh


Then check : sh example.sh

PRACTICAL 6c

Aim : Working with Web Server

3. Using the select Command

Step 1:
Open the vi editor
Create “vi example2.sh”
Shell Script :

echo 'Enter the name of an RPM of the file that you want to check or install or delete'
read RPM
echo 'select a task form the menu'
select TASK in 'check from which RPM this file comes' 'check if this RPM is installed' 'Remove this
RPM'
do
case $REPLY in
1) rpm -qf $RPM*;;
2) rpm -qa | grep $RPM*;;
3) rpm -ivh $RPM*;;
4) rpm -e $RPM*;;
*) echo error && exit 1;;
esac
if [ -n "TASK" ]
then
echo you have selected TASK $TASK
break
else
echo invalid choice
fi
done
Step 2:
After saving the changes run the .sh file
Step 3:
multiple options will appear, then choose 2

Practical 7a
Aim: Working with shell scripting.
a)Write a shell script to the user name and age from input and print the year when the user
would become 50 years of age.
Shell Script :
#!/bin/bash
# Read user name
echo "Enter your name:"
read name
# Read user age
echo "Enter your age:"
read age
# Calculate the year when the user will turn 50
year_when_50=$((50 - age + $(date +%Y)))
# Print result
echo "$name will turn 50 years old in the year $year_when_50"
OUTPUT:

Practical 7b
Aim: Working with shell scripting.
b) Write a shell script to create a directory called demo1 inside /tmp and three blank file
file1,file2,file3 inside it and list them.
 
Shell Script:
#!/bin/bash
# create the demo1 directory inside /tmp
mkdir /tmp/demo1
# change to demo1 directory
cd /tmp/demo1
# create three blank files
touch file1 file2 file3
# list the files in demo1 directory
ls -l

OUTPUT:

Practical 7c
Aim: Working with shell scripting.
c). Write the shell script to delete the file3 created in the question 2 above and also print the
time after deletion of the file.

Shell Script:

#!/bin/bash
rm file3
echo "File3 has been deleted."
echo "Time after deletion: $(date)"

OUTPUT :

Practical 7d
Aim: Working with shell scripting.
d). Writing Shell Scripts for following:  Find Factorial Number, Palindrome
Number,Palindrome String,Reverse Number, Armstrong Number,Count of Digit.

Shell Script :

1. Find Factorial Number:

#!/bin/bash
read -p "Enter a number: " num
fact=1
for((i=1;i<=num;i++))
do
fact=$((fact * i))
done
echo "The factorial of $num is $fact"

OUTPUT :

2. Palindrome Number

Shell Script :

#!/bin/bash
read -p "Enter a number: " num
original=$num
reverse=0
while [ $num -gt 0 ]
do
rem=$((num % 10))
reverse=$((reverse * 10 + rem))
num=$((num / 10))
done
if [ $original -eq $reverse ]
then
echo "$original is a palindrome number"
else
echo "$original is not a palindrome number"
fi

OUTPUT :

3. Palindrome String:
Shell Script :

#!/bin/bash
read -p "Enter a string: " str
if [ "$str" == "$(echo $str | rev)" ]
then
echo "$str is a palindrome string"
else
echo "$str is not a palindrome string"
fi

OUTPUT :
4. Reverse Number:

Shell Script : 

#!/bin/bash
read -p "Enter a number: " num
reverse=0
while [ $num -gt 0 ]
do
rem=$((num % 10))
reverse=$((reverse * 10 + rem))
num=$((num / 10))
done
echo "The reverse of the number is $reverse"

OUTPUT :
5. Armstrong Number:
Script Shell :

#!/bin/bash
read -p "Enter a number: " num
original=$num
sum=0
while [ $num -gt 0 ]
do
rem=$((num % 10))
sum=$((sum + rem ** 3))
num=$((num / 10))
done
if [ $original -eq $sum ]
then
echo "$original is an Armstrong number"
else
echo "$original is not an Armstrong number"
fi
OUTPUT : 

6. Count of Digits:
Script Shell : 

#!/bin/bash
read -p "Enter a number: " num
count=0
while [ $num -gt 0 ]
do
count=$((count + 1))
num=$((num / 10))
done
echo "The number of digits in the number is $count"

OUTPUT : 
Practical 8a
Aim: Working with advance shell script.
1. Write a shell script to perform numeric comparison in Linux.

Shell Script: 

#!/bin/bash
# Script to perform numeric comparison in Linux
# Take two numbers as input
read -p "Enter first number: " num1
read -p "Enter second number: " num2
# Check if num1 is equal to num2
if [ $num1 -eq $num2 ]; then
echo "$num1 is equal to $num2"

# Check if num1 is less than num2


elif [ $num1 -lt $num2 ]; then
echo "$num1 is less than $num2"

# Check if num1 is greater than num2


else
echo "$num1 is greater than $num2"
fi

OUTPUT  : 
  

Practical 8b
Aim: Working with advance shell script.
2. Write a shell script to find out unique word in a file and also count the occurrence of
each of the word.

Shell Script  : 
Here 
l corresponds to line
w corresponds to word
c corresponds to character
Practical 8c
Aim: Working with advance shell script.
3.Write a shell script to validate password strength .

Shell Script  : 

#!/bin/bash

echo "Enter password: "


read password

# Check password length


if [[ ${#password} -lt 8 ]]; then
echo "Password is too short, must be at least 8 characters long."
exit 1
fi

# Check for mix of uppercase and lowercase characters


if [[ $password == *[A-Z]* && $password == *[a-z]* ]]; then
echo "Password is strong."
else
echo "Password must contain a mix of uppercase and lowercase characters."
exit 1
fi

# Check for special characters


if [[ $password == *[@#$%^&+=]* ]]; then
echo "Password is strong."
else
echo "Password must contain at least one special character (@#$%^&+=)."
exit 1
fi

exit 0

OUTPUT 

Practical 8d
Aim: Working with advance shell script.
4.Write a shell script to get the current date time username and working directory.

Shell Script  : 

 #!/bin/bash

echo "Current date and time: $(date)"


echo "Username: $USER"
echo "Working directory: $PWD"

OUTPUT 
Practical 8e
Aim: Working with advance shell script.
5.  Write a shell script that adds two numbers if provided as the command line argument and
if the two numbers are not entered it outputs error message

Shell Script  : 

#!/bin/bash

if [ $# -eq 2 ]; then
  num1=$1
  num2=$2
  result=$((num1 + num2))
  echo "The result is: $result"
else
  echo "Error: Please provide two numbers as command line arguments."
fi

OUTPUT 

PRACTICAL 8a

Aim : Working with advance shell script.


1. Write a shell script to perform numeric comparison in Linux.

Shell Script :

echo "Enter 2 numbers"


read no1
read no2

if [ $no1 -eq $no2 ]


then
echo "The Numbers are Eqauls"

elif [ $no1 -gt $no2 ]


then
echo " 1st number is greater"

else
echo "2nd number is greater"
fi
vi practical.sh

Bash practical.sh

You might also like