linuxmod - wordpress.com · 2016. 9. 12. · linux uses ext2 & ext3 file system. boot loader...
TRANSCRIPT
1
2009
[REDHAT LINUX RHEL‐5 SERVER] IN THIS FILE I WILL TELL YOU ALL ABOUT LINUX BASIC COMMANDS AND SERVERS . Rahul Gupta
2
INDEX
1. History of L inux 2. LINUX PRINCIPLE 3. Linux Directory Structure 4. INSTALLATION 5. LINUX BOOT PROCESS 6. Linux Basic Commands
A. Directory commands B. Fi le Commands C. Commands for deleT ng D. Help Commands E. Rename & Move F. LisT ng Commands G. Copy H. Editors in l inux
7. SOME BASIC COMMANDS
8. RPM (RedHat Package Manager)
9. BREAKING PASSWORD & PASSWORD SECURITY
10. PERMISSIONS
11. BASH SHELL PROGRAMMING
12. RUN LEVEL ( INIT)
13. Looping command for making users
14. CRONTAB
15. PARTITIONS A. CreaT ng new/home parT T on
B. CreaT ng Swap ParT T on
16. RAID
17. LVM {LOGICAL VOLUME MANAGER}
18. USER QUOTA
19. PRINTER COMMANDS
3
20. SOME IMPORTANT FILES & COMMANDS
21. SUDO
22. Servers A. YUM (YELLOW DOG MODIFIER) SERVER
B. SQUID SERVER (Proxy in L INUX)
C. DHCP
D. DNS (DOMAIN NAME SYSTEM)
E. NFS SERVER
F. SAMBA SERVER
G. NIS SERVER
H. APACHE (WEB) SERVER
I. SENDMAIL
J. XEN SERVER (VIRTUALIZATION)
K. FTP (FILE TRANSFER PROTOCOL)
L. TELNET
4
History of Linux
In 1969, Four programmer Ken Thompson, Dennis Ritchie, Rudd Canady & Doug McElroy made a program in Bell labs which does not have any name in year 1969.
Brian Kernighan checked that program & found it is very good soiware for client & networking purpose. He gave the name Unix to this program on 1st January 1970 (epoch Tme). First OperaTng System. That Tme that program was wrijen in Assembly language.
In 1972, a programmer Dennis Ritchie started converTng this program in C language. (Also called
founder of C language). 1973‐ Unix in C language. 1980‐ Berkeley Soiware Development (a part of research program of Berkeley University)
launches open BSD (a small program wrijen in a single floppy). Paul Allen & Bill Gates are the employee of Bell Labs. In 1981, they both started Microsoi with 9 more candidates & they gave a programme named
Xenix (1980) but it was flopped. In 1981‐ Launched MS‐DOS 1.0 In 1984‐ UNIX open source In 1985‐ First Graphical Based OS‐ Win 2.0 In 1991, Linus Benedict Torvalds, B‐tech Iind year Computer Science, 23 years old student of
University of Helensiki (Finland) made Kernel (25th August 1991). In 1994‐ RedHat Company (collecTon of Linux Sets) came into existence. 96.8 % servers of Linux Tll 2009.
5
LINUX PRINCIPLE 1. Everything is a file. 2. Small, single purpose programmers’. 3. Ability to Chain programmers’ together to perform complex tasks. 4. Avoid capTve user interfaces. 5. ConfiguraTon data stored in text.
Linux Directory Structure
1. /home ‐ Users home (all users folders) 2. /bin ‐ Commands (user executable & Scripts) 3. /usr/bin ‐ Commands (user executable & Scripts) 4. /sbin, /usr/sbin ‐ root privileged command 5. /usr/local/bin ‐ commands which we make for our use. 6. /etc ‐ System ConfiguraTon files 7. /boot ‐ Linux Kernel & Bootable files 8. /root ‐ root (Admin) Data 9. /mnt, /media ‐ for mounTng any external devices 10. /dev ‐ devices (hdd, CD‐Rom, Pen Drive) 11. /var, /svr ‐ Server data 12. /proc, /sys ‐ System InformaTon 13. /lib/usr/share ‐ Library files stored
6
INSTALLATION Here I will tell you installaTon related requirements and files. (not whole installaTon). Linux uses ext2 & ext3 file system. Boot loader of linux GRUB (Grant Unified Boot Loader) new & LILO (Linux Loader) old. Boot from CD or DVD There are many types of method of installing linux 1. Simple Graphical method ‐ it will ask for a Enter 2. Text based ‐ in this you have to write linux text or linux askmethod (from this you can also
install from NFS) Minimum requirement for Graphical installaTon – x86 processor, 256 MB RAM. ParTTon Created at the Tme of installaTon
Partition Name File System Used for Minimum Size / ext3 linux file system 6000MB or 6 GB /boot ext3 Linux booTng files & kernel 75 or 100 MB /home ext3 Linux users entry It’s upon you /swap Swap Uses as virtual ram Double of RAM
Linux can support maximum 63 harddisk IDE & 15 SATA Harddisk.
In Linux 7 users can log in at the same Tme. Ist User ‐ Atl + Ctrl + F1 IInd to VIth user ‐ Alt + Ctrl + F2 to F6 Graphical user ‐ Alt + Ctrl + F7
7
L INUX BOOT PROCESS
8
Linux Basic Commands
Directory commands:
1. # mkdir ‐ For creaTng directory. 2. # cd ‐ change directory. 3. # cd .. ‐ to come out from working directory. 4. # rmdir ‐ to remove directory
Fi le Commands:
1. # touch <filename> ‐ creates a blank file. 2. # cat > filename ‐ creates a file and for saving this file (ctrl + D) 3. # cat ‐ to see the content of the file. 4. # cat file1 >> file2 ‐ to move file1 majer in file2 5. # cat ‐n filename ‐ to see how many lines are written in that file.
Commands for deleT ng:
1. # rm filename ‐ deletes a file. 2. # rm ‐i ‐ deletes file/folder in interacTve mode (asking mode) 3. # rm ‐r ‐ deletes directory. 4. # rm ‐f ‐ deletes files/folders forcefully.
Help Commands:
1. # whaTs <command> These all are the help commands. Prints all related tags 2. # man <command> about that command. 3. # info <command> 4. # <command> ‐‐help 5. # which <command> 6. # cd /usr/share/doc
Rename & Move:
1. # mv <oldfile> <newfile> (Rename) 2. # mv <filename> <where we have to move the file> (Move)
LisT ng Commands:
1. # ls ‐ lisTng files/folders 2. # ls ‐l (ll) ‐ long lisTng of files/folders with whole informaTon 3. # ls ‐a ‐ lists all files/folders (hidden also) 4. # ls ??? ‐ all files/folders named with 3 characters 5. # ls m* ‐ files & directories started with lejer m.
9
Copy:
1. # cp <source> <desTnaTon> ‐ copies files from source to desTnaTon 2. # cp ‐i <source> <desTnaTon> ‐ copies files from source to desTnaTon in asking mode 3. # cp ‐i * <desTnaTon> ‐ copies current working directory all data to desTnaTon. 4. # cp ‐r <directory name> <desTnaTon> ‐ copies directory from source to desTnaTon
Editors in l inux:
1. nano 2. vi These editors are used in console mode. 3. vim 4. gvim 5. gedit These editors are used in graphical mode. 6. Emacs
VI editor/ VIM editor:
There are three modes in vi editors 1. ex mode (default mode, by pressing escape key, this mode is used for saving and exit ) 2. Insert mode (by pressing insert or I key, this mode is used for ediTng) 3. Replace mode (this mode is used for replacing text wrijen, by again pressing insert or r key)
For saving document‐ come on esc mode and write :wq For sexng line numbers in document come on esc mode and write : se nu For coming on any specific line press line no. and then ‘G’ (ex‐ 102 then G) or :line no (enter) For going at the end of page press ‘G’ For going at the top of page press gg For searching any text in the file /text For undo u and for redo ct rl+r
Vim editor is not installed default when you install linux, you have to install vim editor. It is the enhanced version of vi editor. # vim/vi filename Press ‘v’ to come to visual mode, here we can select the majer which we want to copy , press ‘yy’ to copy (y stands for yank). Press ‘p’ to paste that majer. Press ‘dd’ to delete a parTcular line where cursor is. Nano Editor: Nano is a command based editor, earlier used when advanced editors were not came into being. When you open a a file with this editor, you will find all related help of this command.
10
SOME BASIC COMMANDS
1. # poweroff ‐f
2. # halt ‐n ‐p ‐ These commands are used to turn off computer.
3. # init 0
4. # init 6 ‐ These commands are used to Restart computer.
5. # reboot
6. # startx ‐ Switch from command to graphic.
7. # init 5 ‐ Restarts system from command mode to graphic mode.
8. # history ‐ To see history of recent commands.
9. # history ‐c ‐ To clear the history of recent commands
10. # cat > /etc/issue ‐ To create logoff scripts.
11. # cat > /etc/motd ‐ To create logon scripts.
12. # cal yyyy or mm yyyy ‐ To see the calendar of that month & year.
13. # bc ‐ Starts basic calculator.
14. # whoiam or # w ‐ To know by which user we logged on
15. # adduser <username> ‐ To create user
16. # passwd <username> ‐ To give password to user.
17. # userdel <username> ‐ To delete user.
18. # usermod ‐L <username> ‐ To lock a user account.
19. # usermod ‐U <username> ‐ To unlock a user account.
20. # passwd ‐d <username> ‐ To remove password for a user.
21. # cd ~ ‐ Switch directly to users home directory with.
22. # head <filename> ‐ To see the top ten lines of a file.
23. # head ‐n 16 <filename> ‐ To see top 16 lines of a file.
24. # tail <filename> ‐ To see the bojom ten lines of a file.
25. # tail ‐n 16 <filename> ‐ To see bojom 16 lines of a file.
26. # evince <filename.pdf> ‐ To open a pdf file (only on graphical terminal)
27. # sort <filename> ‐ Sort file in a‐z format.
28. # sort ‐d <filename> ‐ Sort file in dicTonary format.
29. # sort ‐r <filename> ‐ Sort file in z‐a format.
30. # sort ‐t : ‐k 3 –n/r/u <filename>‐ Sort the file according to given delimiter (n=numeric,
11
r= decending, u=removes duplicaTon)
31. # cat <filename> |tr ‘a‐z’ ‘A‐Z’ ‐ Translate file in all capital lejers.
32. # wc (‐l/‐w/‐c ) <filename> ‐ Word count (‐l for line, ‐w for word, ‐c for character)
33. # diff file1 file2 ‐ To see difference between same looking files.
34. # blkid ‐ To see device id (ex‐ hda1, sdb).
35. # mkfs.vfat ‐I /dev/device id ‐ To format device in fat format.
36. # aspell ‐c <filename> ‐ To check spelling in a file.
37. # neat ‐ To open network configuraTon on graphic terminal
38. # ifconfig ‐ To check the IP & MAC address of NIC.
39. # ifconfig eth0 <ip address> ‐ To assign temporary IP
40. # ifup eth0 ‐ To enable network card.
41. # ifdown eth0 ‐ To disable network card.
42. # vi /etc/sysconfig/network‐scripts/ifcfg‐eth0 To assign permanent IP , here we
43. # vi /etc/sysconfig/networking/devices/ifcfg‐eth0 have to edit a file.
44. # ethtool eth0 ‐ To check graphically whether cable is connected or not.
45. # # df ‐h <parTTon> ‐ To check the free space of a parTTon.
46. # ping (‐c2, ‐a) <ip address> ‐ To check connecTvity (‐c2 for seeing two lines, ‐a lisTng)
47. # look <word> ‐ For looking the exact word spelling.
48. # date mmddhhmmyy ‐ To set date.
49. # ps ‐ To check the processing status.
50. # kill ‐9 PID ‐ To kill the service no. 9.
51. # top ‐ Full details of all processing & their ID. (k‐ kill, h‐ help)
52. # wget <website> ‐ To download the website home page.
53. # elinks <website> ‐ To open website in command line.
54. # xterm ‐ Starts a new sub‐terminal.
55. # muj ‐ To send mail in a NIS or single PC between user & root
56. # du ‐h <parTTon> ‐ To check how much parTTon is used.
57. # ln /home/rahul /rahul ‐ It will link the file in home name rahul with rahul (in root)
58. # seq 1 1000 >/home/rag ‐ It will create a file named rag having no. 1 to 1000.
59. # uname ‐ To see kernel name.
60. # uname –r ‐ Kernel release.
61. # uname –a ‐ Whole informaTon about kernel.
62. # find / ‐name <filename> ‐ Searches file in /.
12
63. # find ‐perm 775 ‐ Searches for files having permission 775.
64. # find ‐size ± 512k ‐ Searches for files of 512k
65. # find ‐name *.htm ‐ Searches files having extension .htm.
66. # zcat <filename.gz> ‐ To see the content of compress file.
67. # chkconfig on/off <service> ‐ To on/off any service permanently.
68. # lsmod ‐ List of drivers running.
69. # modinfo ‐ Details about running driver
70. # sysctl –n kernel ‐ To update kernel.
71. # tmpwatch ‐ Shows temporary files.
72. # ge�acl <filename> ‐ It will display full informaTon about that file or directory.
73. # se�acl ‐m u:<user>:rwx /ww ‐ It will set the full user permission on ww directory.
74. # mount /dev/cdrom /mnt ‐ To mount CD ROM.
75. # mount /dev/device name/mnt‐ To mount any external device.
76. # mount ‐t vfat /dev/parTTon /mnt To mount fat parTTon.
77. # groupadd <name> ‐ To add a group.
78. # groupdel <name> ‐ To delete group.
79. # groupmod ‐n <newname> <oldname> ‐ Rename the group.
80. # usermod ‐G <group> <user> ‐ It will add user to group.
81. # adduser ‐g <group> <user> ‐ To add network user in group.
82. # cat .bash_history ‐ To see history of commands (aier execuTng history –c)
83. # cat > .bash_history ‐ To remove history of commands
84. # chage ‐E YYYY‐MM‐DD <user> ‐ Set user expiraTon.
85. # chage ‐l <username> ‐ To see user detailed informaTon.
86. # chage ‐W 1 <username> ‐ To set warning period for user.
87. # file <file/directory name> ‐ To check whether it is file or folder.
88. # cut –f1 –d : /etc/passwd ‐ It will show the first column of passwd file.
89. # cut ‐d , 1 file > new file ‐ cuts that line and put it in new file.
90. # paste newfile 2newfile > 3 ‐ paste the data which you have cut from a file in a new file.
91. # finger (‐l) ‐ shows the status of the user (‐l shows some add. Info)
92. # id username ‐ To see the id of user.
93. # command|tee stages.out ‐ It will give the output of command in file name stages.out.
94. # less <filename> ‐ To see a file pagewise.
95. # grep <word> <filename> ‐ To find a parTcular word or string in a file.
13
(‐v= didn’t have that word, ‐c= contain that word)
96. # grep –n <word> <filename> ‐ To see the line number in which that word is.
97. # grep ‐r word <path> ‐ searches word in all files of that locaTon.
(grep= get regular expression)
98. # tar ‐cvf <name> <filesname> ‐ It will take the backup of files as a single file.
99. # tar ‐tvf <name> ‐ Show how many files & their name in the backup file.
(‐z= gzip, ‐j=bzip2) (tar = tape archieve)
100. # tar ‐xvf <name> ‐ Restore the backup.
101. # tar –rvf <name> filename ‐ Append backup with some files.
102. # gzip <filename> ‐ It will compress a file.
103. # bzip2 <filename> ‐ It will compress a file.
104. # gunzip <filename>.gz ‐ It will decompress a file.
105. # gzip ‐d <filename>.gz ‐ It will decompress a file.
106. # bzip2 ‐d <filename>.bz2 ‐ It will decompress a file.
107. # bunzip2 <filename>.bz2 ‐ It will decompress a file.
108. # ssh <ip of remote PC> ‐ It will take control of remote pc (ask for password)
109 # scp /root/proxy.exe 10.0.0.1:/root ‐ To send any file in network.
110. #scp ‐rv <source> <desTnaTon> ‐ To send any directory in network.
111. # tunetofs ‐j /dev/parTTon ‐ for converTng ext2 to ext3
112. # nmap <IP address of PC> ‐ Shows all the port no. opens in that PC
(RPM must be installed)
14
RPM (RedHat Package Manager)
xmms‐1.2.10‐9.i386.rpm
Package Name Version Type of Extension architecture
# rpm <opTons> <package name>
# rpm ‐ivh <package name>
‐‐aid (install package along with dependencies)
‐‐force (forcefully)
‐‐nodebs (to remove package along with dependencies)
# rpm ‐e <package name> (To uninstall package)
‐U (upgrade the package)
# rpm ‐q <package name> (Show whether package is install or not)
‐qa (queries all installed rpm packages)
‐qc (lists only the configuraTon files stored in the queried package)
‐qd (lists only the documentaTon files stored in the queried rpm)
‐qi (displays whole informaTon about the queried rpm)
‐qs (displays the states of files in the queried rpm)
‐ql (displays all files related to the queried rpm)
15
BREAKING PASSWORD & PASSWORD SECURITY
Breaking root password:
When system ask to select OS, here press ‘e’.
Choose the second opTon ‘Kernel/vmlinuz‐2.6.i8, again press ‘e’.
Write ‘1’ at the last of the line,
Then press esc key and then ‘b’.
Now system will reboot and stops on single user mode
sh#
here type passwd , then enter
type new password
now reboot & give root and new password.
Password Security (adding password on grub ai er insta llaT on):
{on graphical terminal}
# grub‐md5‐crypt
Password:
Confirm password:
(Here you see some digits, copy those digits)
Now edit file grub.conf
# vi /boot/grub/grub.conf
Here you see a line where wrijen hidden menu, come under that line and type
Password ‐‐md5 {paste those digits}
Save file.
Now your password cannot be broken on startup.
16
PERMISSIONS
_ _ _ _ _ _ _ _ _ _ owner group fi lename f/d User group others
r=4 (22) w=2 (21) x=1 (20)
read write execute
For di rectory maximum permiss ion = 777
For fi les maximum permission = 666
To give user fu ll permission
# chmod 777 filename
Defaul t permiss ion for fi le = 644
Defaul t permiss ion for di rectory = 755
To see the internal permission
# umask (max per. ‐ umask = default permission)
# umask 000 (full permission for all)
# umask 777 (deny for all)
To change the owner of fi les or d irectory‐
# chown <username> file/directory name
To change group of fi les & di rectory‐
# chgrp <groupname> file/directory name
Every user has its own UID (User IdenTficaTon)
Every group has its own GID (Group IdenTficaTon)
If UID matches (i.e. login user & owner) user permission is applicable.
If GID matches (i.e. login user & group) group permission is applicable.
If nothing matches other permission is applicable.
17
To check UID/GID
# cat /etc/passwd (UID for root = 0, UID for user starts from 500)
Fi les where UID & GID informaT on saved
/etc/passwd (UID)
/etc/shadow (UID in encrypted form)
/etc/group (GID)
/etc/gshadow (GID in encrypted form)
BASH SHELL PROGRAMMING
By this we can make a script of any server and run at Tme we want it.
# mkdir ~/bin
# cd /root/bin
# vi test.sh (type the following in the file)
#!/bin/bash
mkdir /repo
cd /repo (write command in a sequence of its use)
:wq
# chmod u+x test.sh (to give executable permission to file)
# test.sh (to run that file)
To display the content on the screen‐
# echo “what is your ip address $ (ifconfig)”
# alias ‘R’=ifconfig
# echo “what is your ip address $ (R)”
18
RUN LEVEL ( INIT)
To edit or see init level
# vi /etc/inijab
0 = shutdown 1 = single user mode 2 = mulTuser mode without NFS support 3 = full mulTuser mode 4 = not used 5 = Graphical (x11) 6 = reboot If our system boots on graphical and we want that our system boot on init 3 default, we change the
following line
Id:5:initdefault (here we change 5 with 3)
Looping command for making users
# for USER in name1 name2 name3 name 4 name5
>do
>useradd $USER
>echo redhat|passwd –stdin $USER
>done
Now it will create five users named name1, name2, name3, name4, name5 with password redhat.
CRONTAB
# crontab ‐e ‐u username
*/1 * * * * echo ‘Hello’ > ‘/dev/jy2’
(1*min = 0‐59, 2*hour=0‐23, 3*date=1‐31, 4*month=1‐12, 5*day=0‐7, 0/7 Sunday,1 Monday)
Save file.
# service crond restart (now when user login on 2nd terminal it will get message hello aier every 1 min.)
# crontab ‐l ‐u username (to see how many crontab are running for user)
# crontab ‐r ‐u username (deletes the crontab)
# crontab ‐e (write the command)
40 5 * * * tar ‐cvf backup /home (save file)
19
Now it will take backup of /home at 05:40 AM on daily basis
PARTIT IONS
CreaTng new/home parTTon # fdisk ‐l (for checking the posiTon of harddisk parTTons) # fdisk /dev/hda (to assign whole harddisk)
IDE0 Primary Master hda Primary Slave hdb IDE1 Secondary Master hdc Secondry Slave hdd :n (n for creaTng new parTTon, enter) Again enter Now give the size (ex‐ 10000M) :w (w for save, d for delete)
# partprobe (or restart) Now to format this parTTon # mkfs.ext3 /dev/hda7 (whatever parTTon you have made) Now to mount this parTTon, make a folder (ex‐ /home) # mount /dev/hda7 /home (but this is temporary mounTng) For permanent mounTng # vi /etc/fstab (now do the following entry in the file) /dev/hda7 /home ext3 default 1 2 Save the file. (now if you have permanently mounted the parTTon and now you want to delete parTTon firstly remove the entry from fstab, otherwise your system will be dump)
20
CreaTng Swap ParTTon Firstly if there is swap parTTon in your system, stop swap # free ‐m (to check swap is working)
# swapon ‐s (to check swap is on which parTTon)
First remove the entry of swap from fstab
# fdisk /dev/hda
(delete swap and reboot)
Now create
:n
:l (for seeing the swap code)
:t (to give code)
ParTTon no: 5
Hex code :82 (for swap)
:w (save)
# partprobe
# mkswap /dev/hda5 (to make parTTon swap)
# swapon ‐a /dev/hda5
# e2label /dev/hda5 hda5‐swap (to give label to parTTon)
Now in fstab
LABEL=hda5‐swap swap swap defaults 0 0
:wq (save)
Now reboot your system and you will find a new swap parTTon.
21
RAID
Raid are of two types
1. Soiware Raid
2. Hardware Raid
Here we will learn to implement soiware Raid (Raid1, Raid5)
MD (Metadisk) ( when many harddisk makes a disk)
First create 4 (ex‐ had 7,8,9,10) parTTon of equal size.
Now, for Raid level 5 (minimum three harddisk)
# mdadm ‐C /dev/md0 ‐n3 /dev/had{8,9,10} ‐l5 (by this command we have successfully created
raid level 5)
To format the md0
# mkfs.ext3 /dev/md0
Now mount md0 in a folder
# mkdir /raid
# mount /dev/md0 /raid
To check the status of ra id devices
# mdadm ‐D /dev/md0
# cat /proc /mdstat
To make any parT T on faulty
# mdadm ‐f /dev/md0 /dev/hda10
To remove the parT T on from raid
# mdadm ‐r /dev/md0 /dev/hda10
To add new parT T on in raid array
# mdadm ‐a /dev/md0 /dev/hda7
22
To stop the raid
# mdadm ‐S /dev/md0
Before stopping, we have to unmount raid
To acT vate raid
# mdadm ‐A /dev/md0 /dev/had {7,8,9}
(mount before acTvaTng)
Now for RAID level 1 (Mirroring) (minimum two harddisk required)
# mdadm ‐C /dev/md0 ‐‐chunk=64 ‐‐level=1 ‐‐raid‐devices=2 /dev/had{6,7}
Now format & mount same as above.
LVM {LOGICAL VOLUME MANAGER}
In LVM, parTTons space are merged logically not physically.
Make parTTons of same size (100mb‐ 2 parTTons)
Fi rst c reate Physical Volume (PV)
# pvcreate /dev/hda5 /dev/hda6 or
# pvcreate /dev/hda{5,6}
# pvdisplay (to see whether pv is created successfully)
Now create Volume Group
# vgcreate vg0 /dev/had{5,6} (200 mb)
# vgdisplay (to see whether vg is created successfully)
Now we wi l l create logical volume
# lvcreate ‐L +50M /dev/vg0 ‐n lv0 (it will create a logical volume of 50 Mb{52 Mb})
To extend the logica l volume
23
# lvextend ‐L +25M /dev/vg0/lv0 (it will extend the logical volume to approx. 80 Mb)
To reduce the log ical volume
# lvreduce ‐L ‐25M /dev/vg0/lv0 (it will reduce the logical volume to 25 Mb)
USER QUOTA
Firstly edit file /etc/fstab for adding quota for users
# vi /etc/fstab
LABEL=home /home ext3 defaults,usrquota 0 0
Save the file
# mount ‐O remount /home (remount home parTTons)
# quotacheck ‐cu /home ( to check whether quota is applied or not)
# quotaon /home (to start the quota)
Now, add two users and edit file for user
# edquota user (edit this file) or
# setquota user 512 512 40 50 /home
It will set quota for the user that he can only use 512kb of home parTTon space.
# quotaoff /home (to stop quota)
24
PRINTER COMMANDS
These commands are called CUPS (Common Unix PrinTng System)
1. # system‐config‐printer ‐ To iniTalize Printer graphically
2. # lpstat ‐ To check the status of printer
3. # lprm <job id> ‐ To cancel the prinTng
4. # lpq ‐ To check the prinTng queue status
5. # a2ps ‐ Change normal text to Post Script
6. # ps2pdf ‐ Changes post script to pdf
7. # lpr <filename> <Printer> ‐ Sends prinTng
8. # cancel all or can –a ‐ cancel all prinTng
(if you want to cancel a user prinTng then log on to that user root and then execute this
command.)
SOME IMPORTANT F ILES & COMMANDS
1. # vi .bashrc (This is hidden file & used to create shortcuts for commands)
alias c=’clear’
alias m=’mkdir’
save the file
by typing the above words it will create shortcut for clear and mkdir (c & m)
but aier ediTng file first logout & again login.
2. # vi /var/log/messages (shows audit messages)
3. # vi .exrc (we have to create this file)
:se nu (write this in the file)
Save the file
Aier saving file you will find line numbers already wrijen in every file you open for ediTng.
4. For replacing many words in a file (for ex‐ if we have made a file, in that file many Tmes dog word
is wrijen and we want to replace word dog with cat)
Open file with vi editor and on esc. Mode type
25
:%s/dog/cat/g
5. # sed ‘s/dog/cat/g’ filename (show file with replaced word)
6. $ su (on user, ask for root password and act as root)
7. #su ‐ username (moves directly to user and its directory)
8. # ls –R (Show all files & directory in tree order)
9. # vi .bash_history (history of commands which you have executed)
10. # vi /boot/grub.conf
Tmeout: 50 (here we can change the OS selecTon Tme)
save the file.
SUDO
By this we can give user permission to run a parTcular command or can run all root privileged command.
# vi /etc/sudoers (in this file we have to edit the file & write the user name under the following line)
## Al low root to run any commands anywhere
root ALL=(ALL ) ALL
user ALL=(ALL ) ALL
(here write the username to whom you want to give permission to run root privileged command)
(Note‐ edit this file carefully otherwise your OS could be corrupt)
Now login with that user
$ sudo <root privileged command>
Password (give user password)
26
27
YUM (YELLOW DOG MODIFIER) SERVER
When we install RPM it will ask for dependencies but when we install any package with the help of yum it
will install all dependencies by default.
For making YUM we have to ‐
1. Create a folder named repo
2. Mount CD ROM (# mount /dev/cdrom /mnt)
3. Copy Server, Cluster, ClusterStorage, VT from DVD/CD of RHEL‐5
(# cp ‐Rvf Server Cluster ClusterStorage VT /var/repo)
4. Paste it in folder named repo
5. Delete repodata named folder from all the four folders.
6. Create a file named base.repo
# v i /etc/yum.repos.d/base.repo
[base] name= base baseurl=file:///var/repo/Server enabled=1 gpgcheck=0 [Cluster] name= Cluster baseurl=file:///var/repo/Cluster enabled=1 gpgcheck=0 [ClusterStorage] name= ClusterStorage baseurl=file:///var/repo/ClusterStorage enabled=1 gpgcheck=0 [VT] name=VT baseurl=file:///var/repo/VT enabled=1 gpgcheck=0 (save the file)
28
7. Edit a file named rhel‐debuginfo.repo # v i /etc/yum.repos.d/rhel‐debuginfo.repo
(In this file enabled & gpgcheck must be 0)
8. Now, edit this file
# v i /etc/yum.conf
(Here also enabled & gpgcheck must be 0)
9. Now, edit last file
# v i /etc/yum/pluginconf.d/rhnplug in.conf
(Here also enabled & gpgcheck must be 0)
10. Now we have to group files to create repodata
11. Install standalone service
# rpm ‐ ivh /mnt/Server/createrepo‐0 .4.4‐2. fc6.noarch.rpm
12. # createrepo ‐g /mnt/Server/repodata/comps‐rhel5‐ server‐core.xml
/var/repo/Server
13. # createrepo ‐g /mnt/C luster/repodata/comps‐rhel5‐c luster.xml
/var/repo/C luster
14. # createrepo ‐g /mnt/C lusterStorage/repodata/comps‐rhel5‐c luster‐ st.xml
/var/repo/C lusterStorage
15. # createrepo ‐g /mnt/VT/repodata/comps‐ rhel5‐vt.xml /var/repo/VT
16. # yum clean all
17. # yum l ist al l
18. Now install package from command
# yum instal l <package name>
19. To uninstall package
# yum remove <package name>
20. Now on graphics you will find add/remove program and all packages are there to install.
21. Some commands related to YUM # yum info <package name> Gives informaTon and work of installed package. # yum search <package name> The above command will search all known RPMs, its descripTon, summary and packages installed for that service. # yum l ist <package name>
29
List all installed and available RPMs for that package. # yum whatprovide <package name> Same as search.
30
SQUID SERVER (Proxy in L INUX)
∗ Squid server controls clients computer’s access to the internet.
∗ It blocks the users from accessing undesirable websites and hides the internal idenTty of
the network.
∗ It improves performance by storing WebPages locally.
∗ It is generally used to share internet from one machine to several clients.
∗ Squid server is widely used as Proxy server because it provides many features & is an open
source.
Packages required:
Squid‐2.6.STABLE6‐4.el5.i386.rpm
Port Number:
3128 (default)
Confi guraT on File:
/etc/squid/squid.conf
Service/Daemon:
squid
For squid your system must have two lancard one for internet line & other for your private
network.
1. # yum install squid* or
# rpm ‐ivh Squid‐2.6.STABLE6‐4.el5.i386.rpm
2. Edit file
# vi /etc/squid/squid.conf (in this file set line no. & remove ‘#’ and do following changes)
L ine no. 73
hjp_port 3128
Line no. 993
Cache_dir ufs /var/spool/squid 100 16 256
Line no. 1079
31
access_log /var/log/squid/access.log squid
L ine no. 1087
Cache_log /var/log/Squid/cache.log
L ine no. 1097
Cache_store_log /var/log/squid/squid.log
L ine no. 2522
acl our_networks scr 192.168.1.0 192.168.2.0/24 (here change with your network range)
L ine no. 2523
hjp_access allow our_networks
L ine no. 2778
cache_mgr [email protected] (change with your email‐address or name)
by doing these configuraTon your internet
Now for Access l ist
L ine no. 2409
(there you will find typed acl CONNECT method CONNECT, type under that line)
acl <any name> url_regex <Websites you want to block or iniTals, downloadings>
(acl xyz url_regex orkut mp3 downloading www.gmail.com )
hjp_access deny <above name> (xyz) or
acl xyz url_regex www.google.com (Only this website you want your client to access)
hjp_access allow xyz
hjp_access deny all (save the file)
3. # service squid restart/reload
4. # netstat ‐tulpn |grep 3128 (to check whether squid is working or not)
5. # vi /var/log/squid/access.log (to see the record of website opened by client)
6. Now on client PC
Redhat‐ FireFox‐ edit menu‐ preferences‐ connecTon sexng‐ Manual Proxy sexng‐ Proxy
Server IP‐ __________ Port no. 3128‐ check (use this proxy for all protocols)
On Windows:‐ Internet explorer‐ Tools‐ Internet OpTons‐ connecTons‐ Lan Sexng‐ check
(use a proxy for this lan)‐ Give IP & Port no.‐ OK.
32
DHCP (DYNAMIC HOST CONFIGURATION PROTOCOL)
SERVER
∗ It provides IP address automaTcally to the clients which request for an IP address.
∗ Centralized IP management
∗ DHCP prevents IP address conflicts and helps conserve the use of client IP address on
the network.
∗ DHCP reduces the complexity and amount of administraTve work by assigning TCP/IP
configuraTon is updated automaTcally.
Packages:
dhcp*
Port numbers:
67 Bootp, 68 DHCP
Confi guraT on fi le:
/etc/dhcpd.conf
Service/Daemon:
dhcpd
1. Install dhcp package
# yum instal l dhcp*
# rpm ‐ ivh dhcp*
2. Copy dhcp configuraTon file
# cp /usr/share/doc/dhcp‐3.0.1/dhcpd.conf.sample /etc/dhcpd.conf
33
3. Edit this file
# v i /etc/dhcpd.conf
Subnet 192.168.1.0 netmask 255.255.255.0
OpTon domain name “example.com”
OpTon domain‐name‐servers 192.168.1.1;
range dynamic bootp 192.168.1.10 192.168.1.20;
hardware ethernet __:__:__:__:__:__
fixed address 192.168.1.16
(save file)
In this file we have to give our network range, domain name & its IP (opTonal), range of IP
provided by DHCP and if we want to fix any address for specific user we can reserve IP for that
with the help of MAC address.
4. # service dhcpd restart
5. Now on client set the TCP/IP sexng on obtain an IP address automaTcally & obtain DNS
server address automaTcally.
6. To see what IP is provided to PCs in the network.
# vi /var/lib/dhcpd/dhcpd‐leases
34
DNS (DOMAIN NAME SYSTEM)
Host file provides resoluTon of hostnames to IP address. It can only resolve the names provide
in the local host file. It cannot be used as central database. You can add the name & Ip address
in /etc/hosts file.
# vi /etc/hosts
# Do not remove the following line or various programs
127.0.0.0 localhost.localdomain local host
192.168.1.1 rahul.com server (save the file)
DNS
Provides resoluTon of names to IP address and resoluTon of IP address to names, defines a
hierarchical namespace where each level of a namespace is separated by a ”.”.
Zone‐ Zone is a storage database which contains all zones records.
Forward lookup zone:‐ Used to resolve hostname to IP address. It maintains host to IP
mapping informaTon.
Types of Records:‐
SOA Record:‐ The first record in any zone file. NS Record :‐ IdenTfies the DNS Server for each zone. A record:‐ Resolves a hostname to IP address. CNAME Record:‐ Resolves an alias name to a host name. PTR Record:‐ Resolves IP address for hostname. MX Record:‐ Used by mail server.
Required Packages:
bind‐chroot‐9.2.4‐2.i386.rpm bind‐devel‐9.2.4‐2.i386.rpm bind‐libs‐9.2.4‐2.i386.rpm bind* bind‐uTls‐9.2.4‐2.i386.rpm bind‐9.2.4‐2.i386.rpm caching‐nameserver‐7.3‐3.noarch.rpm system‐config‐bind
Port number: 53‐ DNS Serv ice/Daemon: named
35
1. Install bind
# yum instal l bind*
# rpm ‐ ivh b ind*
# yum instal l caching*
# rpm ‐ ivh caching*
# yum insta ll system‐confi g‐bind*
# rpm ‐ ivh system‐confi g‐bind*
2. Copy the file
#cp /usr/share/doc/bind‐9.3.3/sample/var/named/named.root
/var/named/chroot/var/named
3. Now on graphical terminal‐
(check that in network tab there must be yours IP address in DNS tab)
# system‐confi g‐bind
Now a window comes there r ight cl ick on DNS server‐ add‐ zone‐ internet‐ ok‐
forward lookup zone‐ ok‐ rahul.com (g ive the domain name)(ok)
Now right cl ick on domain name (rahul.com)‐ add‐ IPv4 address (A)‐
www.rahul.com (full domain name)‐ then IPv4 address (192.168 .1….. )
4. # service named restart
5. For reverse lookup zone‐ 255‐ R.C‐ Internet Reverse IPv4 zone‐ R.C.‐ add‐ NS
(Name Server)‐ Server Domain Name: www.rahul.com (save)
6. # service named restart
7. To check whether your DNS server is working
# host www.rahul.com (forward lookup zone)
# host 192.168.1.1 (Reverse lookup zone)
# dig www.rahul.com/192.168.1.1
# nslookup www.rahul.com/192.168.1.1
8. On client PC add your IP in DNS tab in TCP/IP sexngs and ping the domain name, if it
completes successfully, means your forward lookup zone is working and ping ‐a <ip
address>, if it gives domain name it means reverse lookup zone is working. (on windows)
36
NFS SERVER
Sharing of files & folders between Linux.
Packages: portmap‐4.0‐63.i386.rpm
nfs‐uTls‐1.0.6‐4.6.i386.rpm
Port Number:
2049 – nfsd
111 – portmap
Confi guraT on File:
/etc/exports
Service:
portmap
nfs
Daemons:
nfsd
1. Create a folder and make files or paste files you want to share from in network. (ex.‐ /var/dump)
2. Edit file for sharing
# vi /etc/exports
/var/dump *(rw) /var/rahul 192.168.1.15(ro) (save the file) (in first line, we have share /var/dump for all users in a network with read & write permission & in
second line, we have shared /var/rahul only for the PC having IP address 192.168.1.15 with read
only permission)
3. # service nfs restart
4. # service portmap restart
5. # showmount ‐e (To check NFS Server and its shared directory from Server itself)
6. # showmount ‐e <IP address of Server > (To check NFS Server and its shared doc from client)
7. CLIENT END: For taking NFS server service we have to mount directory from server to client
# mount ‐t nfs <server IP>:/var/dump /mnt # cd /mnt (here you will find all the shared material) # cd /net # cd /IP of NFS Server
8. For installaTon from NFS, copy whole DVD/CD in a folder and share it.
37
9. Boot from CD on another client computer, write linux askmethod, here it will ask to select the installaTon media, select NFS, now it will ask to give IP for your client computer, give IP, Now it will ask for Name of NFS Server: <Give IP of NFS Server>, and directory : <Give the path>. Now your system will install very quickly with the help of NFS server.
SAMBA SERVER
∗ Samba is a way a Linux Computer communicate with SMB (Server Message Box) and CIFS.
∗ With Samba, you can make your Linux computer a part of Microsoi based network.
Computers with various Microsoi OperaTng systems can communicate with each other using
the server.
∗ Message Block (SMB) protocol. When a Microsoi based OS shares files or printers on a TCP/IP
network, it uses the CIFS (Common Internet File System).
Confi guraT on Files: Service:
/etc/samba/smb.conf smb
1. # yum install samba* (Install samba package)
# rpm ‐ivh samba*
2. Now, edit file
# vi /etc/samba/smb.conf
(at last of file, pressing ‘G’ copy the following line and paste the lines and then remove ‘;’ infont of
the line.)
[My Share] (Share name) comment= (any comment) path= (here give the path which you want to share) valid users= (Here give samba users) public= no writable=no (Here give the permission you want to give) printable=no save the file.
3. # service smb restart
4. To create Samba users
# useradd <username>
# smbpasswd ‐a <username>
5. To check samba is configured of not
# testparm
6. Samba users entry can be find in /etc/samba/smbpasswd
38
7. On c lient computers: on run: \\<IP address of samba server>
Now it will ask for samba user give username and password.
NIS SERVER
NIS server is just like AcTve Directory Services in Windows. NIS server need NFS server , so it is necessary to install NFS server before NIS.
1. Set the hostname
# hostname rahul.com
2. Set the domainname
# domainname rahul.com
3. Install the package
# yum install ypserv* # rpm ‐ivh ypserv*
4. Now create as many as user you want to create. Share /home in NFS server.
# vi /etc/exports
/home *(rw,sync) (save the file)
5. # service nfs restart # service portmap restart # service ypserv restart
6. # cd /usr/lib/yp
7. # ./ypinit ‐m (in this file it will ask for hostname, add hostname, then ctrl + D)
8. On Client:
# setup (here a window will be open, here mark * in NIS opTon, it will ask for domain & IP‐ OK)
9. # vi /etc/auto.master
/home /etc/auto.misc (save the file)
10. # vi /etc/auto.misc
* ‐rw,soi,intr server IP: /home/& (save the file)
11. # service autofs restart
(Now you client is ready, login with the user that you have created on Server and make file you
will find that file on Server.)
39
APACHE (WEB) SERVER
Apache Server is used for hosTng website for Internet/Intranet. By this server we can also
authenTcate only limited users to access website. For this server you must have DNS server
configured or add your IP and server name in hosts file.
Packages:
hjpd*
1. Install package for hjp.
# yum install hjp* # rpm ‐ivh hjp*
2. Now make a webpage.
# vi /var/www/html/rahul.html
(for single webpage, for virtual hosTng make another page in another locaTon, )
3. Now when we enter the DNS address, apache server welcome screen comes, if we want to
add our own homepage we have to edit a file.
# vi /etc/hjpd/conf/hjpd.conf (at last of the file)
</virtual Host *: 80> (change * with IP address) Document root /var/www/html Servername www.rahul.com </virtual Host> (save the file)
4. # service hjpd restart
5. Now when you enter the Domain name (www.rahul.com) it will open your webpage)
6. AUTHENTICATION:
open the same file and at the end of file, type the following
<Directory /var/www/html> AuthUserfile /etc/hjpd/conf/htpasswd AuthName “Web AuthenTcaTon” AuthType Basic Require Valid‐User </Directory> (save the file)
7. Adduser for hjp
# useradd rahul
# htpasswd ‐c /etc/hjpd/conf/htpasswd rahul
(it creates a new file htpasswd and add user rahul in it)
For adding more user
# htpasswd /etc/hjpd/conf/htpasswd <username> (again start service)
40
8. Virtual HosT ng‐
First copy the above four lines
<Virtualhost *:80> (change * with IP address at both place) Documentroot /var/www Servername www.yahoo.com </Virtualhost>
Come to the lines above these lines # Name Virtual Host *:80 (remove * and # change * with IP address of the system )
SENDMAIL
Packages: Confi guraT on File: send* /etc/sendmail.mc
1. # rpm ‐ ivh ‐ ‐aid send* # yum instal l send*
2. # vi /etc/sendmai l.mc Line no. 116
deamon_opTons (Port=smtp, addr=127.0.0.0,name=mta’) dnl (add dnl # at the beginning )
save the file.
3. # m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf 4. # service sendmail restart 5. MAIL:
# mail [email protected]
41
XEN SERVER (VIRTUALIZATION)
PARAVIRTUALIZATION
For virtualizaTon, first we have to configure NFS server.
1. Install packages
# yum install system‐config‐kickstart*
# yum install virt‐manager*
2. Now copy whole DVD in a folder & share it in NFS & also share that folder in which kickstart file is
saved.
3. # system‐config‐kickstart
(here make a kickstart file, select installaTon by NFS give NFS IP & Directory and save it)
4. Also make a parTTon having 10 GB space and format that parTTon ( do not mount).
5. Now, reboot and select the Xen‐Linux
6. Now on graphical console
# virt‐manager
New‐ forward‐ paravirtualizaTon‐ forward‐ Install media URL: nfs:<IP address of NFS >:/<path>
& kickstart URL: nfs:<IP address of NFS>:<path where kickstart file saved> ‐ next – Normal Disk‐
/dev/<new parTTon created by you> ‐ next‐ finish.
7. Your virtual‐Linux machine is ready to install with the help of NFS.
42
FTP (FILE TRANSFER PROTOCOL)
Required Package
Vsipd*
1. # rpm ‐ ivh vsi pd* # yum instal l vsi pd*
2. # v i /etc/vsi pd/vsi pd.conf
We have to remove # infront of the following lines.
L ine no. 12:
anonymous = default user
(FTP uses two users anonymous & FTP anonymous has no password)
L ine no. 15:
local_enable=yes
(Local user can login through FTP)
L ine no. 18:
write_enable=yes
(write permission is enabled to FTP)
L ine no. 27:
anon_upload_enable=yes
(anonymous user can upload files)
L ine no. 31:
anon_mkdir_write_enable=yes
(anonymous user can create directory )
L ine no. 35:
dir message enable=yes
L ine no. 85:
Ftpd_banner= welcome to FTP
3. # service vsi pd restart
4. Client end:
ip <Server IP>
>cd pub >get <filename> (download) >put <filename> (upload) >bye (exit)
43
TELNET
1. # yum instal l xinetd*
2. # yum instal l telnet*
3. Now we have to edit a file for enabling telnet.
# v i /etc/xinetd.d/te lnet
disabled= no (by default it is yes, we have do it no.)
(save the file)
4. Now give the IP of those PCs from where you will access telnet in hosts file
# v i /etc/hosts
192.168.1.12 pc10 (ex.) (save the file)
5. Start the service
# service xinetd restart
6. Now you must have a user in the server pc with whom you login and aier that with su
command you can take the root access.