Linux KernelTech
Linux KernelTech
TECH
(Skilled with Excellence)
LINUX
Reference Guide
With Lab Exercises
Student Name:
Batch:
Branch:
AMEERPET
Page 1 of 274
UNIX Basics
Page 2 of 274
UNIX Basics
www.kerrneltech.com
0^
Compiled bv
Linux Faculty
Kernel Technologies
Page 3 of 274
UNIX Basics
www.kerrneltech.com
Page 4 of 274
UNIX Basics
www.kerrneltech.com
Iwould like to thank Mr.Vinod Kumar(Rahul) and Ms. Jyoti Singh (MD Kernel Tech),
for giving me the opportunity to compile this book on Linux.
I would especially like to thank my Mentor Mr. Vinod Kumar (Rahul) for all his support,
guidance, supervision and patience in making of this book, without whom this could
never have been possible.
I would also like to thanks the entire dedicated Team of Kernel Technologies for their
support and suggestions in making of this book
Musabuddin Syed
Words To The Students
Though we have taken utmost efforts to present you this book error free, but still it may
contain some errors or mistakes. Students are encouraged to bring, if there are any
mistakes or errors in this document to our notice. So that it may be rectified in the next
edition of this document.
This document provides the brief information on every topic and lab practices. The
students are advice to make full use of the lab sessions, taking help of the Lab Assistants
available. Please, feel free to ask your doubts to our faculties.
We urge you to work hard and make use of the facilities we are providing to you,
because there is no substitute for hard work. We wish you all the best for your future.
"God gives every bird its food, but He does not throw it into its nest" J.G. Holland
You and yoursuggestions are valuable to us; Help us to serve you better. In case of any
suggestions, grievance, or complaints, please feels free to see our MD Ms. Jyoti Singh,
You can also write us yoursuggestions, grievance and feedback on the following
[email protected]
Jvoti(5)kerrneltech.com
musab(5) kerrneltech.com
Page 5 of 274
UNIX Basics
Page 6 of 274
UNIX Basics
www.kerrneltech.com
v/lNTRODUCTION TO LINUX
09-15
16-33
v^BASIC COMMANDS
34-55
56-74
75-93
94-113
114-124
125-133
134-150
y-JOB AUTOMATION
151-158
159-168
169-176
^SOFTWARE MANAGEMENT
177-194
195-197
198-200
y MANAGING PROCESSES
201-210
211-223
224-231
SAMBA SERVER
232-239
240-250
251-260
261-274
Page 7 of 274
UNIX Basics
Page 8 of 274
UNIX Basics
www.kerrneltech.com
INTRODUCTION TO LINUX
OPERATING SYSTEMS
SINGLE-USER
MULTI-USER
TTTTTTri-.:
computer cannot understand the human readable language as it works on binaries i.e^QIs-ancLlls. Also it
is very tough for humans to understand the_bjnary_language, in such case we need an interface which
can translate human language to hardware and vice-versa for effective communication.
E.g.: MS-DOS
Page 9 of 274
UNIX Basics
www.kerrneltech.com
HISTORY OF UNIX
Bell Labs' Ken Thompson developed UNIX in 1969 so he could play games on a scavenged DEC PDP-7.
With the help of Dennis Ritchie, the inventor of the "C" programing language. Ken rewrote UNIX entirely
in "C" so that it could be used on different computers. In 1974, the OS was licensed to universities for
educational purposes. Over the years, hundreds of people added and improved upon the system, and it
spread into the commercial world. Dozens of different UNIX "flavors" appeared, each with unique
qualities, yet still having enough similarities to the original AT&T version. All of the "flavors" were based
on either AT&T'sSystem V or Berkeley System Distribution (BSD) UNIX, or a hybrid of both.
During the late 1980*5 there were several of commercial Implementations of UNIX:
IBM's AIX
The Open Standards Foundation is a UNIX industry organization designed to keep the various UNIX
flavors working together. They created operating systems guidelines called POSIX to encourage inter
operability of applications from one flavor of UNIX to another. Portability of applications to different
gave UNIX a distinct advantage over its mainframe competition.
Then came the GUIs. Apple's Macintosh operating system and Microsoft's Windows operating
environment simplified computing tasks, and made computers more appealing to a larger number of
users. UNIX wizards enjoyed the power of the command line interface, but acknowledged the difficult
learning curve for new users. The Athena Project at MIT developed the X Windows Graphical User
Interface for UNIX computers. Also known as the Xll environment, corporations developed their own
"flavors" of the UNIX GUIs based on Xll. Eventually, a GUI standard called Motif was generally accepted
by the corporations and academia.
During the late 1990/5 Microsoft's Windows NT operating system started encroaching into traditional
UNIX businesses such as banking and high-end graphics. Although not as reliable as UNIX, NT became
popular because of the lower learning curve and its similarities to Windows 95 and 98. Many traditional
UNIX companies, such as DEC and Silicon Graphics, abandoned their OS for NT. Others, such as SUN,
focused their efforts on niche markets, such as the Internet.
Page 10 of 274
UNIX Basics
www.kerrneltech.com
fljf^
l$p*
Linus Torvalds had a dream. He wanted to create the coolest operating system in the world that was
free for anyone to use and modify. Based on an obscure UNIX flavorcalled MINIX, Linus took the source
code and created his own flavor, called Linux. Using the power of the Internet, he distributed copies of
his OS all over the world, and fellow programmers improved upon his work. In 1999, with a dozen
versions of the OS and many GUIs to choose from, Linux is causing a UNIX revival. Knowing that people
are used to the Windows tools, Unux developers are making applications that combine the best of
Windows with the best of UNIX.
UNIX Principles
Everything is a file:- UNIX system have many powerful utilities designed to create and
manipulate files. The UNIX security model is based around the security of files. By
treating everything as a file, you can secure access to hardware in the same way as you
secure access to a document.
Ability to chain programs together to perform complex tasks:- A core design feature of
UNIX is that output of one program can be the input for another. This gives the user the
flexibility to combine many small programs together to perform a larger, more complex
task.
JpSl
jp\
0>>
wvvw.kerrneltech.com
0*
'^Hk
Linux Origins
LINUS TORVALDS
Why Linux?
1) Linux is a UNIX like OS: Linux is a similar to UNIX as the various UNIX versions are to each
other.
3) Wide hardware support: Red Hat Linux support most pieces modern x86 compatible PC
hardware.
4) Fully Supported: Red Hat Linux is a fully supported distribution Red Hat Inc. provides
many support programs for the smallest to the largest companies.
Page 12 of 274
www.kerriieItech.coni
/^$$\
/^ftk
JJP*
ARCHITECTURE OF UNIX
0s
The architecture of UNIX can be divided into three levels of functionality, as shown in Figure . The lowest
level is the kernel, which schedules tasks , manages resources, and controls security. The next level is
the shell, which acts as the_user interface, interpreting user commands and starting applications. The
highest level is utilities, which provides utility functions. In other words it is the USER level, as user is the
one who operates those utilities.
jp
Page 13 of 274
(^
Linux uses single rooted, inverted tree like file system hierarchy
/
s^~
/root
/etc/dhcpd.conf....
DHCP server
C:\windows\system32\dirvers\
/usr
/opt
/bin
/sbin
Page 14 of 274
www.kerrneltech.com
/dev
Like
/dev/hda
... for hard disk
/dev/cd rom ... for ccl rom
Similar to device manager of windows
/proc
/proc/cpuinfo ...
information of CPU
/var
. .- ,
'
C-ZXQ^
/mnt
/media
/lib
I
Page 15 of 274
www.kerrneltech.coni
Recommended
Minimum
Recommended
Minimum
Requirement for
Requirement for
Requirement for
Requirement for
RHEL6-32BIT
RHEL6-32 BIT
RHEL6-64BIT
RHEL6-64BIT
AMD/INTEL
AMD/INTEL P IV
AMD/INTEL
AMD/INTEL
PROCESSOR
DUAL CORE
CORE 2 DUO
DUAL CORE
MOTHER BOARD
NORMAL
NORMAL
VT ENABLED
VT ENABLED
RAM
1GB
384-512 MB
2 GB
768-1GB
HARD DISK
20 GB
15 GB
40 GB
20 GB
/ (root)
/boot
8 to 10 GB
15 to 20 GB
200 MB
200 MB
SWAP
Twice of RAM
Twice of RAM
Enter into BIOS setting and make CD/DVD Drive as first boot device
Make sure that VT (Virtual Technology) is enabled for RHEL6-64 bit systems
Insert the RHEL 6 CD/DVD into CD/DVD drive and boot the system
If booted from CD/DVD Rom the following screen will be displayed
Helcone to Red Hat Enterprise Linux
fran
local
dr iue
RED HAT
R
Page 16 of 274
www.kej-nieilech.com
9
1
To test the media select OK, to skip the testing move cursor to Skip and press enter
Page 17 of 274
www.kerrneltech.com
~~l ~
Catalan (Catala)
"
Dutch (Nederlands)
' "fr'ai
French (Francais)
German (Deutsch)
Greek (EAAn,viKC)
Gujarati (=pr?icfl)
Hebrew (jv-mv)
Minrli fite*tt
^iBack
B^Next
*N
Russian
Serbian
Serbian (latin)
Slovak (qwerty)
Slovenian
Spanish
Swedish
Swiss French
U.S. International
Ukrainian
United Kingdom
<agack | | E^Mext
Page 18 of 274
www.kerrneltech.com
Select the keyboard type as required usually U.S English, click Next to continue
What type of devices will your Installation involve?
Basic Storage Devices
Installs or upgrades to typical types ofstorage devices. If you're notsure which option Is right for you.
this Is probably It
O Installs orupgrades toenterprise devices such a*Storage Area Networks (SANs). This option wltl allow
you to add FCoE / ISCSI/ zfCP disks and to filter out devices the Installer should Ignore.
^fiack
,&*&
Select the type of storage for the Computer. Click Next to continue
l=a Pleasename this computer. The
pp hostname identifiesthe computer on a
*^ network.
Hostname: ktadmin.kts.comj
Configure Network
| <*aBack
,
| ^>Next
_j
^.
Page 19 of 274
www.kerriieltech.coni
Assign a hostname to the system, ifwish to give ip address click on Configure Network, else
Click Next to continue
^gack
^Next
Select the nearest city in your Time Zone and Click on Next to continue
Pase 20 of 274
www.kerrneitech.com
Root Password:
Confirm:
^Bfiack
E^Mext
systems.
Tip: This option will remove data from the selected devlce(s). Make sure you have backups.
E?}
Replace Existing Unux Systom(s) Removes only Unux partitions (created from a previous Unux Installation). This does not remove other
partitions you may have on your storage devfeets) (such as VrAT or RKT32).
Tip: This option will remove data from the selected device's). Make sure you have backups.
Shrinks existing partitions to create free space for the default layout.
Retains your current data and partitions and uses only the unpartltloned space on the selected device
(s). assuming you have enough free space available.
<8>
|| .,^M.r^lly;awj;a^f3fl^^
... * K--,%-?
selected c^jcefat)j,uslr>g qur|
jrHng.faBJf
D Encrypt system
13 Review and modify partitioning layout.
^agack
G>uext
Select the type of partitioning you want, to create your own partitions with custom sizes,
select Create Custom Layout and click on Next to continue
Page 21 of 274
www.kerrneltech.com
Device
v
Size
Mount Point/
(MB)
RAID/Volume
Type Format
Hard Drives
sda
mm
Create
Eait
Reset
i Sack
Next
Click on the Free space, then click on Create to create your own partitions
25596 MB
Device
Hard Drives
Create Storage
Size
Mo|
(MB)
RA Create Partition
Standard Partition
^ sda
Information
O RAID Partition
O
RAID De,
Create LVM
Information
O LVM Vol'.! :
O LVM Logii
O LVM Physical Volume
Cancel
Create
Reset
^aBack
} :.!> Next
Page 22 of 274
www.kcrriieltech.com
Add Partition
Device
Hard Drives
Mount Point:
/
-
ext4
c sda
Free
o
25600".!::
j Allowable
,'irtual S
Drives:
Size (MB):
15000
si
Additional Size Of
fixed size
115000
Encrypt
Cancel
Reset
ok
<$SBack
Mext
Select / from Mount Point Box, give the size you wish for it and click on OK to create it.
Select the Free space again and click on Create to create another partition. Also Check the
box beside Standard Partition, Click on Create to continue
ITierAdd Partition
Device
"="
Hard Drives
Mount Point:
File System Type:
Sda :.';:c-.
sdal
|/boot
ext4
i
25600 MB
VM i
Allowable Drives:
Size (MB):
200
Fixed size
Encrypt
Cancel
QK
Reset
Back
Page 23 of 274
vvvvw.kernieltech.com
Select /boot from Mount Point Box, give the size 200 MB for it and click on OK to create it.
Repeat the same steps and create swap space
Please Select A
Device
Add partition
Device
Mount Point:
File System Type:
swap
El sda
sda
sdal
25600 MB
Allowable Drives:
sda2
Free
Size (M3):
|2048|
ncrypt
Cancel
Reset
OK
IBack ] [ E>Next !
This time select swap from File System J_ype, give the size required and click on OK
Please Select A
Device
Device
Hard. Drives
sda .
sdal
sda2
200 /boot
15000 /
sda3
2048
Free
8351
ext4
>/
ext4
swap
v"
Beset
Create
; noc-:
Next
Page 24 of 274
vvwvv.kernieliech.com
Please Select A
Format Warnings
The following pre-existing devices have been selected to be
formatted, destroying all data.
Device
<
-
lard Drives
v
Device
sda
/dev/sda
sdal
sda2
sda3
Free
Cancel
format
Create
Reset
Back
c*> Next
Device
n,..!^ s'ze
Mount Point/ ._
e_...J
,.,_, .._.., .
Type Format
Device
(MB)
RAID/vb ume
"
Reset
Create
Next
iBack
Click on Write changes to disk to continue, if wish make changes click on Go back.
Page 25 of 274
www.kerrneltech.com
hange device
! Device
Add
Edit
Qelete
<*afiack
[ ^Ciext
To change the name of boot loader select Edit and assign new name to it.
To assign password to boot loader check the box beside Use boot loader password and
assign a password to it.
/%
**^^b
Page 26 of 274
www.kerrneltech.coni
<^k
/^s
The default installation of Red Hat Enterprise Linux is a basic server install. You can
optionally select a different set of software now.
O Basic Server
O Database Server
O Web Server
O Virtual Host
>'
j=?fModify repository
You can further customize the software selection now, or after install via the software
management application.
Customize later
O Customize now
; Back
+ Next
RED HAT
ENTERPRISE LINUX' 6
Page 27 of 274
www.kerrneltech.com
El Reboot
uVJ
When above prompt is displayed, remove the CD/DVD from the drive and click on Reboot
to reboot the system.
Page 28 of 274
www.kcrriicltccij.com
Welcome
There are a few more steps to take before your system is ready to use. The
Setup Agent will now guide you through some basic configuration. Please
click the "Forward" button in the lower right comer to continue
RED HAT-
ENTERPRISE LINUX 6
Forward
License Information
END USER UCENSE AGREEMENT RED HAT<S> ENTERPRISE LINUX* AND RED HAT
APPLICATIONS
This end user license agreement ("EULA") governs the use of any of the
.versions of Red Hat Enterprise Linux, certain other Red Hat software
>J
fiack
| Forward
www.kerrneltech.com
Welcome
- License
Information
>-S et- Up
Updates
Create User
as:
Software
Kdump
Forward
Back
Check No, 1 prefer to register at a later time, to skip the registration and click on Forward.
Welcome
License
Information
y setup
Software
Updates
Create User
Kdump
fi|
Compliance:
Stay in compliance with your subscription
i~ agreement and manage subscriptions for systems
connected to your account at http://rhn.redhat.com/.
You will not be able to take advantage of these
subscriptions privileges without connecting
your system to Red Hat Network.
Forward
'
Page 30 of 274
www.kerrneitcch.coin
License
Information
Back
Forward
Create User
You must create a 'usemame' for regular (non-administrative) use of your
system. To create a system 'username', please provide the information
requested below.
Username:
ktuser
Full Namg:
ktuser
Password:
Confirm Password:
If you need more control when creating the user (specifying home directory,
and/or UlD), please click the Advanced button.
I Advanced-
Back
Forward
Page 31 of 274
www.kerrneltech.com
Give a name to create a user and assign it a password. Click on Forward to continue.
License
Date
<
October
>
ETTEBn
iVHi!
'
Hour:
Minute :
29
10
11
12
13
14
Second :
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
x-
[4F
Back
Forward
Page 32 of 274
www.kerrneitech.com
Kdump
Kdump is a kernel crash dumping mechanism. In the event of a system
crash, kdump will capture information from your system that can be
invaluable in determining the cause of the crash. Notethat kdump does
require reserving a portion of system memory that will be unavailable for
other uses.
D Enable kdw
ii Memory
499
Back
Finish
Page 33 of 274
www.kerrneItech.coni
BASIC COMMANDS
cat (Concatenate.) command is used to create a file and to display and modify the contents
of a file.
To create a file
ktfile
Hello World
World
[root@ ktlinux
~]# 3
ktfile
[rootQktlinux ~]# :
Page 34 of 274
Creating a Directory:
tfmkdir <dirname>
#mkdir ktdir
|ktdir |
anaconda-ks. cfg
Downloads
le3
Desktop
filel
install.log
ktfile
Documents
ile2
Music
[root@ktlinux ~]# M
Let us make some directories accordingto the following architecture in one command.
KernelTech
Linux
Aix
advlinux linuxclstr
hacmp Ipar
Storage
san
netapp
#mkdir-pKernelTech/{Unux/{ady|{nux/linuxclstr}/Aix/{hacmp/lpar}fStorage/{san,netapp}}
Check it by usingtree command or Is-R command
,
(root@ktlinux -]# mkdir -p KernelTech/{Linux/{advlinuxllinuxclstr},Aix/{hacnipllpar},Storage/{san,net
app}}
root@ktlinux -]# tree KernelTech/
[ernelTech/
Aix
hacmp
tpar
inux
advlinux
linuxclstr
Storage
I netapp
san
9 directories, 0 files
[root@ktlinux ~]# 1
Page 35 of 274
www.kerrneitech.com
JJPn
*^lj
fWf\
[rootSktlinux ktdir] # I
Copying directories from one location to other
file2
^k
ktdir2
l"^jl
'^sk
anaconda-ks .cfg
Desktop
Documents
Downloads
filel
file3
install.log
install.log.syslog
file2
[root@ktlinux ktdir] # |j
/sa
Page 36 of 274
www.kerrneltech.com
/^k
#*
[rootQktlimix ~]# Is
anaconda-ks. cfg
Desktop
Documents
Downloads
filel
file3
install. log
install.log. syslog
ktdir
ktdir2
filel
install.log
[ktdir2
Desktop
file3
ktfile
Downloads
filel
file2
file3
file4
[rootSktlinux ktdir2]# I
file5 |ktdir
'
Renaming a File
#mv<oldname> <newname>
#mv ktfile kemelfile
[root@ktlinux ~]# Is
anaconda-ks.cfg
Desktop
rrontakfHmix
Documents
Downloads
~1# rat
install.log
install.log.syslog
ktfile
Pictures
Templates
MUSIC
Public
Videos
k t f 11 o
[rootSktlinux -]# Is
anaconda-ks.cfg
Desktop
Documents
Downloads
install.log
install.log.syslog
kernelfile
MUSIC
Templates
Pictures
Public
Videos
[rootSktlinux ~]#
Renaming a Directory
The procedure arid command for renaming the directoryis exactly same as renaming a file.
#mv old name new name
[root@ktlinux ~]# Is
anaconda-ks.cfg
Documents
install.log
kernelfile
Desktop
Downloads
install.log.syslog
ktdirI
anaconda-ks.cfg
Desktop
Documents
Downloads
[rootSktlinux ~]# 1
install.log
install.log.syslog
kerneldir
kernelfile
Page 37 of 274
www.kerrneltech.com
~^im
Removing a File
install.log
install.log.syslog
kerneldir
KernelTiLe
kerneldir
Music
[rootSktlinux ~]# B
Removing an Empty directory
#rmdir dirname
/^h
[rootSktlinux ~]# Is
anaconda-ks.cfg Documents
Desktop
Downloads
install.log
install.log.syslog
kerneldir
ktdir
anaconda-ks.cfg
Desktop
Documents
Downloads
install.log
install.log.syslog
kerneldir
Music
/^
[rootSktlinux ~]# |
A dir which is having some contents inside it cannot be removed by rmdir command. There are
two ways to delete the directory with contents.
i.
Remove the contents inside the directory and then run rmdir command
ii.
Run#rm -rf dimame (where r stands for recursive and f stands for forcefully.
[rootSktlinux ~]# Is
anaconda-ks.cfg
Documents
install.log
Music
Desktop
Downloads
Pictures
Page 38 of 274
www.kerrneltech.com
/^$\
r <mmk
VIM EDITOR
VI
This is command mode editor for files. Other editors in Linux are emacs, gedit
vi editor is most popular
It has 3 modes:
Command Mode
Note: When you open the vim editor, it will be in the command mode by default.
In the command mode the cursor's can be used as
h/l/k/j
Insert Mode:
v^
v^
v^
Command Mode:
gg
G
w
nw
nb
u
Page 39 of 274
www.kernieitech.com
*%
Ctrl+R
yy
nyy
P
P
dw
x
dd
ndd
To
To
To
To
To
To
To
To
Extended Mode is used for save and quit or save without quit using "Esc" Key with ":"
Esc+:20(n)
To
To
To
To
To
To
To
To
Esc+: se nu
Esc+:se nonu
Esc+:w
Esc+:q
Esc+:wq
Esc+:wl
Esc+wq!
Esc+:x
Esc+:X
y^$s
#ls
#ls-l
long listing of the file
#ls -\ filename
to see the permissions of a particular file
#ls-al
shows the files in ascending order of modification.
#ls p*
All the files start with p.
#ls ?ample
Files with any first character and has ample
#ls -Id I*
Directory listing only
#ls -Id directory name
to see the permissions of a particular directory
#ls [ae]*
First character of the filename must be a or e.
# Is [!ae]*
! Symbol complements the condition that follows. The characters must
/%
not be a or e.
#ls [a-m][c-z][4-9]
/^$k
Page 40 of 274
www.kerrneltech.com
/^?i\
Types of Files:
Symbol
Type of File
Normal file
Directory
Link file (shortcut)
Soft Link
Hard link
different
4
>/l
SHORTCUT FILE
5934
3394
Hrwxrwx rwx.
[rootSktlinux -]# |
-> ktfile
[rootSktlinux -]# I
Page 41 of 274
wvvw.kerrneltech.com
/^l
f^^
Grep stands for Global Regular Expression Print. It is used to pick out the required expression
from the file and print the output. If grep is combined with another command it can be used to
pick out the selected word, phrase from the output of first command and print it.
Examples of Grep:
Let us pick the information about root from the file /etc/passwd (/etc/passwd contains
information about all the users present in the system)
[rootSktlinux ~]# |
To avoid case sensitivity of the word (i.e. the word may be uppercase of lowercase) use -i
#grep -i kernel ktfile (lets grep the word kernel whether upper of lower case in the file ktfile)
kernel ktfile
[rootSktlinux ~]# |
To display a word and 2 lines after the word:
#grep-nA2 wheel /etc/group
.';. "
[rootSktlinux -]# fl
To display a word and 2 lines after the word:
#grep -nB2 wheel /etc/group
Page 42 of 274
wvvw.kerrneitech.com
^^k
jp^
[rootSktlinux ~]# 0
To display the searched word in color
#grep -color root/etc/passwd
Combining grep with other commands
>
Like this we can combine grep with many commands which we will see in later chapters
Filter Commands:
Filtercommands are used to filter the output so that the required thingscan easily be
picked up. Thecommands which are used to filter the output are
#less
#more
#head
#tail
#sort
#cut
#sed
Page 43 of 274
www.kerrneitech.com
less:-
The less command is used to see the output line wise or page wise.
Ex: less/etc/passwd
/^j
shutdown:x:6:8:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail :/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin I,
ftp:x:14:50:FTP
User:/var/ftp:/sbin/noloqin
A^
./
command
/'
more:-
head:
/etc/passwd
root:x:Q:O:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/va r/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/noloqin
r^ai&k
Page 44 of 274
www.kernicitech.com
^Sf^*.
bin:x: 1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/va r/adm:/sbin/nologin
Ip:x:4:7:Ip:/var/spool/lpd:/sbin/nologin
tail:
[rootSktlinux ~]# |
Page 45 of 274
www.kerriieltech.com
Sort:
i <;
Frppriom
'<''*-i-\ :W
Linux is Freedom
Linux is Freedom
Welcome to Kernel Tech
Welcome to Kernel Tech
Welcome to Kernel Tech
r\
'f
'
' '
*
,''
^-
[rootSktlinux ~]# |
'l%fk
5.Linux is Freedom
6.Linux is Freedom
Page 46 of 274
www.kerrneltech.com
[rootSktlinux -]# |
cut command:
The cut command is used to pick the given expression (in columns) and display the output.
# cut -d -f filename (where d stands for delimiter ex.:," * etc and f stands for field)
[rootSktlinux ~]# cut -d: -fl /etc/passwd
root
bin
daemon
adm
IP
sync
shutdown
halt
mail
uucp
hello,how,are, you
[rootSktlinux ~J# cut -d, -fl hello
hello
Page 47 of 274
www.kernieltech.com
sed command:
sed stands for stream editor, which is used to search a woni in the file and replace it with the
Note: it will only modify the output, but there will be no change in the original file.
I)
*i
I/O Redirection:
Redirection is a process where we can copy the output of any command(s), file(s) into a new
file. There are two ways of redirecting the output into a file.
9
9
Note: if the given name of the file is not available a new file will be created automatically. If
the file already exists then it will overwrite contents of that file.
9
9
9
ktfl
- Hyderabad
Ex:
Page 48 of 274
The above options of redirections will not display any output, but directly save the output in
a file. Using tee command will not only redirect the output to new file but it will also display
the output.
Syn: cat <filename> | tee <new file name>
y
Note: if the given name of the file (newfile) is not available a new file will be created
automatically. If the file already exists then it will overwrite contents of the file.
#cat ktfile | tee ktfl
Kernel Tech
Kernel Tech
ktfl
Ameerpet - Hyderabad
[rootSktlinux ~]# cat ktfl
Welcome to
Kernel Tech
Ameerpet - Hyderabad
Page 49 of 274
www.kerrneltech.com
9
Find command:
find command is used to find the files or glirtary's:path, it is exactlyjike the find option in
windows where you can search for a file.
-inum
-type
-user
-group
Usage
#find/-name KernelTech
[rootSktlinux -]# find / -name KernelTech
Vvar/named '
/root/Ke rnelTechl
/
*/var/named'.
find:
find:
find:
Vproc/9206/task/92G6/f d/5' : No s
Vproc/9206/task/9206/fdinfo/5' :
'/proc/9206/fd/5': No such file o
find:
Vproc/9206/f dinfo/5' :
No
such fi
/root/ktfile.hlink
/root/ktfile
[rootSktlinux -]#
9
Pa^e 50 of 274
www.kerrneltech.com
,/
Vvar/named' .
/var/spool/mail/ktuser
/home/ktuser
/home/ktuser/.mozilla
/home/ktuser/.mozilla/plugins
/home/ktuser/.mozilla/extensions
/home/ktuser/kernel2
/home/ktuser/.bashrc
/home/ktuser/. gnome2
/home/ktuser/kernell
N/var/named'.
/home/ktuser/kernel2
/home/ktuser/kernell
/home/ktuser/kernel4
/home/ktuser/kernel5
/home/ktusei7kernel3
Pase51of 274
www. ke r r n e 11e c h. c o m
File Permissions:
Permissions are applied on three levels:-
Group level
Others level
v"
v^"
r read only
w write/edit/delete/append
x execute/run a command
Permissions
r
w
X
Directory
Files
Example: Assigning different permissions to the file (user=rwx, group=rw and others=r)
-rwxrw-r--.
[rootSktlinux ~]# 1
Page 52 of 274
www.kerrneitoch.com
tfchmod go-wx ktfile (Removing write and execute permissions from group and other)
#chmod go+wx ktfile (Adding write and execute permissions from group and other)
tfchmod go=r ktfile (Giving only read permission to group and other)
Read=4
Write=2
Execute=l
#chmod 764 ktfile (where 7 means rwx i.e. 4+2+1, rw=6 i.e. 4+2 and 1 indicates x)
[rootSktlinux ~]# Is
-I
root root
[rootSktlinux ~]# chmod
[rootSktlinux ~]# Is -I
-rwxrw-r--. 1 root root
- rwx rwx rwx.
ktfile
0 Sep 17 09:21 ktfile
764 ktfile
ktfile
0 Sep 17 09:21 ktfile
[rootSktlinux ~]# Is
-rwx rw-r- -.
-I ktfile
root root 0 Sep 17 09:21 ktfile
www.kerrneliech.coni
Umask:
When we create any file using t""<"K-cat-ac-^i rnrnrnflnds thpy gpWrpatpri with defauJliile
permissions as stored in umask (User file creation mask).umask is a 4 digit octal number which
tells Unix which of the three permissions are to be denied rather than granted. Umask will
decide that what should be the default permissions for a file and directory when it is created.
The default umask value is 0022
tfumask
9
[rootSktlinux ~]# umask
0022
[rootSktlinux ~]# I
9
Calculation of default permissions for file and directory, basing upon the umask value
Note: For a file by default it cannot have the execute permission, so the maximum full
permission for a file at the time of creation can be 666 (i.e. 777 -111 = 666), whereas a directory
can have full permissions i.e. 777
666
-022
644
(rw-,r,r)
[rootSktlinux
Page 54 of 274
www. ke r in e i tec h. com
777
- 022
755
The Modified default Permission for a file will be 666-002=664 i.e. rw,rw,r, and for the
directory it will be 777-002=775 i.e. rwx,rwx,r-x.
[rootSktlinux ~]# umask
D022
[rootSktlinux ~]# |
Note: Create a file and a directory and check for the default permissions.
These were the few things amongst the basics; keep working to furnish your basics. After All,
"if the foundation isgood then only the building can stand still"
Page 55 of 274
www.kerrneltech.com
-*
What is a partition?
Partitioning is a means to divide a single hard drive into many logical drives. A partition is a contiguous
set of blocks on a drive that are treated as an independent disk. A partition table is an index that relates
Encapsulate your data. Since file system corruption is local to a partition, you stand to lose only
some of your data if an accident occurs.
Increase disk space efficiency. You can format partitions witK-varvlag-block sizes, depending on
your usage. If your data is in a large number of small files (less than Ik) and your partition uses
4k sized blocks, you are wasting 3k for every file. In general, you waste on average one half of a
block for every file, so matching block size to the average size of your files is important if you
have many files.
Limit data growth. Runaway processes or maniacal users can consume so much disk space that
the operating system no longer has room on the hard drive for its bookkeeping operations. This
will lead to disaster. By segregating space, you ensure that things other than the operating
system die when allocated disk space is exhausted.
9
9
EXTENDED
FREE
L= LOGICAL PARTITION
Page 56 of 274
www.kerrneltcch.com
On the disk where O/S is installed,will have the first partition as MBR,
MBR is a Master Boot Record, which contains two important utilities, iPL (initial
Program Loader) and PTI (Partition Table information)
IPL isjgsponsible for booting the_QDating the system, because it contains the boot
loader.
In earlier versions of Linux i.e. up to RHEL 4, the default boot loader was LILO (Linux
Loader). But, since RHEL5 onwards it has been changed to GRub (Grand Unified Boot
loader), which is far more superior to LILO.
The_PJJ (Partition Table information) is the information about the number of partitions
on the disk, sizes of the partition and types of partitions.
THE CRITERIA OF DISK PARTITIONING:
Primary Partition is a partition which usually holds the operating system. Only one
amongst the 3 primary partitions can be active which will be booted by MBR to load
Extended Partition is a special type of primary partition which can be subdivided into
multiple logical partitions. As there can be only 3 primary partitions per disk, and if
the user is required to make further partitions then all the space remaining on the
disk should be allocated to extended partition, which can be used to create the logical
partitions later. There can be onlyone extended partition per disk.
Logical partitions are the partitions which are created under extended partition, all
the space in the extended partition can be used to create any number of logical
partitions.
Disk Identification:
FILE SYSTEM:
It is method of storing the data in an organized fashion on the disk. Every partition on
the disk except MBR and Extended partition should be assigned with some file system
in order to make them store the data. File system is applied on the partition by
formatting it with a particular type of file system.
PaRe 57 of 274
www.kerrneltech.com
The file systems supported in Linux are ext2, ext3 and in RHEL 6 ext4, vfat, etc.
Ext file system is the widely used file system in Linux, whereas vfat is the file system to
maintain a common storage between Linux and windows (in case of multiple o/s'
EXT3
EXT4
EXT2
S.NO
Stands
1.
2.
3.
4.
for
File System
File System
Supports Joumaling
Supports Joumaling
feature.
Feature.
Feature.
from 16 GB to 2 TB
from 16 GB to 2 TB
16 GB to 16 TB i?r
Maximum ext4 file system size
is 1 EB (Exabyte). 1 EB = 1024
PB (Petabyte). 1 PB = 1024 TB
(Terabyte).
file
TB to 32 TB
TB
system to ext2.
Maximum
5.
6.
Second
ext2
rs~-~
MOUNTING:-
Attaching a directory to the file system in order to access the partition and its file
system is known as mounting.
The mount point is the directory (usually an empty one) in the currently accessible file
system to which a additional file system is mounted.
The /mnt directory exists by default on all Unix-like systems. It, or usually its
subdirectories (such as /mnt/floppy and /mnt/usb), are intended specifically for use as
mount points for removable media such as CDROMs, USB key drives and floppy disks.
/etc/mtab is a file which stores the information of all the currently mounted file
/etc/fstab is the file which is keeps information about the permanent mount point. If
you want to make your mount point permanent, so that it will be mounted even after
reboot, then you need to make an appropriate entry in this file.
Page 58 of 274
www.kerrneItech.coni
/^k
0s
LAB WORK:
Start
2
/dev/sdal
Partition 1 does
End
201
202
8201
8202
8192000
83
Linux
12201
4896000
83
Linux
/dev/sda4
12202
Partition 4 does
System
Linux
/dev/sda3
Partition 3 does
Id
83
/dev/sda2
Partition 2 does
Blocks
204800
30720
18963456
Extended
/dev/sda5
/dev/sda6
12204
15205
15203
17204
3072000
2048000
83
Linux
82
Start
End
Size
Type
File system
Flags
1049kB
211MB
210MB
ext4
boot
211MB
8389MB
8599MB
8599MB
12.8GB
4194MB
primary
primary
primary
12.8GB
32.2GB
19.4GB
extended
12.8GB
15.9GB
3146MB
15.9GB
18.0GB
2097MB
logical
logical
ext4
ext4
ext4
linux-swap(vl)
Note: Observe in the above picture that the device name is /dev/sda.
Page 59 of 274
www.kernieitech.com
|p\
S^m\
<^m
#fdisk /dev/sda
c
d
I
m
n
o
p
q
s
t
u
v
Page 60 of 274
www.kerrneltech.com
/1%
^tak
#fdisk /dev/sda
Use p to list out the partition information first and
Use n to create a new partition.
[root<aktcl5 Desktop]* fdisk /dev/sda
WARNING:
"T^
rT~^
"""^
'u').
6xOO09Oa56
Device Boot
*
/dev/sdal
Start
2
not end on
Partition
does
/dev/sda2
262
Partition 2
8202
not end on
does
not
12202
/dev/sda5
/dev/sda6
end
Id
System
83
Linux
83
Linux
83
Linux
cylinder boundary.
4096666
cylinder boundary.
36728
on
8192666
cylinder boundary.
12261
does
/dev/sda4
Partition
Blocks
204800
8261
/dev/sda3
Partition 3
End
261
18963456
Extend
cylinder boundary.
12204
15263
3072000
83
15205
17264
2048666
82
Linux
Linux .
Now use nto create a new partition and verify it again with p.
/dev/sdal
Partition 1 does
/dev/sda2
Partition 2 does
/dev/sda3
Partition 3 does
/dev/sda4
Partition 4 does
Start
2
End
Blocks
Id
System
281
284800
83
Linux
83
Linux
83
Linux
8201
8192000
12201
4096000
30720
18963456
Extended
/dev/sda5
/dev/sda6
12204
15203
15205
17204
|/dev/sda7
17205
17705
3072000
2048000
513008
83
Linux
82
83
Linux
Page 61 of274
www.kerrneltech.com
-/fPN
/^|V
Deleting a partition
Use d to delete a partition and specify the device name, in our case it is 7.
Every time you make a partition or delete a partition, the changes made has to be saved using
w, otherwise the creation and deletion will not be considered to be happen. For practice
purpose you can make any no. of partition and delete it and just quit using q so that it will not
be saved.
[root@ktcl5 Desktop]* |
#partprobe /dev/sda ,,
Or
#partx-a/dev/sda
Or
#kpartx /dev/sda
Note: In RHEL6 partprobe is not functioning properly, so it is recommended to use partx
command only.
Now then we have learnt creating a partition. Lefs see how to format a partition with a
particular file system.
Page 62 of 274
www.kerrneltech.com
After creatinga partition we need to assign some file system to it so that we can start storing
the data into it. To format a partition the following syntax is used.
# mkfs.<file system typo <partition name>
[root@ktcl5 Desktop]# |
Likewiseyou can format the different partitions with different file systems like
#mkfs.ext3 /dev/sda8
#mkfs.vfat/dev/sda9
Note: Even after formatting the partition we cannot add the data into the partition. In order
to add the data in the partition it is required to be mounted.
Page 63 of 274
jp\
Mounting a partition
Mounting is a procedure where we attach a directory to the file system. There are two types of
mounting which will be used in Linux or any UNIX.
$k
Temporary Mounting
Permanent Mounting
Temporary Mounting
In a temporary mount point we will create a directory and mount it, but this mount point will
last only till the system is up, once it is rebooted the mounting will be lost.
Syntax:
'-.?
[root@ktcl5 ~]# I
To View allthe mounted partitions
#mount
/-i
: a N,
/^ll
mode=0590)
Now we have successfully mounted the partition we can access it and can store the data
#cd /kernel
Add the data and exit the directory
Unmounting a partition
^%
Permanent Mounting
Permanent mounting procedure is exactly same like temp mounting, but here we will update
the /etc/fstab file with the mounting details, so that it will be mounted even after the system is
reboot.
Use mount -a command to check it is mounting, (mount -a will mount all the entry
placed in /etc/fstab)
Herewe will be using our existing/kernel directoryas mount point which is created previously.
#vim /etc/fstab
#
# /etc/fstab
UUID=62419cbf-4435-4798-b879-8f821el5cd5b
UUID=46aa65bl-Sd68-432a-9d64-69ae332feb2d
UUID=4f72eaef-8667-450c-ab56-ed36d5dfb8b6
UUID=948a9c29-3a8f-4b6b-a84b-aaa7be57e2a8
/
/boot
/home
/usr
ext4
ext4
ext4
ext4
UUID=204d9293-fe4e-4dc2-89cd-816c7a986188 swap
tmpfs
/dev/shm
tmpfs
devpts
/dev/pts
devpts
sysfs
/sys
sysfs
proc
fdev/sda7
/proc
/kernel
Mount Point
swap
defaults
gid=5,mode=629
defaults
e
e
proc
defaults
ext4
defaults
Device Name
defaults
defaults
defaults
defaults
defaults
1 2
1 2
1 2
e
#mount -a
Iroot@Ktc15 ~j# mount -a
mode=85eo)
t/dev/sda7 on /Kernel type ext4 (r\'/)|
[root(aktcl5 ~]# fl
Page 65 of 274
www.kerrneltech.com
./iilN
You can now access the directory and add, delete or modify the contents and can also unmount
the file system at any point
Sometimes a directory reflects error while unmouting, the possible causes for it are
You are in the same directory and trying to unmount it. Check with pwd command
Some users are present in the directory and using the contents in it.
[root@ktcl5 -]# I
Now you can use umount command to unmount the file system. .-*
Tq view the usage information of mounted partition use the command df-h
#df-h
M,
Lroot@ktcl5 ~J# df -h
Filesystem
Size Used Avail Use% Mounted on
/dev/sda3
3.9G
tmpfs
499M
/dev/sdal
/dev/sda5
/dev/sda2
/dev/sr6
/dev/sda7
[root@ktcl5
194M
2.9G
7.7G
3.2G
486M
383M
372K
39H
69H
3.1G
3.2G
11H
3.3G 11% /
499H
1% /dev/shm
146M 21% /boot
2.7G
3% /home
4.3G 42% /usr
8 169% /media/RHEL 6.0 x86 64 Disc 1
456M
3% /kernel
~l#l
Assigning the label is giving some name to the partition. To assign label to the partition e2label
command is used
^sa
Syntax
#e2label/dev/sda7
To list all the mounted partition along with their labels, use mount-I command
Page 66 of 274
www.kerrneltech.com
IP*
Mounting a /dev/sda7 partition with its label ktdisk, verify it with mount command
[root@ktcl5 ~]# mount LABEb=ktdisk /kernel
[root@ktcl5 ~]# mount
Making a permanent mount point using label
#vim /etc/fstab
tmpfs
devpts
/dev/shm
sysfs
/sys
/proc
proc
|LABbL=ktdisk~
tmpfs
devpts
sysfs
/dev/pts
/Kernel
defaults
gid=5,mode=620
defaults
0 0
0 6
8 8
proc
defaults
68
ext4
qeTauits
6 9"|
Now use mount -a command and verify it with mount command whether it is mounted or
not.
[root@ktcl5 ~]# I
'
#vim/etc/fstab
tmpfs
devpts
sysfs
proc
/dev/shm
/dev/pts
/sys
/proc
trapfs
devpts
sysfs
defaults
gid=5,raode=620
defaults
9 e
9 0
9 8
proc
defaults
8 9
/kernel
ext4
defaults
JP
Page 67 of 274
|pN
www.kerriieltech.com
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system
needs more memory resources and the RAM is full, inactive pages in memory are moved to the
swap space. While swap space can help machines with a small amount of RAM, it should not be
considered a replacement for more RAM. Swap space is located on hard drives, which have a
slower access time than physical memory.
Recommended System Swap Space
p '-
Apart from the above recommendation a basic rule is applied to create the swap partitions
if the size of the RAM is less than or equal to 2GB, then size of SWAP=2 X RAM SIZE
If the size of the RAM is more than 2GB, then size of SWAP= 2GB + size of the RAM
Swap space is compulsory to be created at the time of installation. But, additional swap spaces
can be created and deleted at any point of time, when it is required. Sometimes we need to
increase the swap space, so we create additional swap spaces which will be added to the
existing swap space to increase the size.
V-
*- -%,
Page 68 of 274
www.kerrneltech.com
gps
Create a normal partition using fdisk and change hex code to make it swap partition.
The hex code for SWAP is 82. (To change the use t in fdisk and list all the hex code use I)
Update the partition table using partx -a command
[root@ktlinux /]# fdisk /dev/sda
82
/dev/sdal
/dev/sda2
/dev/sda3
/dev/sda4
/dev/sda5
/dev/sda6
Start
End
Blocks
Id
System
3825
36720000
8e
3825
3851
204860
83
Linux LVM
Linux
3851
4361
4096000
82
4361
6527
17406303+
4361
4425
521957
83
Extended
Linux
4426
4496
522081
82
Page 69 of 274
www.kerrneltech.coni
<**^\
/dev/sda3
/dev/sda6
[rootSktlinux /]# free -m
Size
Used
Priority
Type
partition
4095992 0
-1
partition
522072
-2
total
used
free
shared
buffers
cached
2907
741
1266
272
-/+ buffers/cache:
464
1543
4509
Mem:
Swap:
4569
In order to make the swap partition mount automatic after reboot, we need to make an
"$
#vim /etc/fstab
#
# /etc/fstab
/dev/mapper/vg ktlinux-rootI v /
ext4
defaults
UUID=ce33cb92-21b8-49c8-95fc-17f48437d44b /boot
ext4
ext4
ext4
ext4
1 1
defaults
defaults
defaults
defaults
swap
1 2
1 2
1 2
1 2
defaults
sysfs
proc
/sys
/proc
sysfs
proc
defaults
gid= 3,mode=620
defaults
defaults
/dev/mapper/ktpart
/kernel
ext4
defaults
8 e
/dev/sda6
swap
swap
defaults
8 8
8 e
0 8
8 a
8 8
6 e
Page 70 of 274
www.kerrneltech.com
/^i|
It encrypts the partition or volume, which will decrypt only by providing correct
password.
The partition must be decrypted before the file system in it can be mounted.
Once it is open (decrypted), you can work with the partition normally i.e. mounting and
adding the data to the partition.
After the completion of work the partition has to be closed i.e. encrypted, so that it
cannot be mounted nor can be accessible by others, unless you lose password.
Commands used in LUKS encryption:
cryptsetup luksFormat: To Format the partition with encryption, and assigning the
password.
cryptsetup luksOpen: To open or decrypt the partition, (password will be required) and
the you need to assign some name to it, which will be used for further operation as
/dev/mapper/name.
crypsetup luksClose: To Close or encrypt back the partition after use.
cryptsetup luksAddKey: To add the key (password) to the configuration to automatically
decrypting the partition.
7. Unmount the partition, and close the partition i.e. encrypt back.
1. Create a normal partition using fdisk.
/dev/sdal
/dev/sda2
/dev/sda3
Start
End
Blocks
Id
System
3825
30720000
8e
3825
3851
204800
83
Linux LVM
Linux
82
3851
4361
4096000
/dev/sda4
4361
6527
17406303+
Kdev/sda5
[rootSktlinux --]#B
4361
4425
521957
5
83
Extended
Linux
Page 71 of 274
www.kernieltech.coni
^v
[rootSktlinux ~]# |
3. Decrypt the partition.
To decrypt the partition for further use, make use of the following steps
[rootSktlinux ~]# |
4. Formatting the partition with ext4 file system.
Page 72 of 274
www.kerrneltech.com
#vim /etc/fstab
UUID=60dcea45-f68b-473d-b953-0fbc5b63d5fc swap
defaults
swap
tmpfs
devpts
sysfs
/dev/shm
/dev/pts
/sys
tmpfs
devpts
sysfs
nroc
/Proc
_E2
'dev/mapper/ktpart
/kernel
ext4
defaults
gid=5,mode=620
defaults
defaults
defaults
0 0
~e"ef
#vim/etc/crypttab
Mb
Qtpart /dev/sda5
6. Access the partition andsome data to it.
Access the partition using mount point
lost+found
7. Unmount the partition, and close the partition i.e. encrypt it back
# umount /dev/mapper/ktpart
Page 73 of 274
www.kerrneltech.com
Either you should type the passphrase to continue or can ignore it by usine etrl+e to
continue booting without decrypting and mounting the partition
*
Nntl. TKhange the permlsslon of* fil* (600), and add the path ofthe file in /etc/crvattab
^-^^the^schanged
sothatgroups others^ ^
IrootSktlinux /J# chmod 600 enphrs
[rootSktlinux /]# is -l enphrs
-rw-------. i root root 10 Sep 28 06:44 enohrs
[rootSktlinux /]# |
#mkfs.ext4/dev/sda5
Encryption will be removed
En^ST data ln the Partitin Wl" be ,0St' S mate SUre that you have backuP **"efore
Page 74 of 274
www.kerriielfech.rnm
larger partitions than you could, achieve with a single.drive. Traditional uses of_LVM_ have
jncludea^databases and company_fjje_servers, but even home users may want large partitions
for music or video collections, or for storing online backups. LVM can also be convenient ways
to gain redundancy without sacrificing flexibility.
A typical example for the need of LVM can be, assuming that we are having a disk of size 2GB
and we start adding the data in the form of a single file, eventually it grows to the size of 2GB.
In this case the possibility is, you go for another disk which is larger than 2GB, let's say 4GB. But
what if the file again grows more than 4GB? How far you will be migrating file from one disk to
another so on and so forth? It requires a down time as well which is not possible in real time, so
to avoid these circumstances we implement LVM and store data in LV's whose size can be easily
increased whenever required without a downtime.
Logical Volurne(s)
Physical Partitions
The Basic structure of LVM
Above picture shows the structure oLLVM. LVM consists of Physical Volumes, Volume Group,
Logical Volumes and finally file systems. The Physical partitions are known as Physical Extents
(PE), and the logical partitions are known as logical Extents (LE)
Page 75 of 274
www.kerrnehech.coni
It is the standard partition that you add to the LVM. Normally, a physical volume is a standard
primary or logical partition with the hex code 8e.
Physical Extent (PE)
It is a chunk of disk space. Every PV is divided into a number of equal sized PEs.
Volume Group (VG)
It is composed of a group of PV's and LV's. It is the organizational group for LVM.
Logical Volume (LV) is composed of a group of LEs. You can format and mount any file system
on an LV. The size of these LV's can easily be increased or decreased as per the requirement.
Logical Extent (LE)
It is also a chunk of disk space. Every LE is mapped to a specific PE.
LVM Command
Function
vgreduce
pvremove
vgremove
pvs
vgs
Ivs
pvdisplay
vgdisplay
Ivdisplay
pvcreate
vgcreate
Ivcreate
vgextend
Ivextend
Ivresize
Ivreduce
pvmove
Ivremove
9
9
Page 76 of 274
www.kerrneltech.com
LAB WORK:0&\
Create a partition using fdisk, and change the hex code of it to 8e.
Save and exit the fdisk and update the partition table using partx-a command
Device Boot
/dev/sdal
/dev/sda2
*
/dev/sda3
/dev/sda4
/dev/sda5
/dev/sda6
/dev/sda7
Start
1
3825
3851
End
Blocks
3825
3851
30720000
204880
8e
83
Id System
Linux LVM
Linux
4361
4096000
82
4361
4361
4426
6527
4425
17406303+
521957
5
83
Extended
Linux
4490
522081
82
4491
4555
522081
83
Linux I
8e
7 to
8e (Linux LVM)
#pvcreate/dev/sda7
JpV
VG
/dev/sdal
vq ktlinux lvm2 a-
Fmt
Attr PSize
29.29q
PFree
1.95g
Atev/sda7
lvm2 a509.84m 509.84m
[rootSktlinux Desktop]* pvdisplay
"/dev/sda?" is a new physical volume of "509.84 MiB"
--- NEW Physical volume --PV Name
/dev/sda7
VG Name
jpPN
PV Size
Allocatable
PE Size
Total PE
509.84 MiB
NO
0
0
Free PE
Allocated PE
pV UUID
RzuHEg-ks6y-cvem-C5F4-tfk8-veco-n)Jqs46
The above command will list all the PVs in the system, if you want tosee the details only for
a particular PV, then use
www.kerrneltech.com
JP*
/^fflfl
/^i\
yh,-
1ktvq
vgktlinux
VSize
0 wz--n- 508.00m
0 wz--n-
VFree
508.00m|
29.29g
1.95g
/si . "; .
r^!|\
System ID
. Format
lvm2
Metadata Areas
Metadata Sequence No
VG Access
read/write
VG Status
resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
/^H^
/^$^
Act PV
VG Size
508.80 MiB
PE Size
Total PE
4.00 MiB
Alloc PE / Size
Free PE / Size
0/0
VG UUID
127
To check all the VGs detail you can also use the command
#vgdisplay
/^^v
Page 78 of 274
www.kerrneltech.com
Once we are ready with aVolume Group then it's the time to create a Logical Volume LV
The syntax for creating an LV is
#lvcreate-L <size of LV>-n <name for LVxVG name>
[rootSktlinux Desktop]* |
Verifythe LV by using the following commands
#lvdisplay ktvg
f^
VG
ktvq
Attr
LSize
-wi-a- 300.00m
3.91g
3.91g
9.77g
varlv
9.77q
vq ktlinux -wi-ao
/dev/ktvg/ktlv
ktvg
x0NkZc-Qqll-6Ev/K-HuGj-YNlI-5vVW-XQUKB
LV Write Access
read/write
LV Status
available
# open
LV Size
Current LE
75
300.00 MiB
Segments
Allocation
inherit
auto
- currently set to
256
Block device
253:4
Note: The output for only Ivdisplay command is very lengthy to show, it is recommended
that you run the command on the system and check itout. The syntax is given above.
Page 79 of 274
www.kerrncltech.coni
.<(t^
r^k
As per now we have our VG created so is our LV. In order make it accessible we need to
format it with a file system like ext4 or ext3 or vfat.
The syntax for formatting an LV is exactly like formatting a normal partition, Instead of
/dev/partition name we use the path of LV that will be something like /dev/vg/lv
#mkfs.ext4/dev/ktvg/ktlv
/W0\
S^h
[rootSktlinux Desktop]* |
Mounting:
Mounting an LV is exactlysame like a normal partition, again the path for mounting will be
/dev/vg/lv
/%$k
/S^]S
#vim /etc/fstab
/sys
/proc
sysfs
proc
/dev/mapper/ktpart
/kernel
ext4
/dev/sda6
swap
swap
ydev/ktvq/ktlv
/ktdir
ext4
sysfs
proc
defaults
defaults
defaults
defaults
defaults
0 0
0 0
0 0
0 0
0 01
0!^
JIN
Add the partition to the VG using vgextend command, the syntax for it is
0^
VG
Fmt
Attr PSize
PFree
29.29g
i.95g
/dev/sda7
ktvg
lvro2 a-
508.08m 208.00m
/dev/sda8
Ktvg
lvm2 a-
508.00m 508.00m
[rootSktlinux /]# |
Increasing the size of a logical volume
/%k
Sometimes the file system size may be full, so we need to increase the size of the LV to
Increase the size of the LV by using Ivextend or Ivresize command, the syntax for it is
#lvextend -L <+addition size> </dev/vg/lv name> (syntax for Ivresize is also same)
#lvextend-L+200M/dev/ktvg/ktlv
Update the file system by using resize2fs command
#resize2fs /dev/vg/lv name
#resize2fs /dev/ktvg/ktlv
Verify the change by using df -h command
[rootSktlinux /]# df -h
Filesystem
size Used Avail Use% Mounted on
/dev/mapper/vgktlinux-rootlv
3.9G
450M
3.3G
tmpfs
1Q04M 300K 1004M
/dev/sda2
194M
39M 146M
/dev/mapper/vgktlinux-homelv
3.9G
13% /
1% /dev/shm
21% /boot
72M
3.6G
2.3G
6.9G
25% /usr
9.7G
3.5G
5.7G
39% /var
291M
11M
266M
2% /home
/dev/mapper/vgktlinux-varlv
/dev/mappe r/ktvg-ktlv
4% /ktdir
IrootSktlinux /J# |
Page 81 of 274
www.kerrneltech.coni
d^v
/^I
Filesystem
Size Used
/dev/mapper/vg ktlinux-rootlv
450M
3.3G
1004M 300K
1004M
3.9G
tmpfs
/dev/sda2
194M
13% /
1% /dev/shm
21% /boot
-~'*3f'
39M
146M
72M
3.6G
2.3G
6.9G
25% /usr
9.7G
3.5G
5.7G
39% /var
485M
11M
450M
r^H
/dev/mapper/vg ktlinux-homelv
3.9G
2% /home
/dev/mapper/vg ktlinux-usrlv
9.7G
/dev/mapper/vg ktlinux-varlv
/dev/mapper/ktvg-ktlv
3% /ktdir
/Ssjk
[rootSktlinux /]# ]
Reducing the size of an LV is a bit complicated task, there are few things which you need to
keep in mind before reducing the size of an LV.
LV size cannot be reduced online, it requires a down time i.e. unmounting the file
system.
#e2fsck-f/dev/ktvg/ktlv.
#resize2fs /dev/ktvg/ktlv 300M (where 300M is the approximate total size of LV after reduction)
Page 82 of 274
www.kerrneltech.com
/^H||
[rootSktlinux /]# |
Organize the data in the file system.
*s
[rootSktlinux /]# e2fsck -f /dev/ktvo/ktlv
[rootSktlinux /]# |
Update the file system about the size after reduction
v^
[rootSktlinux /]# |
Finally reduce the size of the LV using Ivreduce command. It will prompt you about the change
type y to continue with reduction.
[rootSktlinux /]# |
Mount the LV and run the command df-h, to verify the change in the size of LV
#mount -a (if an entry is passed in /etc/fstab use this command)
#df-h
/dev/mappe r/ktvg-ktlv
291M
11M
266M
4% /ktdir
[rootSktlinux /]* |
Page 83 of 274
www. ke r rn e 11 c c h. c o in
There might be a situation where the PV might be failing and it is required to be replaced, in
I'^Hk
such case, we need to migrate or move the data from such PV to the other and isolate the
PV.
Access the mount point of failing PV and check the data in it,
Verify the size of the PV by pvs command or pvdisplay command.
A%S
Add new PV, which should be of the same size or higher than that of the replacing
PV to the volume group.
Migrate the PVs contents to the new PV using following command
#pvmove <01d PV> <New PV>
Mount back the LV, access the mount point and verify the data in it.
Remove the faulty PV from Volume Group.
j -
ktdata2
ktdata3
ktdata4
ktdataS
ktdata6
ktdata7
ktdataS
lost+found
ktdata9
[rootSktlinux ktdir]* |
Verify the size of the PV by pvs command or pvdisplay command.
[rootSktlinux --]# pvs
Fmt
Attr PSize
PV
VG
/dev/sdal
rootvq lvm2 a-
/dev/sda6
ktvg
lvm2 alvm2 a-
/dev/sda7
[root@ktlinux --]# pvdisplay
17.57q
PFree
598.00m 208.00m
509.84m 599.84m
Physical volufnp
PV Name
/dev/sda6
VG Name
ktvq
PV Size
Allocatable
PE Size
Total PE
127
/^i
Free PE
52
Allocated PE
75
PV UUID
Hjki4-doLN-I0DB-P8T9-itBr-Hn6V-yVrrz2
Page 84 of 274
www.kerrneltech.com
Add new PV which should be of the same size or higher than that of the replacing PV to
l have created another partition from fdisk i.e. /dev/sda7 with the size around 500MB
[rootSktlinux -]# pvs
PV
VG
/dev/sdal
rootvg lvm2 a-
Fmt
Attr PSize
/dev/sda6
ktva
lvm2 alvm2 a-
/dev/sda7
PFree
17.57g
508.00m 108.00m
509.84m 509.84n
[rootSktlinux ~]# |
/dev/sda7
[rootSktlinux ~]# |
Mount back the LV, access the mount point and verify the data in it.
[rootSktlinux ~]# mount -a
[rootSktlinux ~]# cd /ktdir
[rootSktlinux ktdir]* Is
ktdatal
ktdataie
ktdata2
ktdata3
ktdata4
ktdata5
ktdata6
ktdata7
ktdata8
lost+found
ktdata9
[rootSktlinux ktdir]* |
Remove the faulty PV from Volume Group.
Asthe data is moved safely, now let's remove the faulty PVfrom the volume group.
The syntax to remove a PV from a VG is
#vgreduce <vg name> <PV name>
flvgreduce ktvg /dev/sda6
Page 85 of 274
www.kerrneltech.coni
/^ft
Deleting/Removing an LV:
To Delete/Remove an LV, first unmount the file system.
Remove the entry from /etc/fstab.
/*ss%
'
'
[rootSktlinux -]# |
As we was having only one LV and that is now deleted, that's why it is not showing any LVs
after executing Ivdisplay command.
To delete the volume a group, make sure that if there is any LV in it, it should not be
mounted. Because while removinga vg it will also remove LV's inside it. In our case we have
/flto
#vgremove ktvg
[rootSktlinux ~]# vgremove ktvg
Volume group "tog" successfully removed
[rootSktlinux -]* |
Deleting a Phvsical Volume
Deleting a PV is very simple. The only thing we should check that the PV we are going to
delete should not belong to any volume group. We can only delete a PVwhich is free.
/m
#pvremove /dev/sda6
#pvremove /dev/sda7 OR
#pvremove /dev/sda{6,7} (To remove multiple PVs in one command)
[rootSktlinux ~]# pvremove /dev/sda{6,7}
Labels on physical volume "/dev/sda6B successfully wiped
Labels on physical volume "/dev/sda7" successfully wiped
Building anything requires lots of concentration, hard work, and patience, but to demolish
it, it is just a matter of a moment. Isn't it....!
Page 86 of 274
www.kerrneltech.com
gfp\
Ox0OO03d37
Device Boot
/dev/sdal
/dev/sda2
/dev/sda3
System
Start
End
Blocks
Id
1
1785
1811
1785
14336898
8e
Linux
1811
284888
83
Linux
2872
2619
2897152
82
4325849
/dev/sda4
|/dev/sda5
2872
2972"
2136
518412+
83
LVM
Linux swap /
Solaris
Extended
Linux]
[rootSktlinux ~]# |
Verify the PE size using vgdisplay command
[root@ktlinux ~]# vgdisplay ktvg2
Volume
VG
group
ktvg2
Name
System ID
Format
lvm2
Metadata Areas
Metadata Sequence
1
No
VG Access
read/write
VG
resizable
Status
MAX
LV
Cur
LV
Open LV
Max
PV
Cur PV
Act
PV
VG Size
496.08 MiB
|PE Size
Total
Alloc PE /
Free
VG
16.00 MiB|
PE
PE /
UUID
31
Size
Size
0/0
31 /
496.00 MiB
lacNDZ-szQ6-Fq76-lZMZ-Px3K-KQXo-UMDQV
Page 87 of 274
www.kerrneltech.com
JP*
Size of LE=Size of PE
In Command we are specifying the no. of LE not the size of LE,as the size of LEis based on
Size of PE.
For example if the size of PEis 16, then the size of LE will also be 16.
*^k
Volume group
/^i
ktvg2
VG Name
System ID
lvm2
Format
Metadata Areas
Metadata Sequence
read/write
VG Access
VG
1
No
resizable
Status
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size
496.00 MiB
|PE Size
16.00 MiB|
Total PE
31
Alloc PE / Size
8/0
Free
31 / 496.08 MiB
VG
PE /
Size
UUID
z^t)
lacNDZ-szQ6-Fq76-lZHZ-Px3K-KQXo-llMDQV
Okay, now then we know the size of PE is 16, lets calculate how many LE is required to
If the size of LV is to be 2 GB then first we need to convert GB into MB and then calculate
/^$\
2x1024/16=128.
You can use #bc command to do all the calculations. Use ctrl+d or Ctrl+c to quit the
calculator
[root@ktlinux ~]# be
be 1.06.95
/9h
408/16
25
2*1024/16
128
Page 88 of 274
www.kerrneltech.com
So now we got the calculation done and we came to know that 25 LEs are required to
create 400MB of LV.
#lvcreate -I <no. of LE> -n <name for the LV> <volume group name>
#lvcreate-i 25 -n kth/2 ktvg2
[root@ktlinux ~J# |
Now check the size of the LV
#lvdisplay ktvg
LV UUID
/dev/ktvg2/ktlv2
|ktvg2 |
t83rmU-kk2z-I83a-BXpo-18LH-aDM8-FeFliW
LV Write Access
read/write
LV Status
available
# open
LV Size
460.00 MiB
Current LE
125
Segments
Allocation
Read ahead sectors
auto
inherit
- currently set to
256
Block device
253:5
The only difference in a normal installation and LVM installation is that instead of creating
normal partition we will create a VG andthen LVs forall partitions, except /boot and swap.
The advantage of installing Linux using LVM is that, ifany ofsystem partition is running out
of space and required more space, in case of normal partitioning it is not possible to
increase the size of a partition once it is created. But, using LVM the space can be
LVM ensures the possibility of increasing and decreasing the sizes whenever required and
prevents unnecessary loss of time.
Page 89 of 274
www.kerrneltech.com
jp\
Start the installation normally as done previously, but only at the time of partitioning follow
the steps below.
:
(MB) RAJWV
P HardCnvci
"
vda
Create storage
Oeate fertstion
O Standard Partition
Information
'; RAJOPartition
information
Create IVM
<".-
' >
Create
Reset
Select the Free space and click on Create, then select LVM Physical Volume and click on
Create to proceed.
**
X S?>
Add Partition
h* Hard Drives
v
vda
Mount Point
Allowable Drives:
Si?e (MB):
125000,
AdditionalSize Options
S Fixed size
-: rypt
Cancel j
gk
Give the maximum possible size to this PV, as all the partition has to be created inside it
only.
Page 90 of 274
www.kernieltech.cuni
Size
":
Free
Mount Point/
'.-
. ' ;- .
'
IS95S
create storage
Create Partition
C Standard Partition
information
t RAID P.
Create LVM
Information
Cancel
j Create
Qreate
Edit
: i -
Reset
Select the created PV, i.e., vdal and this time check the box beside LVM Volume Group to
create a volume group.
Drive /dcv/vda (4096Q MB) (Modal: V)rtk> Block Davlco)
Size
Mount Point/
(MS)
RAID"*"''""-*
Type
Format
vg_ktcl3
physical Extent:
4 M3
S3 vdal
25000 00 MB
Used Space:
0.00 MB (0.0%)
Free Space:
24996.00 MB (100.0%)
Total Space:
24396.00 MB
Logical Volumes
:/
D Encrypt
'T.--J
Q<
Create
Edit
Delete
Beset
Click on Add button to start adding LVs, Select a mount point and assign a size to it and click
on OK
Page 91 of 274
www.kerrnelrecli.com
Repeat the above step and create the following partitions with the given sizes
/usr with 8.5 GB approx
/var with 4.5 GB approx
/opt with 2 GB approx
/, /tmp, /home 2 GB each approx
/opt 3 GB approx
Note: All the sizes listed above are based on the availability of the space. It is no where a
recommended or minimum sizes. The sizes can be based on your requirements. But /usr
required the above given size if it is 64 bit architecture.
E d i t i_vrvi v o l u m e G r o u p : vg_lctc:l3
Volume Group Nnnie:
Physical Extent:
ED
vdal
2 5000.00 MB
9
u s e d Space:
2 2 0 0 0 . 0 0 MB
2996-OOMB
Free Space:
Total Space:
Uogical Volumes
(38.0 %)
(12.0%)
24996.00 MB
9
9
Cancel
S2K
vg_ktcl3
24996
LogVo'05
3000 /opt
ext4
Logvoi04
4500 /'var
BXt4
Log .oiOl
2000 /home
art*
LogVoiOO
2000 /
ext4
s
/
LogvbKH
8500 /usr
ext4
Logvol02
20C0 /tmp
e>t4
Free
2996
9
9
Hard Drives
v
vda
vdal
25000 vgjctcl3
jfrMmHJHJilUlllll 'Hill
Create
Reset
Select the Free space under Hard Drives and create /boot with 200 MB and /Swap with
2GB. Make sure that you select Standard Partition this time, instead of LVM.
Page 92 of 274
www.kerrncItccii.coni
0s
0\
Please Select A Device
Device
Type
Format
24996
3000/opt
ext4
4500/var
ext4
2000 /home
ext4
ext4
LorjVolOO
2000 /
LogVolOl
8500 /usr
ext4
LogVol02
2000 /tmp
ext4
Free
2996
Hard Drives
^
vda
!-. .".,:
vdal
vda2
vda3
Free
25000 vgjctcl3
200/boot
2048
physicalvolume (LVM)
ext4
swap
J
J
13711
c^ftext
Verify the sizes and click on Next to continue with the installation. Complete the installation
as usual as we have done previously at the beginning of the course.
0s
sIPn
Practice the LVM Concept well; as it isthe most important part in Linux and
in any UNIX operating system as welK
www.kerrneltech.com
In Linux/Unix user is one who uses the system. There can be at least one or more than one
users in Linux at a time. Users on a system are identified by a username and a userid. The
username is something that users would normally referto, but as far as the operating system is
concerned this is referred to using the user id (or uid). The username is typically a user friendly
string, such as your name, whereas the user id is a number. The words username and userid are
often (incorrectly) used interchangeably. The user id numbers should be unique (one number
per user). If you had two usernames with the same user id, effectiyeiy.there permissions would
be the same and the files that they create would appear to have been created by the same
user. This should not be allowed and the useradd command will not allow usernames to share
the same userid.
Users and groups are used to control access to files and resources
Users login to the system by supplying their username and password
Every file on the system is owned by a user and associated with a group
Every process has an owner and group affiliation, and can only access the resources its
owner or group can access.
Every user of the system is assigned a unique user ID number (the UID)
Users name and UID are stored in /etc/passwd
User's password is stored in /etc/shadow in encrypted form.
Users are assigned a home directory and a program that is run when they login (Usually a shell)
Users cannot read, write or execute each other's files without permission.
TYPE
EXAMPLE
USER ID (UID)
GROUP ID
HOME
(GID)
DIRECTORY
SHELL
Super User
Root
/root
/bin/bash
System User
ftp, ssh,
1 to 499
1 to 499
/var/ftp, etc
/sbin/nologin
500 to 60000
500 to 60000
/home/user
/bin/bash
apache
nobody
Normal User
Visitor,
ktuser,etc
name
Page 94 of 274
www.kerrneltech.com
r#"
0^
Super user or the root user is the most powerful user. He is the administrator user.
2. System user
System users are the users created bythe softwares orapplications. For example ifwe install
Apache it will create a user apache. These kinds of users are known assystem users.
3. Normal user
Normal users are the users created byroot user. They are normal users like Rahul, Musab etc.
Only the root user has the permission to create or remove a user.
0$\
It means that whenever a user is created ishas its own private group
For Example ifa user is created with the name Rahul, then a primary group for that user will
be Rahul only
There are two important files a user administrator should be aware of.
1. "/etc/passwd"
2. "/etc/shadow"
Each of the above mentioned files have specific formats.
1. /etc/passwd
JIN
bin:x:1:1:bin:/bin:/sbin/nologin
The above fields are
root =name
www.kerrnelrech.com
/sips
2. /etc/shadow
root:$lfdsfsgsdfsdkffefje:14757:0:99999:7::
The fields are as follows,
1. root = User name
2. :$lfdsfsgsdfsdkffefje = Encryptedpassword
3.14757 = Days since that password was last changed.
4.0 = Days after which password must be changed.
5.99999 = Days before password is to expire that user is warned.
6.7 = Days after the password is expires that the user is disabled.
7. A reserved field.
A root user can change password of self and of any user in the system, there are no rules for
root to assign a password. Root can assign any length of password either long or short, it
can be alphabet or numeric or both. On the whole there is no limitation for root for
assigning a password.
A normal user can change only its password. Validpassword for a normal user should adhere to
the followingjules
>f
m$k
r^i|
Note: For security reasons don't keep the password based on date of birth because it can easily be
hacked.
LABWORK:-
Creating a user
-G Secondary group id
-g primary group id
-d home directory
-c
comment
-s
shell
Page 96 of 274
www.kerrneltech.com
When no option is used with useradd command the options like UID, GID, home dir and
shell will be assigned default.
#useradd <usemame>
#useradd ktusr
[rootSktlinux ~]# |
Observe that the uid, gid, home dir, and shell is assigned automatically.
Ler/s create a user with our own attributes
salesman
named:x:25:25:Named:/var/named:/sbin/nologin
ktusr:x:502:503::/home/ktus r:/bin/bash
ktuser2:x: 505:505: salesman:/home/kernel:/bin/bash
[rootSktlinux -]# |
Page 97 of 274
www.kerrneltech.com
^k
"^Sll
^k
[rootSktlinux ~]# |
After creating a user if we need to modify the attributes of user like changing uid, changing
secondary group id or adding a comment, locking or unlocking the user account, can be
done by following command
Syntax.
# usermod <options> <username>
options are:
all the options which are used with useradd command can be used and also the following,
to change login name
-I
-L
to LOCK account
-U
to UNLOCK account
Note: - when an account is locked it will show! (Exclamation mark) in /etc/shadow file.
Page 98 of 274
www.kernieltech.com
/s^j|
#usermod-L ktuser2
Verify it in /etc/shadow file, it shows exclamation mark before user a/c or try login as
ktuser2
[rootSktlinux ~J# usermod -L ktuser2
pulse:!!:14923::::::
gdm:!!:14923::::::
sshd:!!:14923::::::
tcpdump:!!:14923::::::
ktuser2:! ^6$sygiWqG7$uTphGmvQhScKQ8acThAMhb3uGiK9eRNBuBV4al
. bhMNMZQA6GStxPlXSRyeTpKph.: 15250:0:99999:7:::
[rootSktlinux ~]# |
tfusermod -U ktuser2
Verify it in /etc/shadow file, it shows exclamation mark before user a/c or try login as
ktuser2
gdm:!!:14923::::::
sshd:!!:14923::::::
tcpdump:!!:14923::::::
visitor: $6$0NwZFaSl6WerWm2i$ULgPWbt3. E8Ge.6jwTDQKTaQLvX5i
8Kiq)/6rq9DPlxelZIFyM6Mbwhy35GGem0:14923:0:99999:7:::
ktuser :S6S6iAEv8c9$i9vTJaLPwD0uCuMIm6S2I7k3KdfAJktHGNBlakl
ecLDS3DAOvq074OFwIUXyWS2/: 15234:0:99999:7:::
named:!!:15239::::::
ktusr:! 1:15250:0:99999:7:::
ktuser2: S6$XbHuW6gS$NO4lvd4XbZ76ZdvZFIUXxwBhQO80sshf664zgi
asNnhz0zDKrt39Q5OJZnKaj6G1:15254:0:99999:7:::
[rootSktlinux ~]# 9
Observe in both pictures that once the account is unlocked the exclamation is gone.
Page 99 of 274
www.kerrneltech.com
For any user we can set the parameters for the password, like min and max password age,
password expiration warnings and a/c expiration date etc.
To view the advanced parameters of the user, use
#chage -l<username>
#chage -I ktusr
never
Password inactive
never
Account expires
never
: 0
: 99999
: 7
[rootSktlinux ~]# |
Last password change: When the password was change last time.
Password expires: Password expiry date
y?
Password inactive: After password expiry grace period before the account gets locked.
Account expires: Date on which the account expires.
Minimum number of days b/w password change: once the password is changed, it cannot
be changed until a min period of specified date. [0] means never.
Max number of days b/w password change: After changing the password how long it will
be valid for.
Number of days of warning before password expires: start of warnings to change the
password, no. of days before the password expires.
Password inactive [-1]: 0 same day account is locked after password expiry.
'1^
/5%
/^Sk
tfchage ktusr
Oct
Oct
Oct
Dec
Password inactive
Account expires
03,
10,
10,
31,
2011
2011
2011
2011
2
7
2
[rootSktlinux -]# |
The second method is for, if you want to change a particular field of password aging policy
#chage <option> <value> <username>
The options which can be used are as follows
-m for Min password age
-M for Max password age
-d for last time the password is changed.
-W Password expiration warnings
-I Password inactive [-1 means inactive).
-E A/C expiration date
Password inactive
Oct 10,
Recount expires
2011
2
2
[rootSktlinux -]# |
Likewise you can use any option listed above and change any particular field in password aging
parameters.
www.kernieltech.com
.MWSH
/^ji
/^%
Deleting a User:
ktuser
- kernell
- kernel2
- kernel3
- kernel4
- kernels
ktusr
lost+found
visitor
/^ii\
4 directories, 5 files
[rootSktlinux ~]# |
/^k
We're now done with user administration, let's see what's in part-11
/^^
GROUPS
JPN
All users inagroup can share files that belong to the group
Each user isa member ofat least onegroup, called a primary group. In addition, a user can be a
member of an unlimited number of secondary groups. Group membership can be used to
control the files that a user can read and edit. For example, if two users are working on the
same project you might put them in the same group so they can edit a particular file that other
users cannot access.
A user's primary group is defined in the /etc/passwd file and_Secondary groups are defined
in the /etc/group file.
The primary group is important because files created by this user will inherit that group
affiliation.
#groupadd ktgroup
tcpdump:x:72:
slocate:x:21:
visitor:x:500:
ktuser:x:581:
named:x:25:
ktusr:x:503:
(fP^
lktqroup:x:504:|
[rootSktlinux Desktop]* |
www.kerrneitech.com
0^
Verify it in /etc/group
[rootSktlinux Desktop]* groupadd -g 595 ktgroup
[rootSktlinux Desktop]* tail /etc/group
stapdev:x:491:
stapusr:x:490:
sshd:x:74:
tcpdump:x:72:
slocate:x:21:
visitor:x:500:
ktuser:x:501:
named:x:25:
ktusr:x:503:
ktgroup:x:595j
[rootSktlinux Desktop]* |
-';-v
=K..,--I
Verify it in /etc/group
[rootSktlinux Desktop]* groupmod -g 688 ktgroup
[rootSktlinux Desktop]* tail /etc/group
stapdev:x:491:
stapusr:x:490:
sshd:x:74:
tcpdump:x:72:
slocate:x:21:
visitor:x:500:
ktuser:x:501:
named:x:25:
ktusr:x:503:
ktgroup:x:600: |
[rootSktlinux Desktop]* |
/9^
Addingthe members to the group is to add users to the group. To add the members to the
[rootSktlinux Desktop]* |
Adding multiple single or multiple users to the group with various attributes
#gpasswd < option> orgumentsxgroup name>
Options:
M ktuser2,ktuser3,ktuser4 ktgroup
/etc/group
ktusr:x:503:
ktuser2:x:601
ktuser3:x:504
ktuser4:x:505
ktg roup:x:600 :jktuser2, ktuser3,ktuser4
[rootSktlinux Desktop]* |
Page 105 of 274
www.kerrneltech.com
j$^
/3m
[rootSktlinux Desktop]* |
/mm
[rootSktlinux Desktop]* |
Removing a user from the group
#gpasswd -d ktuser2 ktgroup
[rootSktlinux Desktop]* grep ktgroup /etc/group
ktgroup:x:600 :!Ktuser2i ktuser3, ktuser4, ktuser
[rootSktlinux Desktop]* gpasswd -d ktuser2 ktgroup
Removing user ktuser2 from group ktgroup
[ rootSktlinux Desktop]* grep ktgroup /etc/group
ktgroup:x:600 : ktuser3, ktuser4, ktuser
[ rootSktlinux
Desktop]* |
To add and remove groups use can also use the graphical tool in linux
#system-config-users &
H:~:'&*
Add User
hMp
dfe
Add Group
5&
Pf-operr.ls
Refresh
r^eiec
Help
Search filter: f~
Apply filter I
Users |^r>jpsj
User Name
visitor
SOO
ktuser
visitor
r*faLT>^8 ktuser
| Full Nome
visitor
Login Shell
Home Directory
/bin/bash
/home/visitor
/bin/bash
/home/ktuser
/bin/ bash
/home/ktusr
/bin/bash
/homc/ktuser2
ktusr
502
ktuser2
503
'\*ktuser2
ktuserS
504
ktuser3
/bin/ bash
/home/ktus era
ktuser-4
/bin/bash
/ h o m e / k t u s er4
ktusr
/^^
/^i^
There are three special permissions that can be assigned to a file or directory apart from
basic file permissions(rwx), they are
SUID-SETUSERID
SGID-SET GROUP ID
STICKY BIT
Permission
Symbolic Form
Numeric Form
Syntax
SETUID
s orS
SETGID
sorS
STICKY BIT
torT
Note: Where s= setuid + execute permission and S= setuid only. Same is for SGID and also for
sticky bit.
SUID-SETUSERID
Change user ID on execution. If SETUID bit is set, when the file will be executed by a user, the
process will have the_35me_rjghts_as_the owner of thejjle being_executed. Many of the system
commands are the best example for SUID, basically the owner of the commands will be root,
but still a normal user can execute it-
Example
By default ping command is haying suid, so all users can run that command but if suid is
removed and a normal user wants to user execute it, then it will show 'operation not
permitted'
2010 HiHiWiCTiEl
[rootSktlinux Desktop]* I
Note: observe that in the permissions "-rwsr-xr-x" it contains an "s", which means SUID is
placed.
Let's remove suid on Ping command and logged in as normal user and check the results
[rootSktlinux Desktop]# chmod u-s /bin/ping
[rootSktlinux Desktop]* su - ktuser2
[ktuser2S!<tlinux ~]s ping 192.168.10.95
ping: icmp open socket: Operation not permitted
[ktuser2Sktlinux -]5 fl
Page 107 of 274
www.kerrneltech.coni
9
9
SGID-SET GROUP ID
Sgt group,ID. used on executable files to allow the file to be run as if logged into the group
(like SUID but uses file group permissions)
SGID can also be used on a directory so that every file created in that directory will have the
directory group owner rather than the group owner of the user creating the file:
Example
When a directory is created and its group is set to some group. Now if SGID is applied to it,
and the group member creates files and directory inside it, then it will get the same group
rather than getting user's primary group
Let's see it practically.
8 07:32 ktsdir
ktsdir
total 0
-rw-rw-r-- 1 ktuser3 ktgroup 0 Oct
8 07:34 filel
ktgroup
-rw-rw-r-- 1 ktuser3 ktgroup
-rw-rw-r-- 1 ktuser3 ktgroup
0 Oct
8 07:34 file2
Oct
8 07:34 file3
Oct
8 07:34 file4
8 07:34 files
-rw-rw-r-- 1 ktuser3
Note: when a file is created by any user it will get the group as primary group of the owner
which is usually owner's private group with same name.
STICKY BIT
If sticky bit is applied on a file or directory, then only root and owner of that file or directory can
dejfitesit. Even if others are having full permissions they cannot delete the file or directory..
file2
file3
file4
file5
rm:
&
H*f
<Q\
Often, you want to share files among certain groups and specific users. It is a good practice
to designate a directory for that purpose. You want to allow those groups and users to read,
and write files in that directory, as well as create new files into the directory. Such special
msdos
File system
210MB
Type
primary
primary
ext4
4194MB
primary
linux-swap(vl)
Start
End
Size
1049kB
31.5GB
31.5GB
31.5GB
31.7GB
31.7GB
35.9GB
35.9GB
53.7GB
17.8GB
extended
35.9GB
36.4GB
534MB
36.4GB
36.9GB
535MB
logical
logical
36.9GB
37.5GB
535MB
37.5GB
38.0GB
535MB
Flags
Ivm
boot
linux-swap(vl)
logical
logical
[rootSktlinux -]# |
PaRe 109 of 274
www.kerrneltcch.com
/Kernel
ext4
r*dev/sda6
del aults
swaD
'dev/sda7
/ktdir
ext4
G 0
1.
'f -
o ofl
!f your partition already exists, then just add an ac! after defaults as shown above and use
Sis-Id /ktdir
-R
#getfacl /ktdir
[rootSktlinux -]# Is -Id /ktdir
drwxr-xr-x 3
file:
ktdir
# owner:
root
# group:
root
u s e r : : rv/x
group::r-x
other::r-x
Now let's assign full permission to the directory and then apply acl on it, so that we can
analyze how acl will work.
root
[rootSktlinux -]# J
Okay, now we are ready to apply acl, but first lets understand the command and option in
-m Modifies an ACL
-x Removes an ACL
details.
g: group
o: others
Note: Whatever ACL permissions assigned to a user or group or others, it will be treated as
Normal Permissions minus ACL
To assign read and execute permission to a particular user the syntax could be
#setfacl -m u: <usemame>: <permissions> <file or dir name>
file:
owner:
ktdir
root
group: root
u s e r : : rwx
|user:ktuser: r-x |
group:: rwx
mask::rwx
other::rwx
Now login as ktuser and try to create a file inside ktdir, as we have not assigned write
permission to ktuser, though it is having full permissions, still it will not allow ktuser to
create a file inside it.
[ktuserSktlinux ktdir]s j
Observe that when you check for the permissions it is showing a + sign after normal permission,
that indicate that ACL is applied on this directory.
www.kerrneltech.com
-<.
ktdir
# owner:
root
# group: root
user:: rv/x
user:ktuser:r-x
group: :rwx
other:: rwx
Now you know how to apply acl on any file or directory, let me just give one more examples
which you can broaden your understandings.
Assigning read and execute permission for a user and a group at same time.
#setfacl-m u:ktuser:rx,g:ktgroup:rx/ktdir
[rootSktlinux /]# setfacl -m u:ktuser:rx,g:ktgroup:rx /ktdir
[rootSktlinux /]# getfacl ktdir
# file:
ktdir
r
owner:
root
# group: root
user:: rwx
other:: rwx
Likewise you can explore applying acl to any user, group, or others in many ways.
Removing acl for a particular user
ktdir
# owner:
root
# group: root
user: :rv/x
group: :rwx
/Wij&j,
p^
JP*
# group: root
user:: rv/x
group::rwx
mask::rwx
other::rwx
#setfacl-b /ktdir
"
As we have removed acl for a group and a user, let's apply back some acl on ktdir and remove
it using above command
/lp\
root
# group: root
user:: rwx
user:ktuser:r-x
group::rwx
group:ktgroup:r-x
mask::rwx
other::rwx
# group: root
user:: rwx
group::rwx
other::rwx
[rootSktlinux /]#
ACL can also be applied to a file in exactly similar fashion aswe did for adirectory.
This part confirms the end of USER ADMINISTRATION
www.kerrneltech.com
Media
3. Topology
4.
Protocol
5.
IP Addresses
1.
Media
Media is the medium via which two different,computer^ NIC card will be connected. The
Topology
to each other. Example for topology is Bus, Ring, star, mesh, trg_topologies. The following
pictures explain it better.
^
i
a
^
Bus Network Topology Ring Network Topology $tar NetworkTopoIogy Mesh Network Topology
www.kerrneItccli.coni
4.
Protocol
Network protocols include mechanisms for devices to identify and make connections
with each other, as well as formatting rules that specify how data is pa^^edJDtojRessagos,
Hundreds ofdifferent computer network protocols have been developed each designed for
specific purposes and environments.
Example for Protocols are TCP/IP (Transmission Control Protocol), UDP (User Datagram
Protocol), HTTP. The most widely and regularly used protocols for transferring data are TCP
and UDP. Let's analyze some basic differences between TCP/IP and UDP.
UDP
It is connection Oriented
Connectionless
Reliable
Non-Reliable
Slow Communication
Faster Communication
5.
TCP/IP
Transmission Control Protocol
IP ADDRESS
An IP address can be thought of as being similar to a phone number. Just as every person who
communicates with a telephone is using a phone with a unique phone number, every computer that
is on the Internet has a unique IP address. Not only on internet but within an organization every
computer is assigned an IP address so that they can communicate with each other. Basically IP
addressing is very deep concept. To understand the concept of IP address we need to understand
some important aspect of IP Address which is
IP Address Classes
Subnet mask
Gateway
The above concepts in IP Addressing are very important to understand networking clearly.
www.kerrncltech.com
IP Address Classes
The IP addresses are further broken down into classes. These classes are A, B, C, D, E and their-possible
ranges can be seen in Figure below.
End
Start
Class
CIDR
Class A
0.0.0.0
127.235.255.255
255.0.0.0
Class B
128.0.0.0
19U55.255.255
255.255.0.0
/16
Class C
192.0.0.0
223.255.255.255
255.255.255.0
Class D (multicast)
224.0.0.0
239.255JJ55.255
Class E (reserved)
240.0.0.0
255.255255.255
A special IP number (127.0.0.1), that is designated for the software loopback interface of a
machine, 127.0.0.0 Through 127.255.255.255 is also reserved for loopback and is used for
internal testing on local machines.
Multicast
Subnet Mask
A subnet mask allows users to identify which part of an IP address is reserved for the network
and which part is available for host use. By looking at the IP address alone, especially now with
classless inter-domain routing, users cannot tell which part of the address is which. Adding the
subnet mask or netmask gives users all the information needed to calculate network and host
portions of the address with ease. In summary, knowing the subnet mask can allow users to
easily calculate whether IP addresses are on the same subnet or not.
255.
255.
255.
Binary:
11111111
11111111
11111111
00000000
Netmask length
16
24
Gateway
Ajateway is a network point that provides entrance into another network. On the Internet, a
n_o.de-PX_stopping point can be either agateway node or a hostjend-point) node. Both the
cgmp'-'ter-s of jntprnet users and the computers that serve pages to users are host nodes. The
computers that control traffic within your company's network or at your local Internet service
provider (ISP) are gateway nodes.
For example let's say our network is 192.168. something and we want to
sdii
ifdown-post
ifdown-ppp
ifdown-bnep
ifdown-routes
ifdown-eth
ifdown-sit
ifdown-ippp
ifdown-ipv6
if down-tunnel
ifup-aliases
ifup-bnep
ifup-eth
ifup-ippp
ifup-ipv6
ifup
ifup-plip
ifup-plusb
ifup-post
ifup-ppp
ifup-routes
ifup-sit
ifup-tunnel
ifup-wireless
init.ipv6-global
net.hotplug
network-functions
network-functions-ipv6
fl/jJgAyS-CO_nfig/network is a file which keeps the information about the hostname assigned to
the system. If you want to change the hostname permanently, you need to change the
hostname in this file.
[rootSktlinux -]# |
#/etc/hosts a file which is responsible for resolving hostname into IP locally, in other word it
acts as local DNS if DNS server is not accessible.
'
192.163.10.98
127.0.0.1
localhost.localdomain
::1
ktlinux.kt.com
localhost
#/etc/reso.v.conf is a file which keeps the address of DNS server to which the clients will be
# Generated by NetworkManager
search kt.com
Inameserver 192.163.10.98 |
"
www.kcnneltech.com
9
LAB WORK:-
Mask:255.255.255.0
MTU:1500
Metric:1
inet6 addr:
Mask:255.0.0.0
::1/128 Scope:Host
UP LOOPBACK RUNNING
MTU:16436
Metric:1
#ifconfig ethO
[rootSktlinux -]# ifconfig eth
Link encap:Ethernet HWaddr 0O:0C:29:3C:2F:15
eth
inet addr:192.168.10.98
Bcast:192.168.10.255
9
Mask:255.255.255.6
MTU:1500
Metric:1
collisions: txqueuelen:100Q
ktlinux.kt.com
www.kerrneltech.com
f^
\>m
192.168.10.98
Address:
192.168.10.98#53
98.10.168.192.in-addr.arpa
98.10.168.192.in-addr.arpa
name =
kt.com.
name = linux.kt.com.
192.168.10.98
Address:
192.168.10.98#53
Name:
ktlinux.kt.com
Address:
192.168.10.98
answer:
IN
;; ANSWER SECTION:
ktlinux.kt.com.
10800
;; AUTHORITY SECTION:
ktlinux.kt.com.
10300
192.158.10.98
IN
NS
ktlinux.kt.com.
www.kerrneltech.com
L.
*<*Q
With ip address
#dig -x <ip address>
\?
f-
9
9
#dig-x 192.168.10.98
[rootSktlinux -]# dig -x 192.163.10.98
;; QUESTION SECTION;!
;98.10.168.192.in-aftdr.arpa.
IN
PTR
;; ANSWER SECTION:
98.10.168.192.in-addr.arpa. 10800 IN
98.10.168.192.in-addr.arpa. 10300 IN
PTR
linux.kt.com.
kt.com.
NS
linux.kt.com.
PTR
;; AUTHORITY SECTION:
10.168.192.in-addr.arpa. 10300
IN
9
ms
ms
ms
ms
ms
AC
--- 192.168.10.95 ping statistics --5 packets transmitted, 5 received, 0% packet loss, time 4431ms
9
9
[rootSktlinux -]# |
Note: The above change is temporary and will be last only till you are logged in, if you want to
change it permanently edit the /etc/sysconfig/network file and then logout and login to
confirm the change.
'
J
#vim /etc/sysconfig/network delete the previous hostname and add the new name.
NETV/ORKING=yes
HOSTNAME=kernellinux.kt.com
l|root(ckernelLinux H# hostname
kernellinux.kt.com
[rootSkernellinux ~]# ]
Note: Once you logout and login again the change will be permanent, observe the highlighted
region above.
Assigning /Changing the IP Address
Steps for changing the IP Address.
y#setup or #system-config-networkj
It will open a texfbase utility follow the steps below and change the ip address
Restart the network service to apply the changes
Firewall configuration
Keyboard configuration
Network configuration
RHN Register
System services
v-rS^v, j
.. ,-^6
Device
configuration^
- ..:-'<:.'
\
1
\
1
Save&Quit
i
1-
IIbIi
w
M-...,
Now select the NIC adapter i.e. ethO and press Enter
Network Configuration
Name
Device
Use DHCP
Static IP
isk
Default gateway IP
Primary DNS Server
Secondary DNS Server
192.163.10.93
eH
Assign the above ip address and other details as per your requirement, move the cursor to
"OK" and press Enter
; Select A Device j
etho (ethO) - v-l,ri-e vmxnetj Ethernet Controller
Move the cursor to "save" to save the changes in device configuration and press Enter.
Select Action
peyice configuration
DNS configuration
Once again move the cursor to "Save&Quit" button and press Enter
1 Choose a Tool |
Authentication configuration
Firewall configuration
Keyboard configuration
Network contiquration-:
RHN Register
System services
Finally Move the cursor to "Quit" button and Press Enter to quit the utility.
Page 123 of 274
www.kerrneltech.com
Now restart the network service and check for the ip address
^service network restart
If the change is not reflected with above service restart, restart the networkjnanager
^service NetworkManager restart (N and M are case sensitive)
[[email protected] Desktopj# service network restart
Shutting down interface ethO: Device state: 3 (disconnected)
OK
[
[
OK
OK
]
]
OK
ok
OK
[ OK
Mask:255.255.255.0
9
9
The above picture confirms that we have successfully assigned an IP address to a machine.
You can also check the functioning of newly assigned IP address by pinging it from other
If it is not pinging from outside then check whether the cable is connected properly or
not.
If the server is in the remote location use #mii-tool to check whether the cable is
connected or not
[rootOkernellinux
Settings
-for
Desktop]**
ethtool
ethO
ethO :
Supported
Supported
9
9
[root@kernellinux]# mii-tool
ports:
[ TP
"Link modes:
]
lOOObaseT/Full
lQOOObaseT/Full
Advertised
auto-negotiation:
No
Speed:
lG0O0Mb/s
Duplex:
Full
Port:
Twisted
PHYAD:
Pair
Transceiver:
internal
Auto - n e g o t i a t i o n :
HDI-X:
Supports
Wake-on:
Wake-on:
Link
off
Unknown
v e s
uag
9
9
SELinux is a security enhancement to Linux that allows users and administrators more
control over which users and applications can access which resources, such as files.
Standard Linux access controls, such as file modes (-rwxr-xr-x) are modifiable by the
user and applications that the user runs, whereas SELinux access controls ajp
determined by a policy loaded onjhe system and not changeable by careless users or
misbehaving applications.
SELinux also adds finer granularity to access controls. Instead of only being able to
specify who can read, write or execute a file, for example, SELinux lets you specify who
can unlink, append only, and move a file and so on. SELinux allows you to specify access
to many resources other than files as well, such as network resources and inter-process
communicationjipc).
SELinux provides a flexible Mandatory Access Cantml (MAC) system built into the Linux
files, sockets, and other processes. Running a MAC kernel protects the system from
malicious or flawed applications that can damage or destroy the system. The following
picture explains more detailed about both Access controls.
wwvy.kerrneltech.com
Action
Request
Permission
Granted ?
feq:read)
No
SELinux
Policy
Database
configuration file i.e. /etc/seiinux/config file. Well we'll see it later in this chapter.
[rootSktlinux ~]# cat /etc/selinux/config
7 This file controls the state of SELinux on the system.
7
SELINUX=
t
enforcing - SELinux security policy is enforced.
7
permissive - SELinux prints warnings instead of enforcing.
7
7
one of these
two values:
SELINUXTYPE=targeted
Page 126 of 274
v.kerrneltech.com
Modes of SELinux
Enable and enforce the SELinux security policy on the system, denyingaccess and
logging actions
Permissive
Permissive mode is similar to Debugging Mode. In Permissive Mode, SELinux policies and
rules are applied to subjects and objects, but actions ( for example, Access Control denials)
are not affected. The biggest advantage of Permissive Mode is that log files and error
messages are generated based on the SELinux policy implemented.
Disabled
SELinux is turned off and no warn and log messages will begenerated and stored.
Booleans
Booleans are variables that can either besetas trueorfalse^ Booleans e_nhanc_ihe effect of
SELinux policies by letting the system administrator finetune a policy. Apolicy may protect
a certain daemon or service by^agplying various access coj^rol^mlps |n real world scenarios,
a system administrator would not like to implement all the access controls specified in the
DO liny.
SELinux Policy
The SELinux Policy is the set of rules that guide the SlLinjJx.seaLrJiy_engine. It defines types
for file objects and domains for_prorpss5.. It uses roles to limit the domains that can be
entered, and has user identities to specify the roles that can be attained. In essence, types
and domains ar^equjyalent, the difference being that types apply to objects while domains
apply to processes.
SELinux Context
Processes and files are labeled with a SELinux context that contains additional information,
such as a SELinux user, role, type, and, optionally, a level.
www.kerrneltech.com
9
LAB WORK:-
trgetenforce
[rootSktlinux ~]# |
#sestatus
SELinux status:
SELinuxfs mount:
/selinux
Current mode:
enforcing
entorcmg
24
targeted
[rootSktlinux ~]# j
Display the SELinux context of a file or directory.
To display the context of a file the syntax is
#ls-Z<filename>
[rootSktlinux -]# Is
anaconda-ks.cfg
Desktop
Documents
Downloads
^___^_^
install.log
I ktfile I Pictures
install.log.syslog Music
Public
Templates
Videos
[rootSktlinux -]# |
To display the context of a directory the syntax is
[rootSktlinux -]# |
9
9
ep http
[rootSktlinux -]# ]
_______
Page 128 of 274
www.kerrncltech.com
9
9
Observe that the type is admin_home_t, let's change it to public_content_t, so that it will be
available for all users.
[rootSktlinux ~]# |
'
[rootSktlinux ~]# Is
IdZ ktdir
root root systemu:obj ectr:adminhomet:s0 ktdir
[rootSktlinux ~]# Is IZ ktdir
drwxr-xr-x.
-rw-r--r--.
root
root
system_u:object_r:admin_home_t:sO filel
-rw-r--r--
root
root
-rw-r--r--
root
root
-rw-r--r--
root
root
systemu:object_r:adminjiomet:sO file4
-rw-r--r--
root
root
[rootSktlinux ~]# I
ktdir
rootSktlinux ~]# I
www.kerrneltech.coin
home
sB ktfile
[rootSktlinux ~]# |
To restore back the same of a directory with its contents, the syntax is
#restorecon -Rv <dir name >
tfresotrecon-Rv ktdir
N-->
-rw- r- -r-
'R"
in the
command.
enabled
/selinux
|permissivel
\ >->'
enforcing
24
targeted
[rootSktlinux -]# |
To change the SELinux Mode back to Enforcing mode
#setenforce 1
enabled
/selinux
^enforcing |
enforcing
24
targeted
[rootSktlinux ~]# |
wwiv.kerrneltech.com
First check the current status of SELinux and the configuration file.
[rootSktlinux -]# getenforce
Enforcing
[rootSktlinux ~]# cat /etc/selinux/config
#
#
#
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
//^5\
#
targeted - Targeted processes are protected,
#
mis - Multi Level Security protection.
SELINUXTYPE=targeted
Now, edit the configuration file, restart the computer and check the status.
#vim /etc/selinux/config
#
#
^ELINUX=disabled]
^j|
#
targeted - Targeted processes are protected,
#
mis - Multi Level Security protection.
SELINUXTYPE=ta rgeted
[rootSktlinux ~]# getenforce
Disabled
disabled
[rootSktlinux ~]# |
To Enable it back the procedure is exactly same as above, instead of SEUNUX=disabled change
it to SELINUX=enforcing or permissive. Don't forget to restart the system, unless the system is
rebooted the changes will not take effect.
tm