Linux Notes-9
Linux Notes-9
th y trametecticated
place directory
at echo
ftp.int
uptime
echo n hello
hello 3 hello will be printed without any trailing
line
Commandtypes
Type commandname 7
Gives the type ofcommand Internalbuiltin Enternal
echo n hello
Gkommand
named fption argument
Eh shelf
Thereshells
Bourne shell ish I may have diff
core
Shltype C Shel esh or teshl capabilities
Korn shell Ksh But main purpose is to
2 Shell 2sht facilitate communication
Bourne againshell Bash b w user and 0
echo SHE'll
will give the current shell default shell
ansh
Password
features of Bash
alias at date
3 history
will give the details of commands that you ran previously
Variables
fecho Kvaniablename
kill output the value of variablename provided
g en
lists the variables and their corresponding values
export variablenames avalue to assign
This sets the variable for current shell and forany
other programmes procera started by shell
variablename valueto assign
This apply to variable within the shell not applied
to other procend programmes value won't be carried forward
PathVariable
Iver issues an external command into the shell The
shell uses a path variable to search for there external commane
echo PATH
shows the directories defined in path variable
echo 151
7
upon running psi it shows present working directory
homegirish
LS I list conents
mamey dirname
Mkdir p hair
This will create ni and then na inside n
Cd the home
will move directory
Cd
Cd homegirish
Y
ed homegirish name 7 Absolute path
my isoirilitath holutinationtepath
my sourcepathwithwrongnamedirectly Destination
path correctnamediver
Used to rename the given directory name a file name
rm k pathoffileto remove
will remove file directory in given path
cat filepath
content in the given file at given filepath will be displayed
TIED
To emit out of the prompt and save data
QI To emit out
Ing
Liste the file in the directory
LS 1 long list
as
offiles
Provides moredetails directories such
Acer model
Ownership
Laitaccededtime
Is a Itlidedenfiled
lists all the filet including hiddenfiles tilstop
a lot
Ihiddenfiles directories precede startwith filename
Commands
tying
whatis command
This will display one line description of what a command
does
apropos keywords
Wmd librarian
the keeps track of books Send notification
before deerdate i e looks after
I i resources their availability allocation
1300kt studtide
penitytation
limiting would so to makethem
available for all
hemby tip ape in
Process management which Proceu can use cpu when where forHowlong
uname r
gives keenal version details
4 15 0 72 generic
4 Keenalversion O Mindversion Genetic Bistrospecific info
Iemoryatnagement Ind
Memory divided
use space
Enigtiminilitate kunal
g space 1
access to and has
1 has Apps Programs
Proceed insidethisspace
has unrestricted arced
to hardware
Kanal code
Eulation
Device driven
userspace
it c
LIII
I s nugent
LUSITH Uden
When USBattacheddata
It
will be visible under
my pay
udevadm monitor
This command listens to thekeenal uevents
upon detecting events it prints ite details
like i device path
2 device name on screen
Command determines the details
of a newly attached 8
removed device
Lspci
display info abt all PCI devices that are configured
in system
peripheral componentInterconnect
Pel
mens
used listsavailable memory in the system
Is mem summary
will list and printsummary of memory
free m
gives total us used memory in system
in Kb
Ishw
Is tool to entra it detailed info on the entire hardware
configuration of the machine
power on
selftest Boot 1
POST Grandunified This calls systemd
BootlodenVersion 2 daemon
Systema is responsible
for bringing Linux host
to usable state
systemd is universal standard Responsiblefor mounting
But now file systems Starting
Another initialization process andmanaging systemsemi
init was used
Syfy
Syst used in RHELG and centOst
Is I Isbin init
www.o.lsbinlinit 7 liblsystemd systemd
This command will output the init system being used
run level
operational mode that provides Graphical
µ g g interface requires displaymanager service
dr wXv Xv 8
command ist letter will tell typeoffile
The output ofabove
The first letter acts as identified
type identified
Divestay y d
so iket s
Regular
Iharacterdevice a
link 1
Pipe p
Blockdevice b
filesystem Inches
1 bin contains basic programmes and binaries such a cp.my
miidin ele
Iboot
É
to be imported into your programs
media u can view data of anyattached externaldevices
susbl
Imnt used Mount file system temporarily in the system
using ment command
put 3rdparty software here if youwant to install
of dpkg
E
DEB Thesemake use
thin
Debian
RHEL VS CENTOS
1 Paid
2 Enterprise offering
3 Technical support I2 community version
Immunity
support
Package
It is a compressed archive that contains all thefiles
that are required by particular software to own
Pelage
nag is a
software in Linux system that
provides consistent and automated process of installing
upgrading configuring and removing packages from Os
functions
1 Ensuring integrityandAuthenticity
ofpackages
2 Simplified Package manament
3 Grouping Package
4 Manage Dependencies
RPM
Fed in
RHEL
CENTOS
Fedora
of operations in RPM
Idc If
Installation Below command is used to install a Package
system
um local eglaptop
ends.mg
Klarehouse Yiimon
4 There can be accessed
by http HTTPS FTP
HIII
Local FTP
package RPM Package
Manager Manages
Stassiinstalling Padages
Yum install apackagename
Y This
flag will help in Skipping Transaction
Summary input
gum repolist
will show all the repos added to your system
1 gum update
To update all the installed packages use this command
Package
Extension jeb
Simerly to
Installation Below command is used to install update a
update package
dpleg i packagename
Itis
Apt update command used to Refresh repository
apt upgrade
at is used to install available upgrades of
all packages currently installed on the system from
sources configured
apt list
APT V3 APT GET
Archiving files
Tay Elity Tape Archive
used to group multiple files directories into a single
file
files created with tar are call tarballs
bunzip2Lfile
enten.bz2 Sgunziphfile.enten.gz
updatedb
will manually update db and should own as
root user
Mfs't
popular command to search within files in Linux
Commonly used to printlines of a file matching a pattern
will print the lines matching pattern and one line below
it
A will these
Simalay By giving the no
oflines often
no of line
iii iii ii
will print the lines matching and one line above
it
airman
no
of lines above it
A1 131 Awad filename
grip
will print the line matching word and one line
above and below the word
IO Redirection
standard
Stalin Accepts txt as input
Input cat sample txt
standard output output printed will be delivered
by stdout thirst
Standard error as errors will be sent bythis stream
IKE EDIT
To redirect standard output to a file instead printing on screen
missingII
This command will write over to given file
If file
doesn't exist it will create new one It already enisle
the file will be overwritten
Command I I command2
I
pipe
In this case commandI output acts as input
for command 2
II EDITOIS
II Edith
Vi Name path offile to Edit create
This command will open the file for Editing
for creating
Modes in v1 Edith
Commandmode
Insert mode
É heused to editfile Addtext Remove text
To enterthismodefrom commandmode we can use keys
0 A I i d o
a Last Line
Lani Id file using I command
Mona You open any to
move around at will be in command mode and
Navigate infile you say we below keys
II IIIa
copy a line 4 Move to particular line and Enter below
E II
a Moveabove line a place in file and Enter below
paste
F
use uppercase 4713 to save
D To
I Did to delete 3 lines u can replace number
with n roof number lives
of
undo Type D to undo change made previsorly
Redo us type
Do to redo change
To find a
string in a file opened on vi editor
use D Id followed
by pattern to Search
I patternto search
This will search downwards from current position line
upon searching cash will move to 1st ocurrence from
the current position
Any upon pressing will give nxt occurrence below the
current line
pattern above current
line
WIT To find the
patient 7 This will be enact opposite reverse
will search upwards from current position line
N key will search word upwards
N key will search it wold downward
Angstmode
you can lay in IT to a
lastline mode
Type in
By this you can make many change bytyping below
Ed q
save andQuit
wq
Quit q
with confirmation
Doe
TED Ey
Iffy
192172 1.10
Name resolution
Translating hostname to IPaddress through using
letelfile known as Name resolution
command
Ping may not always good if Ping is disabled
in host you can't use them
DIS
The Environment all the etc host files in the
grew
systems got filled with too many Entries then
managing all became difficult
en DNSServer IPaddress
Domin Name
The IPaddrenes translates to names that we can
remember on the public internet are called domain names
Just like we name our hosts
apps google.com
4095ns
216.58221 78
org
DNS
mycompany.com
I
n's mail pay to drive
whw Iq
Now can resolve
we and map ip with name for our
company in internet
Aping web
PING web.mycompany.com
Royl Typed
How records are stored in Dns server
EEA type
TAT hostname IP
hostnam IPV
DtaA record
quad
hostname I hostname 2
ENAMEL
other
mapping one hostname to
Mashup
You can nslookup to query a hostname from a
DNS Seever
nstrokup hostname
Seever
added
Rig
This command return more details in a similar
form stored in Server
SwitchingAnd Routing
A switch B
creates natural
containing
2System
I
42
Inordee to connect system to switch they need interface
A tho a D D D D D Ethio B
192.172 1.0
I Assuming switch is network I
192172.1 10 192 172.111
Now we align with ipaddrenes using blew comma
systems
on both system So that both communicate with each other
elev etho
ip adds aid Ipaddress withCepr
192.172 1.1024 Interfacename
LIII
a DO'D DO D
tho B
it
emo
A etho a DO'D 00 a
192.174.1O 192.172go
12.12.2 192m22
192172.110 a a in io
SITI a ooooo
1921741O igno
a
etno.rs
192172
000
i
D
4,1 g
Steph
4Now there systems need accell to internet
Now connect route to internet
Add new route in your routing table
j it
192.174.1
O 192.1721.0
12.172.110
12.12.2 iat.no
iaz.na.in io
192.172.1 1
Dow Route 192.172.2 I
There are So
many diff sites on diff network on internet
instead of adding routing table routes for each we can
use
default
for any network we don't know route to we the
given route at default gateway
ip route add default via 192.172.21
192
172.110
in z
12.12.2
a
I
ain io
Route
192.172.1 1
Dow Route 192.172.2 I
P lindy
to list and modify interfaces on host
ip addTo
see ipaddvener anigned to those interface
adds add
slip tipaddrescipr den interface name
Linux Security
A t
pq'ake
me and password
of usaccess based authentication
to determine who can system
ELK byte
used to allow alien to services listening on the Linux Server
Normally we depend on firewall
It can be set
up in linux
by using tools such as
IPTables and finewall
SSI Idening
sste used to remote ai cen a serve over an unsecured
network
This will make sure
SSH Hardening only Authorized wees
gain access
cat letelpasswd
will have user alcount details
THE
have many
The
GID
directory
Default shell
If not partofanygroup it
inomelusa
Ibin Sh
assign win as
mm
id username
Superga agent
0 d am and control over mm
1
VIDEO
111
foot
id
gignan up groups part of
Last
Displays record of all logged in weed
Eying
Su username
To Swith to other any in system
any
SV
I To switch to root urea
55011
used to provideAdministrative accel
When treated wees we SUDO
prompted for theirpanned
They are
cat letelsudoers
a
ALL Lyolfity
Most of ACF are stored wider
Agone can we view
Only root canthodity
Modifying is ponible only by
builtin curds
letdpasswd Has basic info abt vers in system
UID GID Home directory
girish X 1001 1001 homegirish bin bash
username password UID 4117 GEcos Homeisin SH Ell
le te shadow stores panwords of woe
content are hashed
girish x x xxx xxxx x xxxx 10219 0 99999 7
Imaging yet
Create local user
userdel username
To delete a wee
Is I L filenames
by this longlisting
He know command we
get
details
of file
rwxowxrwx I A 89 mare 17 07 30 filename
Lets splitup
at
TWX TWX TWX
Regularfile
d Directory
e character device
I link
S SOCKETfile
p PIPE
b BLOCK DEVICE
D X TWX Vox
Consider the owner accessing the above file He can't
access
Although he is present in group
Became an linux system identifies the any trying
to access tile direitchy and checks permissions sequentially
Using Numeric
8 Chmod 777 file
All acred to owner group wet
Chmod 555 filly
read and Eruente access to owner group um
only
chmod 660 Lfiley
Chmod 750 a file
Ssh 1
user
fur
a Hostnamelipaddress
a Hostname ipaddrew
yserver should have
SSH Service running
in Port 22 accessible
from client
SSH port2222
user trengouteer
ClientLaptop
Reed In Sst
SSH key wed to login into machine without password
Create key
pair
Private key should only with client
Public
key Installed on remote server
SEP
Cp allows copy files in directory within filesystem in linux
Sudo iptables I
To list default rules configured
Types of rules
A
Webserver
SSH port22
172 18020.20
172.18020.271
EI JIB
Crow JOB When we need a particular script command
at some
given time regularly He can schedule the
job with date time and frequency without any
human intervention
This functionality is enabled by crond service earning
background
SILK Iob
To Schedule Job run below command from requried user
crontab e
10 00 AM 11th October
00 10 11 10
minute Four Tonth weekday
Tay
at wantto schedulejob onlywhen its
Monday Then set weekday as 1
Set weekday as A
value whatever
at indicates any
day it may be job will run
12 command
This
is called step value
crontab I
To list cron jobs running
tail Ivar logsyslog
used To check whether Job ran successfully
tserviceTI Semidefinatio
Execstart bin bash 198ft bashscript
most basic service can be built with this into
This is used to own command or an application
Ibinlbash as we are running bashscript
servicename7 service
SystemAl Stop
will stop the service
Req service should start with all above depending
on default target graphical CLD
I install runlevel
Wanted This can be your required
By graphicaltargety al Systematarget
will allow service to be enabled during boot this section
will help
Selvig
user Serviceaccounts
Egesta see 10
will set time in seconds to wait before
ServicenamesService
Ionit
Description
Documentation
SYSTEM
CTL JOURNALCTL
on systemd managed Seever thistoolcan
Query system journal
Manage systemstate
continient tool to
Start stop Reload Restart figure out
Enable Disable issues like service failure
list and manageunite
list and updateTargets
4 Activating Deactivating
Systemctl daemon euload
Run this after making changes to service unit file
This will reload system manager config and makes
system aware
of changes
Journal Ctl
Itis useful when troubleshooting issueswith systems
Échecks journal de
log entries from all partsof the
system
Journalat
prints all logs entries from oldest to newest
Journalett b
To see logs with current boot
8 0 0 119.29 0 disk
SIsdal q I loom o past lbootlefi
Sda2 8 2 8 73G
Sela3 8 3 O yo g Ppi Imedialmaldata
is 1 Ident grep ab
g list index directoryand
filetype b
Blockdevice has major and mind number
Majdnumber Devicetype
RAM
is used identify
HD CDROM
6 ParallelPrinter typeof blockdevice
8 scsi Disk
Partition
Partitiontypes
LogicalPortions
There are partitions created within the
Extended partitions
Partyhemeftable
It define how a disk is partitioned
Scheme s MBR Master BootRecord
1 max 4 PrimaryPartitions
2 Max size peedisc 2TB
Eating Iitions
gdisk device path
Eg Idea Sdb
Run above command with devicepath as argument
Éommand I to help
Pation number I
Size I
i Nexcode
1 create filesystem
filesystem defines how data stored
comenlyLedfilesystems
EX 2 EXT EXT U
max 2713 fileSize Max 2713fileSize 16TB filesize
YTBVolumesize up volume size I Enabyte
supports compression usesJournal uses Journal
Linux Permissions BackwardCompatible uses chksum for Jornal
longCrashRecovery Backward compatible
Exes as 2 72
Gmeans can be
mounted
mounted as ext3 bill
to back up
file using dumputility
Ganthet O disable backup
I take tack up J dumpnumter
7 Its priority set for filesystem check tool to
determine the order in which the fire system
should be checked during boot after a crash
O will ignore
1 max usually set for root files
External storage
teeth
storage won'talways suffice our
onboard Tin
Normally
care of Enterprise grade serves Eux
NFS
Hosta
Host t t
By
NAS file storage device and Das SAN are block storage
Ethernet
MAIL.gg
huspeed
This is weed
for Backend Storage for webservers or
app servers
OS installing not recorded
Network
storage Area
Ed
Provides blonk storage used enterprise for
by
business critical
apps that need to deliver
high throughput and low latency
j
T
it
Host B
Consider software
repo Seever
directsoftware repo exists on reposerver
I
This repo is shared over the network using NFS to
clients on laptops
client
NFSSeever software up
Fiat
Mnt software epos
software repos
Tent
tmntsoftware repos
Tam fol directly sharing in NFS
Emporting
5 mom
This defiens client that should be able to
access directory on the Selvey
firewall between
Ideally there will be Network
the NFS Server and clients
So specific ports might be opened b w NFS and
client for solution to work
empatts a
exports all the mounts defined in the
letelenports file
emportfs O client IP softwarerepos
Logicalvolumes
Voll 1012 4013
5413 5913 5GB
volumeGroup
FI E TE
Idevisial Ideutsdal Idrisbdl
Physicalvolumes
pncreate AlexIsdb
Fund discs
2 create a volumegroup using belowcommand
Pvdisplay
volumes names
It lists all the physical sizes
V6 s created
Vgdisplay
displays all Prs partof v6 and diskspace used
L linearvolume
most common volumetype
Enables us to use multiple physical volumes available
to create single logical volume
exdisplay
is to list volume
us
Another
way to list volume and lists
V6 it is partof
mkfs.extyldevlgivish.gg you
5 Mount it
mount t extyldevlgirish.gg vo2Imntlyoll
31,1
ldevlgivish.gg voll
2 accessible at 2places