Linux-Notes 2
Linux-Notes 2
/roo
/root
t it is home
home dire
direct
ctor
ory
y for
for root
root user
user(s
(sup
uper
er user
user)
)
it provides working enviorment for root user
c:\Documents and Settings\Administrator
/hom
/home
e it is home
home dire
direct
ctor
ory
y for
for othe
other
r use
users
rs
it provied working environment for other users(other than root)
c:\Documents and Settings\username
/boo
/boot
t it cont
contai
ains
ns boot
bootab ablele file
files s for
for linu
linuxx
like vmlinuz(kernel) ..... ntoskrnl
initrd(INITial Ram Disk)and
GRUB(GRand Unified Bootloader).... boot.ini, ntldr
/etc
/etc It cont
contai
ains
ns all
all conf
config igururat
atio
ionn file
files
s
l ik e /etc/passwd..... user info
/e t c/ r es o l v. c o nf . .. Preffered DNS
/e t c/ d hc p d .c o n f. . .. DHCP server
c:\windows\system32\dirvers\
/usr
/usr By defa
defaul
ult
t sof
softw
twar
ares
es are
are inst
instal
alle
led
d in
in /us
/usr
r dir
direc
ecto
tory
ry
(Unix Sharable Resources)
c:\program files
/o p t It is
is op
optional di
directory fo
for /u
/usr
It contains third party softwares
c:\program files
/bin
/bin It cont
contai
ains
ns comm
comman
ands
ds used
used by all
all user
users
s
(Binary files)
/sbi
/sbin
n It con
conta
tain
ins
s comm
comman
ands
ds use
used
d by only
only Sup
Super
er Use
User(
r(ro
root
ot)
)
(super user's binary files)
/d e v It co
contains dedevice fi files
like /dev/hda ... for harddisk
/d e v/ c dr o m ... for cdrom
similar to device manager of windows
/pro
/proc
c It cont
contai
ainn proc
proces esss file
files
s
Its contents are not permanent, they keep changing
It is also called as Virtual Directory
It's file contain usefull information used by OS
l ik e / pr o c/ m em i n fo . .. information of
of RA
RAM/SWAP
/p r oc / cp u i nf o . .. information of CPU
/var
/var It is cont
contai
aini
ning
ng vari
variab
able
le data
data like
like mail
mails,
s, log
log fil
files
es
/mnt
/mnt It is defa
defaul
ult
t mou
mount
nt poin
point
t for
for any
any par
parti
titi
tion
on
It is empty bydefault
/media
/media It conta
contains
ins all
all of remo
removabl
vable
e media
media like
like cdrom
cdrom,
, pendri
pendrive
ve
/lib
/lib It cont
contai
ains
ns libr
librar
ary
y file
files
s whi
which
ch are
are used
used by OS
it is similar to dll files of windows
library files in linux are SO(shared object) files
Basic commands:-
[root@sys10~]# pwd
/root
[root@sys10boot]# pwd
/boot
rmdi
rmdirr ....
.... to dele
delete
te an empt
empty
y dir
dir
s y n t ax # r md i r < dir name>
ex # rmdir o ne
error...... Directory not empty
# r m di r o ne / tw o /t h re e
# r m di r o ne / tw o
# r m di r o ne
synt
syntax
ax # touc
touch
h <fil
<filen
enam
ame>
e>
ex # touch fi r s t. t xt
ex # touch second.txt thrid.doc f o ur t h. b at
cat command is used to create file and diplay the contents of file also
e x. # cat > f ir s t. t xt
type the contents of file here
ksldjf;lkas
asdkljfja;sdf
asdfashflkjasdfh
................
press ctrl + d to save the file
ex # cat fi r st . tx t
type the contents of file here
ksldjf;lkas
asdkljfja;sdf
asdfashflkjasdfh
................
ex # cp / r oo t /f i rs t .t x t / ro o t/ o ne / tw o /t h re e / ne w . tx t
this command will copy first.txt file to three directory with new.txt na
me
ex # cp -r
-r /r
/root/one/* / var
this command will copy all the contents of one directory to var director
y
note
note:-
:- we can
can use
use wil
wildc
dcar
ard
d char
charact
acter
ers
s
* means multiple characters
? m ea n s single character
synt
syntax
ax # rm < file
file/d
/dir
ir name
name >
ex # rm / r oo t /f i rs t .t x t
it will ask for confirmation, press y to delete file
ex # rm -f
-f / ro o t/ f ir s t. t xt
it will not ask for confirmation
mv .. . .. to move file/dir
this command is also used to rename file/dir
synt
syntax
ax # mv < sour
source ce name
name > < targ
target
et name
name >
ex # mv
mv /r o o t/ f ir s t. t xt / r o ot / on e /t w o/ t h re e
this comamnd will cut first.txt file and paste it in three directory
ex # mv / r oo t /f i rs t .t x t / ro o t/ n ew . tx t
this command will rename first.txt file to new.txt
cd . . .. . change directory
synt
syntax
ax # cd < dir
dir name
name >
[root@sys10~]# cd /var/log
[root@sys10 log]# pwd
/var/log
[root@sys10 log]# cd /root
[root@sys10~]# pwd
/root
ls -l long listing
ls -a list all files and directories
ls -R Recursive order
ls -r reverse order
ls -i to list inode numbers
ll same as 'ls -l'
..............................................................................
Insert mode:
ex command mode:
command mode:
dd to delete a line (cut)
4dd to delete 4 lines (cut)
yy to copy a line (yank)
10yy to copy 10 lines (yank)
p to paste lines below cursor position
P to past lines above cursor position
u to undo
ctrl+r to redo
/<find what> to find a text inside a file
more and less commands are used to see the contents of a file page wise.
syntax. # more < file name >
ex. # more file1.txt
now to see contents page wise press space
to see contents line wise press enter
less command is same as more
but to quit less command we have to press q
# ll grep "^-"
to show only files
# ll grep "^d"
to show only directory
# ll grep "^-" wc -l
to count no. of files
# wc -l file1.txt
shows only no. of lines
# wc -w file1.txt
shows only no. words
# wc -c file.txt
shows only no. of characters.
..............................................................27/03
to create a group:
syntax. # groupadd <option> <groupname>
options:
-g to set GID
ex. # groupadd -g 1010 sales
ex. # groupadd mktg
PERMISSIONS:-
file dir
r open the file 'ls' the contents of dir
w write,edit,append,delete file add/del/rename contents of dir
x to run a command/shell script to enter into dir using 'cd'
file types:-
- normal file
d directory
l link file(shortcut)
b block file(harddisk,floppydisk)
c character file(keyboard,mouse)
here,
read=4
write=2
execute=1
note:- UMASK- is the number which is removed from default permission of file/
dir.
default umask of root user is 022
default umask of unprivledged user is 002
Advanced Permissions:
SUID:-
If suid is set on any command then any normal user can run
that command with privledges of root user
like, Defaultly ping command is having suid, so all users can
run that command but if suid is removed then 'permission denied'
ex.
# whereis ping
/bin/ping
# ls -ld /bin/ping
-rwsr-xr-x ..........
````` this means SUID is set bydefault
how to remove SUID:
# chmod 0755 /bin/ping
# ls -ld /bin/ping
-rwxr-xr-x ................
```` this means SUID is removed
how to check:
log in as normal user and try to ping
it will display error..... opration not permitted
SGID:-
SGID is used for group inheritance, files and directories will
get groupname from their parent directory
ex.
# mkdir /mywork
# chmod 777 /mywork
# chgrp sales /mywork
# chmod 2777 /mywork
# ls -ld /mywork
now login as sales group members, create some files, and check their
properties
Sticky Bit:-
If sticky bit is set, then only owner can delete that file/dir
ex.
# mkdir /mywork
# chmod 1777 /mywork
# ls -ld /mywork
it will display rwt.... for sticky bit
# su user1
$ touch /mywork/file1
$ exit
# su user2
$ rm /mywork/file1
error.... permission denied
..............................................................................
Network-Client configuration:
ifconfig:-
Interface configuration(Network Interface Card)
it is used to set ip addr temporarily
it is also used to check ip addr
system-config-network
or
neat( Network Administration Tool )
used to set ip addr in Graphical mode
ifup:- interface up
this command will enable lan card
# ifup eth0
to see hostname:-
# hostname (press enter)
to set hostname temporarily:-
# hostname sysX
to check log off and log in again and use 'hostname' command
Partitions:-
fdisk command is used in linux to create,delete,view,manage partitions
# fdisk -l
Note:- 1Block=1KB
Id is used by system to identify the type of partition.
* means it is a boot partiton.
1. restart system
# init 6
2. go to single user mode
at the grub boot screen select Redhat and press 'a'
then give space and type '1'
then press enter
3. at the shell prompt change the root password
sh# passwd root
******
******
4. restart the system
# init 6
What is GRUB?
GRand Unified Bootloader is the default boot loader program for RHEL5
configuration file for GRUB is
/boot/grub/grub.conf
its contents are:-
..............................................................................
08/04/08
Symbolic Link
............................................................................
2 #mkswap /dev/hda11
3 #swapon /dev/hda11
4 #free
it will show total swap space.
Quota:-
quota are used to restrict the amount of disk usage by any user,
group on a particular partition.
QUOTA
user level . group level
blocks inodes .blocks inodes
(size in kb) (no. of files) .(size in kb) (no. of files)
here,
soft means --- limit after which warning message is displayed
hard means --- limit after which error message is diplayed
................................................................................
..........
03/04/08
RAID
Redundant Array of Inexpensive/Independent Disk
Diagram:-
RPM
RedHat Pakage Manager
on client machine:-
method 1:- NFS
first ping server
# ping 192.168.10.10
then mount the shared directory from server to any local directory:-
# mount 192.168.10.10:/var/ftp/pub/Server /mnt
```````````` ``````````````````` ````
IP add of server:/location of shared dir local dir.
go to mount point
# cd /mnt
now install pakage:-
# rpm -ivh <pakage name + version>
# rpm -ivh vsftpd-2.0.5-10.el5.i386.rpm
(try dialog rpm also)
YUM
YellowDog Updater Modified
yum feature was avialable with fedora, now it is available in RHEL5
RPM feature is used to install pakages but its main drawback is
Failed Dependency Resolution.
yum automatically identifies dependency in pakages,& install those
dependencies also.
by using YUM we can install, remove, list pakages and group of pakages.
1. check ip addr
2. ping server(192.168.1.10)
3. edit configuration file /etc/yum.repos.d/rhel-debuginfo.repo
4. start installing pakages using 'yum' command.
yum command :-
# yum install <pakagename> rpm -ivh <pkgname>
# yum remove <pakagename> rpm -e <pkgname>
# yum list installed rpm -qa
# yum list installed <pakagename> rpm -q <pkgname>
# yum grouplist -----
# yum upgrade <pakagename> rpm -Uvh < pkg name>
# yum groupinstall <grpname> -----
..............................................................................
08/04/08
Remote copy:-
scp---- secure copy
this command is used to copy contents of remote system,
we can take remote backup using this command
pakages:- nfs-utils*
portmap*
Services nfs
portmap
Daemon statd,mountd,lockd,nfsd
Steps:-
server side:-
create share folder:-
# mkdir /share
give full permission:-
# chmod 777 /share
export(share) this directory:-
# vi /etc/exports
/share 192.168.1.0/255.255.255.0(rw,sync)
NOTE:- /share *(ro,async)
restart service:-
# service portmap restart
# service nfs restart
client side:-
mount server's dir on /mnt
# mount 192.168.1.10:/share /mnt
check the contents:-
# cd /mnt
# ls
FTP SERVER
FILE TRANSFER PROTOCOL- used to upload and download files from ftpserver
following are different ftp server:-
wuftp washington university ftp
proftp
vsftp very secure ftp
Pakages:- vsftpd*.rpm
Port no. 20 for data transfer
21 for connection control
configuration file /etc/vsftpd/vsftpd.conf
/etc/vsftpd/user_list
/etc/vsftpd/ftpusers
services vsftpd
Daemon vsftpd
Steps:-
line no.
12 anonymous_enable=YES
to allow anonymous user to log into ftp server
user name for anonymous users are,
ftp
anonymous
15 local_enable=YES
to allow local users that are created on server machine to log into ftp
server from
client side
example of local users is user1,user2,raj,ravi
27 anon_upload_enable=YES
to allow users to upload file to ftp server
bydefault any user is not permitted to upload files to server, he can on
ly download
115 userlist_enable=YES
2 download files
go to download directory
ftp> cd download
ftp> get one
3 upload file
go to upload directory
ftp> cd upload
ftp> put localfilename
Note:-
if local_enable=YES is given in vsftpd.conf file
it means local users of server can also login from client side
ex. of local users are user1,user2, and even root
but bydefault root user is NOT allowed to login from network
so to deny any local user to login into ftp server, enter its name in
ftpusers file or user_list file, and reload the service
............................................................................
10/04/08
SAMBA SERVER
pakages samba,samba-common,samba-client,swat
portno. 137 NetBIOS name service
138 NetBIOS datagram service
139 NetBIOS session service
configuration file /etc/samba/smb.conf and /etc/samba/smbpasswd
service smb
Daemon smbd,nmbd
there are 2 methods in which we can access samba server from linux clien
t
NFS:-
# mount //<ip add of samba server>/<share name> <mountpt> -o
username=smbusername
# mount //192.168.1.10/myshare /mnt -o username=user1
FTP method:-
# smbclient //<ip add of server>/<share name> -U username
# smbclient //192.168.1.10/myshare -U user1
smb>ls
smb>get file1
smb>put anyfile
smb>quit
Note :- on samba server you must create user and provide smb password
# useradd user1
# smbpasswd -a user1
*****
*****
..............................................................................
PROCESS MANAGEMENT:-
..............................................................................
DHCP---- DYNAMIC HOST CONFIGURATION PROTOCOL
pakage dhcp-3.0.5-3.el5
configuration file /etc/dhcpd.conf
/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample
/var/lib/dhcpd/dhcpd.leases
note:- if you want to see mac addr of client from server machine then
# ping 192.168.1.X
# arp -a (press enter)
...............................................................................
14/04/08
A Address record
Used to show it Ip Addr of any hostname
portno. 53
main conf file /etc/named.rfc1912.zone
/etc/named.caching-nameserver.conf
Service named
Daemon named
Steps:-
check ip addr:-
# ifconfig
if it is not correct set ip addr
# neat
or
# netconfig
restart network service:-
# service network restart
check hostname
# hostname
if it is not correct then set hostname
# hostname sysX.4s.com
make it permanent:-
# vi /etc/hosts
192.168.1.X sysX.4s.com sysX
# vi /etc/sysconfig/network
hostname=sysX.4s.com
now logout and login again to check hostname
allow-query { localhost;192.168.1.0/24; };
match-clients { localhost;192.168.1.0/24; };
# vi /etc/named.rfc1912.zones
zone "4s.com" IN {
type master;
file "4s.for";
};
zone "1.168.192.in-addr.arpa" IN {
type master;
file "4s.rev";
};
change directory:-
# cd /var/named/chroot/var/named
$TTL 86400
@ IN SOA sys10.4s.com. root.4s.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS sys10.4s.com.
IN A 127.0.0.1
sys10.4s.com. IN A 192.168.1.10
sys9.4s.com. IN A 192.168.1.9
sys2.4s.com. IN A 192.168.1.2
# vi 4s.rev
$TTL 86400
@ IN SOA sys10.4s.com. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS sys10.4s.com.
10 IN PTR sys10.4s.com.
9 IN PTR sys9.4s.com.
2 IN PTR sys2.4s.com.
................................................................................
KICKSTART INSTALLATION
It is similar to RIS/Unattended installation of Windows os
By using kickstart installation we can install linux on remote machine
all the installation files are present on kickstart server
client is booted from linux bootable cd(cd no.1) and
then it will take installation files from server along with
answer file.
Answer file is a file genereted on kickstart server which provides all
answers of questions which are asked during installation process.
...............................................................................
...............................................................................
MAIL SERVER:-
MAIL server uses MTA( mail transfer agent) like sendmail, qmail, postfix
squirrelmail, smail etc
MTA uses SMTP protocol to send and recieve mail at port no. 25
on the client side mail client software like mutt(Mutt Mail User agenT),
thunderbird, evolution, and webmail are used to send and recieve mail.
start service
# service sendmail restart
on client side:-
set hostname............. sysX.4s.com
set ip addr
set ip addr of dns server in resolv.conf file
# vi /etc/resolv.conf
nameserver 192.168.1.X
Then you can access mail in graphical mode using webmail( mail client )
There are many web servers like IIS(windows), apache, sunone, AOL, etc
most popular web server is Apache, it works on both windows and linux
more than 68% of total web servers of world are configured on Apache
Note:- go to www.netcraft.com
type url of any web server, and search, it will show you
on what kind of server that web site is working,
like www.way2sms.com is working on Apache 2.0 installed on Fedora8
go to ip2location.com
type url of any web server, and search, it will show you
the geographical location of that web server,
like www.google.com is in US, california, street...., contact person...
www.whois.net...... you can find who is maintaining that server,
complete contact information is displayed with ph. no. too
use nslookup command to see ip addr of any dns server.
pakages httpd*(httpd,httpd-manaul,httpd-devel)
port no. 80
conf file /etc/httpd/conf/httpd.conf
service httpd
daemon httpd
check it
# dig -x 192.168.1.X
...............................................................................
18/04/08
NIS..... Network Information Services
steps:-
1 install the pakage ( remove it if it is already installed )
# yum remove yp*
# yum install yp*
# vi first.sh
#/bin/bash
echo " this is my first shell script "
echo " Enter your First name:.......... "
read firstname
echo " Enter your Last name:........... "
read lastname
echo " Your Full Name Is :............. $firstname $lastname "
# vi second.sh
#/bin/bash
echo "enter yes or no"
read ans
ans="$(echo $ans tr 'A-Z' 'a-z')"
echo "$ans"
# vi pets
capital=dehli
echo "what is capital of india"
read cap
if [ $cap != $capital ]
then
echo "wrong"
exit 1
else
echo " correct "
fi
read a
read b
c=`expr $a + $b`
echo $c
for x in 10 20 30
do
echo $x
done
...............................................................................
Note:-
when we mount any partition by using 'mount' command, then
/etc/mtab file is updated and new entry is added
but this type of mounting is temporary
after rebooting the system it is automatically unmounted
at
this command is used to schedule task for one time only:
# at 13:30
at> touch /root/breaktime
at> (press ctrl+d to save)
how to check it
# atq
it will diplay task no. and time
ex.
# at 13:29
at> eject
at> ctrl+d
# at 13:30
at> eject -t
at> ctrl+d
# at 13:31
at> eject
at> ctrl+d
...............................................................................
Virtualization
Intel VT-x or AMD-V Pacifica and Vanderpool technology for full and paravirtuali
zation.
For full virtualization your system must support PAE(physical Address Extension)
,
by using PAE technology we can increase the amount of physical or virtual memory
avialable to user applications.
Celeron " Pentium II " Pentium III " Pentium IV " Xeon " AMD Athlon " AMD Duron
for paravirtualization.
Installing virtualization:-
yum install <pakage name>
pakages are:
kernel-xen
xen
xen-libs
virt-managerz
gnome-applet-vm
libvirt
Connect to a domian:
# xm console domain-id
Create a domain:
# xm create -c newdomainname
saving a domain:
# xm save domain-id
destroy a domain:
# xm destroy domain-id
shutdown a domain:
# xm shutdown domain-id
restore a domain:
# xm restore domain-id
suspend a domain:
# xm suspend domain-id
resume a domain:
# xm resume domain-id
reboot a domain:
# xm reboot domain-id
pause a domain:
# xm pause domain-id
unpause a domain:
# xm unpause domain-id
diplay uptime:
# xm uptime domain-id
requirements:
first create a new partition on Domain0 host(ex. /dev/hda9)
then configure your nfs install server 192.168.1.10(share dir is /var/ftp/pub)
then create a kickstart server 192.168.1.10(save file in /var/ftp/pub)
Note:- you can also use "virt-install" command to create a virtual machine in
text mode
...............................................................................
PROXY SERVER
pakage squid*
portno. 3128
conf file /etc/squid/squid.conf
service squid
daemon squid
line no.
73 http_port 3128
remove the hash from line no. 993
cache_dir ufs /var/spool/squid 100 16 256
after defining all acl define allow/deny policy for each of them
below line no. 2500
like
http_access deny denydomain
http_access deny denykeyword
or
http_access deny denydomain denykeyword
http_access allow neighbours