Anda di halaman 1dari 23

`

Basic command (part -1)

1) to login as root (administrator) user (in rhel 7)


click on not listed
username root
password redhat

2) to open the terminal


a) right click then click on open in terminal
b) click on application then on terminal
c) press Alt F2 then write gnome-terminal

3) to increase size of terminal


press Ctrl shift +

4) to decrease size of terminal


press ctrl -

5) to get full screen


press F11

6) to clear the screen


#clear or press Ctrl l

7) to login as multiple user using virtual console


Note : we haveby default six virtual console,
only one will work in graphiacal mode
press Alt Ctrl F1(graphical mode)
remaining five will work in text mode
press Alt Ctrl F2 to F6(text mode)

8) login prompt information


[root@localhost~]#
where root= username(which user has login)
localhost=systemname
~=login user home directory symbol
# = privileage of root user
note a) # indicate max access(privileage)
# sign access will appear only for root user
note b) Except root user, for all other user
we get $ symbol
$ sign indicate min (limited access)

9) to chk user working directory


#pwd
where pwd stand for print the user working directory
Note: if we want to know description of any command
we have the help and for help we have to use #man

for ex #man pwd


to come out from help press q

10) to change the working directory


#cd where cd stand for change directory
ex #cd /boot
11)to chk the content in any directory
#ls where ls stand for lists
#ls /var

12) to chk root content


#cd
#ls
Note a)directory(folder) colour is blue
b) file(text) colour is black

13) to hide the colour of file and directory


#\ls

14) to chk the properties of files and directories


#ll ( where ll is long lists)
or
#\ls -l
note a)for directory: The first character wiil be d
b) for file : the first character will be -

15) to chk hidden files and directories


#ls -a

16) to chk the date of the machine


#date

17) to chk the calender


#cal (for present month)
#cal 2018(for whole year)

18) to chk kernel version


#uname -a
or # ls /boot

19) to chk cpu detail


#lscpu

20) to chk operating system version


#cat /etc/redhat-release
or #cat /etc/centos-release

21) to search files and directories


#find / -name Desktop (file or directory name)

22) to restart the machine


#init 6 or #reboot

23) to shutdown the machine


#init 0 or #poweroff or #shutdown

practical for basic command


1) cat
a) create the new file
# cat > redhat
this is the root file
to save the file
press Ctrl d
to chk the file
#ls or #ll
b) to read the file
#cat redhat
c) to append the file
#cat >> redhat
this is created on wednesday
to save file
press Ctrl d
to chk the result
#cat redhat

2) touch
a) to create single file
# touch banjarahills
to chk
#ls
b) to create multiple files
#touch ccna linux vmware
to chk
#ls
another method
#touch hyd{1..8}
#touch hyd{a..d}
to chk
# ls

3) vi

creation of directory(folder)
a) single directory(folder)
# mkdir zoom
to chk
#ls or #ll
b) multiple dirctories (folders)
#mkdir mcse hardware firewall cisco
to chk
#ls
another method
#mkdir india{1..9}
#mkdir india{a..e}
to chk
#ls
c) parental directory
#mkdir -p a/b/c/d/e
to chk
#ls -R a
to enter into c directory
#cd a/b/c
to chk
#pwd
to go next directory
#cd d
to move two steps backward
#cd ../..
to come out from directory to user home directory
#cd
to go to last working directory
#cd -
to come out
#cd

COPY
a) copy file(old file) into file(new file)
#cp -rv redhat centos
to chk
#ls
#cat redhat(to read the file)
#cat centos
b) copy file into directory
#cp -rv redhat(filename) zoom(directoryname)
to chk
#cd zoom(to enter into directory)
#ls (to chk the filename)
#cat redhat(to read the file)
#cd (to come out from directory)
another method
#ls zoom( to chk filename inside directory)
#cat zoom/redhat( to read the file which is inside the directory)
c) copy file (old) into another file(exiting file) without overwrite
#cat > unix
this is unix file
to save the file
press Ctrl d
#cp -rv redhat (old file) unix(existing file)
n
#cat redhat >> unix
to chk result
#cat unix

RENAMING
a)file
#mv redhat(old name) bluehat(new name)
to chk
#ls
b) directory
#mv zoom(old name) moon(new name)
to chk
#ls

REMOVING(DELETING)
a) file
#rm bluehat
give y(yes)
to chk
#ls
b) directory
#rm -r moon
give y
to chk
#ls
to remove both files and directories without confirmation
#rm -rf hy* in* mcse linux
to chk
#ls

USER ADMINISTRATION COMMANDS


1) to create new user account
#useradd u1(username)
to chk user detail
#grep u1 /etc/passwd
#grep u1 /etc/shadow
2) to assign password to user
#passwd u1
give the password(2 times)
to chk
#grep u1 /etc/shadow
3) to change the age of user password
#chage u1
give the value as per the requirement
to chk
# grep u1 /etc/shadow
4) login as user
a) from root terminal
# su u1
note) then the user will login root home directory(/root)
to chk
$pwd
to come out from user
$exit
another method
# su - u1
note) the user will login to user own home(/home)
to chk
$pwd
to logout from user
$logout

b) from graphical mode


#gdmflexiserver
click on username and give the password
then logout from user
c) from text mode
press Alt Ctrl F2
login give the name
password
then $logout
press Alt Ctrl F1 (to come to graphical mode)

5) to lock the user from login


#usermod -L u1
to chk the result
try to login as user by using
#gdmflexiserver
or press Alt Ctrl F2
try to log is user by giving the username and password
result: user cannot login
press Alt Ctrl F1 (to come to graphical mode)
6) TO unlock the user from login
# usermod -U u1
to chk the result
try to lgin as user by using
#gdmflexiserver
or press Alt Ctrl F2
try to login as user
Result : the user can login
then logout from user
press Alt Ctrl F1 (to come to graphical mode)
7)to chk type of shells
#cat /etc/shells
#grep u1 /etc/passwd

8) to change uid, to write comment and to change the shell of user


#usermod -u 2018 -c "it dept" -s /bin/sh u1
to chk
#grep u1 /etc/passwd
9) to change home directory of new user
# vi /etc/default/useradd
press i (to go to insert mode)
go to 3 line remove /home in HOME
then write HOME=/opt
then press esc key and then press shift :wq
now create the new user
#useradd u2
to chk
#tail -2 /etc/passwd
then change home directory to /home
#vi /etc/default/useradd
press i 3 line remove /opt and write HOME=/home
press esc :wq

10) to delte user account


#userdel -r u1

GROUP ADMINISTRATION PRACTICAL

1) to create the group


#groupadd linux
to chk
#grep linux /etc/group
#grep linux /etc/gshadow

2) to assign group passwd


#gpasswd linux
give the passwd (2 times)
to chk
#grep linux /etc/gshadow

3) create the users


#useradd u1
#useradd u2
#useradd u3
#useradd u4

4) add multiple users into group


#gpasswd -M u1,u2 linux

5) add single user into group


#gpasswd -a u3 linux
to chk
#grep linux /etc/group

6) to delete user from group


#gpasswd -d u2 linux
to chk
#grep linux /etc/group

7) to make one of the user as group admin


#gpasswd -A u1 linux
to chk
#grep linux /etc/gshadow
note: The group admin will get extra privileges like
adding or removing the users from group
(which normal group members cannot do)

8) to remove group admin


#gpasswd -A "" linux
to chk
#grep linux /etc/gshadow

9) to change gid of group


#groupmod -g 2018 linux
to chk
#grep linux /etc/group

10) to change group name


#groupmod -n mcse linux
to chk
#grep mcse /etc/group

11) to delete group


#groupdel mcse

BASIC FILE PERMISSIONS


1) create the file
#cat > redhat
this is the root file
to save the file
press Ctrl d

to chk the permission of the file


#ls -ld redhat

2) to modify the permission of the file


#chmod 756 redhat
oR #chmod u=rwx,g=rx,o=rw redhat
to chk
#ls -ld redhat

3) to assign permission to group


#groupadd linux
#useradd l1
#useradd l2
#gpasswd -M l1,l2 linux
to chk
#grep linux /etc/group
#ls -ld redhat

to change the group owner of the file


#chgrp linux redhat
to chk
#ls -ld redhat

4) to change the owner of the file


#useradd ravi
#chown ravi redhat
to chk
#ls -ld redhat

ACCESS CONTROL LIST(ACL)


1) create the users
#useradd u1
#useradd u2
#useradd u3
2) apply different permission by using acl
#setfacl -m u:u1:r,u:u2:rw,u:u3:0,g:linux:6 redhat
to chk
#getfacl redhat
3) to allow users to enter into /root directory
#chmod 755 /root
4) to verify the result
login as user
#su u1
to chk permission
$ getfacl redhat
to read the file
$cat redhat
to write into the file
$cat >> redhat
to come out from user
$ exit
note: login as other users and verify the permmision

5) how to chk on which file or folder acl is applied


#ll or #ls -l
note + sign will appear after permission
6) to remove acl for particular user
#setfacl -x u:u1 redhat
to chk
#getfacl redhat
#ll
7) to remove acl completely
#setfacl -b redhat
to chk
#getfacl redhat
#ll

PARTITION
1)to chk type of harddisk, total size of harddisk and number of partions
in the harddisk and also pendrive
#fdisk -l

2) to chk free space


#parted
write print freespace
to come from parted command
press q

3) to chk RAM size and swap size


#free -m

4) to chk prtition size in human readble format


#df -h

to create new partition


1 stage
allocating size to new partition
#fdisk /dev/sda
press m (for help)
press p (for print)
press n (new partition)
press enter two times to give the size in BYTES
+100M
press w(write and exit)
to update the new partition to kernel
#partprobe /dev/sda (rhel 7)
note: #partx -a /dev/sda (rhel 6)
to chk new partition
#kpartx /dev/sda

2 stage
formating the new partition

#mkfs.ext4 /dev/sda8
to chk
#blkid
3 stage
mounting: accessing new partition with directory
#mount /dev/sda8 /mnt
or #mkdir /zoom
#mount /dev/sda8 /zoom
to chk
#mount
#df -h
to make permanent mounting
#vi /etc/fstab
go to last line then prees i (to go insert mode)
then press enter (to come to empty line)
then write this
/dev/sda8 /zoom ext4 defaults 0 0
then press esc then :wq
to chk
#mount -a

Disk quotas

1) chk the existing partition and format it


#fdisk -l
# mkfs.ext4 /dev/sda8

2) enable the disk quota on the partition


#mount -o usrquota,grpquota /dev/sda8 /opt

3) create the database for disk quota


#quotacheck -cug /opt

4) make the disk quota on


#quotaon /opt
to chk
#quotaon -p /opt

5) create the user


#useradd u1

6) apply block quota to user


#edquota -u u1
press i (to go insert mode)
blocks soft hard
0 4 6
press esc the :wq

7) give the full permission on /opt


#chmod 777 /opt

8) to verify the result


login as the user
#su u1
$cd /opt
$mkdir r1 r2
to chk block size for each file/folder
$ls -sh
$mkdir r3
$mkdir r4
$mkdir r5
to logout from user
$exit
9) to increase the limit
#edquota -u u1
press i
blocks soft hard
6 4 8
press esc then :wq
again login as user and chk the result
#su u1
$cd /opt
$mkdir r6
$ls -sh
$exit
10) to make disk quota off
#quotaoff /opt
to chk
#quotaon -p /opt

LVM
1 stage
allocating size to multiple partitions
#fdisk /dev/sda
press p (for print)
press n (for new partition)
then press enter two time and give the size
+100M
to create another partition repeat the same thing
press n then press enter two time and give size
+200M
then w(write and exit)
to update new partitions to kernel
#partprobe /dev/sda (in rhel 7)
to chk
#kpartx /dev/sda
2 stage
creating the lvm

a) create the pv
#pvcreate /dev/sda8 /dev/sda9
to chk
#pvdisplay

b) create the vg
#vgcreate linux /dev/sda8 /dev/sda9
to chk
#vgdisplay

c) create the lv
#lvcreate -L +100M linux -n zoom
to chk
#lvdisplay

3 stage
formating the lvm
#mkfs.ext4 /dev/linux/zoom
4 stage
mounting the lvm
#mount /dev/linux/zoom /mnt
to chk size
#df -h
to resize the partition size
#lvresize -L +100M /dev/linux/zoom
to update
#resize2fs /dev/linux/zoom
to chk
#df -h
to remove the lvm
#umount /mnt
#lvremove /dev/linux/zoom
give y
#vgremove /dev/linux
#pvremove /dev/sda{8..9}
swap
1) create the partition
#fdisk /dev/sda
press n
press enter 2 times then give the size +100M
press w
to update new partition to kernel
#partprobe /dev/sda
to chk
#kpartx /dev/sda
2) format the partition
#mkswap /dev/sda9
3) to chk swap size
#free -m
4) to increser swap size
#swapon /dev/sda9
to chk
#free -m

5) to reduce swap size to original valve


#swapoff /dev/sda9
to chk
#free -m

RAID
Raid level 5
1) chk the existing partition
#fdisk -l

2)create the raid level 5


#mdadm -C /dev/md9 -n3 /dev/sda{8..10} -l5
give y

to chk
#mdadm -D /dev/md9

3)format the raid


#mkfs.ext4 /dev/md9

4)mount the raid


#mount /dev/md9 /mnt
5) create the data in raid
#cd /mnt
#mkdir linux{1..200}
to chk
#ls

6) make one of the partition as faulty in raid


#mdadm -f /dev/md9 /dev/sda8
to chk
#mdadm -D /dev/md9
to chk the data
#ls

7) remove the faulty partition


#mdadm -r /dev/md9 /dev/sda8
to chk
#mdadm -D /dev/md9

8) add the partition


#mdadm -a /dev/md9 /dev/sda8
to chk
#mdadm -D /dev/md9
#ls

9) to stop the raid


first come out from mounted directory
#cd
then break the mount link
#umount /mnt
#mdadm -S /dev/md9
to chk
#mdadm -D /dev/md9

to restart the raid


#mdadm -A /dev/md9 /dev/sda{8..10}
to chk
#mdadm -D /dev/md9
to stop the raid
#mdadm -S /dev/md9
to chk
#mdadm -D /dev/md9

Backup And restore


1) tar

#mkdir zoom
#cp -rv /etc zoom

to chk the orinial data of zoom directory


#du -sh zoom

to take the backup of zoom directory by using tar and also


compresses with gunzip tool
#tar -cvzf /mnt/backup.tar.gz(destination) zoom(source)
where c=copy,v=verbose,z=symbol of gunzip,f=file/folder
gz=extension of gungip
to chk compressed size
#du -sh /mnt/backup.tar.gz

remove the original data


#rm -rf zoom
to chk
#ls

Restore
#tar -xvf /mnt/backup.tar.gz
where x= extract and restore

to chk
#ls
#du -sh zoom

2) cpio
to chk file and folders
#ls

to take backup of multiple file and folder using cpio


# ls -d redhat(file) Music(folder) | cpio -ov > /mnt/bk.cpio
to chk
#ls /mnt

remove the original data


#rm -rf redhat Music
to chk
#ls

REstore
#cpio -iv < /mnt/bk.cpio

to chk
#ls

Network Administration

1) to chk nic card name and ip address


# ifconfig

2) to assign temporary ip address(in lab)


#ifconfig enp1s6 192.168.0.1
to chk
#ifconfig

3) to make ip address permanent


#nmtui (in rhel 7) (in rhel 6 it was #setup)
where network manager text user interface
then edit a connection then edit then configuration ipv4
then manual then
ip addresses 192.168.0.1/24 then ok then quit then
# service network restart
to chk ip add
#ifconfig

Package management
Network method
Nfs service For nfs mounting is required
# mount 192.168.0.250:/var/ftp/pub/centos7 /media (in lab)
#mount /dev/sr0 /media (for laptop)
#cd /media
#ls
#cd Packages
#ls
RPM command(tool)
1) to chk (query) the package is install or not
#rpm -q zip
#rpm -q zsh
2) to install the package
#rpm -ivh zsh* --force
where i=install v=verbose h=hash
to chk
#rpm -q zsh
3) to update the package
#rpm -Uvh zsh* --force
where U=update
4) to remove the package
#rpm -e zsh
where e=erase
Note: when we remove the package we should not give *,it will remove the
dependencies of the package
to chk
#rpm -q zsh

yum command(tool)

1) to chk the package is install or not


#yum list samba
Note
a) if package is not install we get last word as base
b) if package is install we get last word as @base

2) to install the package


#yum install samba* -y
to chk
#yum list samba
3) to update the package
#yum update samba* -y
4) to remove the package
#yum remove samba -y
to chk
#yum list samba

FTP SERVER
1) chk ip address of your machine
#ifconfig
#dhclient -v
#ifconfig
2) install the package
#mount /dev/sr0 /media
#yum install vsftpd* -y
3) open the configuration file
#vi /etc/vsftpd/vsftpd.conf
press :se nu (to set line numbers)
go to 29 line remove #(for allowing uploading)
:wq (save and exit)
4) give the full permission on default directory
#chmod 777 /var/ftp/pub
5) go inside the directory
#cd /var/ftp/pub
6) create the file for transfering(sharing)
# touch ftpserverfile file1 file2
7) restart the service
#service vsftpd restart
#iptables -F(to disable/flush iptables)
#setenforce 0(to disable selinux)

to chk the result go to other machine

FTP client
Downloading: receiving the file from ftp server to ftp client
1) chk ip address
#ifconfig
ping to your ftp server (for checking connection)

2) install the package


#yum install ftp* -y

3) access the ftp server


#ftp 192.168.0.9(give your ftp server ip address)
name ftp or anonymous
password press enter
ftp > cd pub
> ls (to chk files)
to download the files
> get ftpserverfile(single file)
> mget file1 file2(multiple files)
to come out from ftp mode
#bye or #exit
then to chk the file
#ls

UPLOADING: sending the file from ftp client to ftp server

FTP client
1) create the files (in client machine)
#touch clientfile c1 c2

2) access the ftp server


#ftp 192.168.0.9(give your ftp server ip)
name ftp
password press enter
ftp > cd pub
to upload the files
> put clientfile (single file)
> mput c1 c2 (multiple files)
> bye
to chk the result go to ftpserver
in ftpserver go to default directory
#cd /var/ftp/pub
#ls (to chk the file)

NFS server

1) chk ip address
#ifconfig
2) install the package
#yum install nfs* -y

3) create the folder in / location


#mkdir /india

4) give the full permission on folder


#chmod 777 /india

5) open the configurtion file


#vi /etc/exports
press i (to go insert mode)
/india *(rw)
press esc (to go to command mode)
press shift :wq(to save and exit)

6) go to share folder
#cd /india

7)create the files and folders for sharing


#mkdir nfsdir
#touch nfsfil

8) restart the service


#service nfs restart
to chk the result go to other machine

NFS client
1) chk ip address
# ifconfig
then ping to your nfs server(to chk cconnection)

2)to know the share folder name


#showmount -e 192.168.0.9(give your nfs server ip address)

3) mount to the share mount


#mount 192.168.0.9:/india /mnt
#cd /mnt
#ls

Dns server practical

1)chk ip address
#ifconfig
#dhclient -v( to assign ip through dhcp)
#ifconfig ( to chk ip)

2)install the package


#mount /dev/sr0 /media(vmware)
#yum install bind* -y

3) assign the hostname


#hostname dns.india.com

to update systemname
#bash
to make hostname permanent
#vi /etc/hostname
press i (to go to insert mode)
delte the exiting name
then write dns.india.com
press esc then :wq (to save and exit)

4) open the configuration files


#vi /etc/named.conf
press :se nu (to set line number)
press i (to go to insert mode)
go to 11 line write your sys ip; ex 192.168.0.9;
go to 17 line write any;

then press esc :wq

# vi /etc/named.rfc1912.zones
press :se nu
press i
to create forward lookup zone
go to 19 line remove localhost and write
your domain name ex "india.com"

to create reverse lookup zone


go to 31 line remove loopback ip and
wtite your sys network in reverse order
ex 0.168.192
press esc :wq

5) go to dns file
#vi /etc/resolv.conf

remove all the lines and


then write nameserver your sys ip ex nameserver 192.168.0.9
press esc :wq

6) go to default directory
# cd /var/named
#ls

7) create the records in forward lookup zone


#vi named.localhost
go to last line then press i then press enter

sys name A sys ip


ex dns A 192.168.0.9
press esc :wq
8) create the records in reverse lookup zone
#vi named.loopback
go to last line then press i then press enter

host ip PTR hostname.


9 PTR dns.india.com.

press esc :wq

9) restart the dns server service


#service named restart
#iptables -F (to disable iptables)
# setenforce 0(to disable selinux)

to chk dns server


forward lookup zone
#nslookup dns.india.com(hostname)
or #dig dns.india.com

reverse lookup zone


#nslookup 192.168.0.9(dns server ip)
or #dig -x 192.168.0.9

to chk the result


go to another machine

dns client
1) chk ip address
#ifconfig

2) go to dns file
#vi /etc/resolv.conf
remove all the lines(by using dd)
press i (to go insert mode)
then write nameserver dns server ip
ex nameserver 192.168.0.9
press esc :wq
#ping dns.india.com(dns server name)

APACHE WEB SERVER

1) chk the ip address


#ifconfig

2) install the package


#yum install httpd* -y

3) assign the hostname


#hostname www.india.com

to update the system name


#bash

to make hostname permanent


#vi /etc/hostname
press i ( to go insert mode)
then write www.india.com
press esc then :wq

4) open the configuration file to host the website


#vi /etc/httpd/conf/httpd.conf
go to last line by using G
press i(to go insert mode)
then enter(to go empty line)
then to host the website write
<virtualhost *:80>
servername www.india.com
serveradmin root@www.india.com
documentroot /var/www/html
directoryindex india.html
</virtualhost>
then press esc then :wq
5) go to default directory
#cd /var/www/html
6) create the webpage by using html language
#vi india.html
press i (to go insert mode)
<html>
<body bgcolor=blue>
<marquee> <h1> WELCOME TO INDIA.COM </h1></marquee>
</body>
</html>
then press esc then :wq

7) restart the service


#service httpd restart
#iptables -F(to disable iptables)
#setenforce 0(to disable selinux)

to chk the result go to other machine

CLIENT
1) chk the ip address
#ifconfig

2) to access the website by name by using hostfile


#vi /etc/hosts
press i(to go insert mode)
127.0.0.1 localhost.localdomain localhost
write your webserver ip website name
press esc then :wq
3) to access the web site
now open the browser
#firefox
www.india.com

DHCP SERVER

1) CHK IP ADDRESS
#ifconfig

2) install the package


#yum install dhcp* -y

3)open the configuration file


#vi /etc/dhcp/dhcpd.conf
:q

4) go to location of example file


#cd /usr/share/doc/dhcp-4.2.5
#ls

5) copy example file into main configuration file


#cp -rv dhcpd.conf.example /etc/dhcp/dhcpd.conf
y

6) open the configuration file


#vi /etc/dhcp/dhcpd.conf
:se nu(set the line number)
press i(to go to insert mode)
40 give the nework id
Ex 192.168.0.0 255.255.255.0
41 give ip address range
Ex 192.168.0.1 192.168.0.30
42 give the broadcast ip
EX 192.168.0.255
49 give the dns server ip
Ex 192.168.0.9
51 give the router ip address
Ex 192.168.0.1
press esc then :wq

7) restart the service


#service dhcpd restart
#iptables -F(to disable iptables)
#setenforce 0(to disable selinux)

to chk the result go to the other machine

DHCP CLIENT
1) chk ip address
# ifconfig

2) to assign ip address through our dhcp server


#dhclient -v
to chk
#ifconfig
to remove ip addrsss
#dhclient -r

POSTFIX MAIL SERVER


1) chk ip address
#ifconfig

2) install the package


#yum install postfix* -y

3) assign the hostname


#hostname mail.india.com
to update systemname
#bash
to make hostname permanent
# vi /etc/hostname
press i (to go insert mode)
mail.india.com
press esc :wq
4) open the configuration file
#vi /etc/postfix/main.cf
:se nu (to set line number)
press i (to go insert mode)
75 remove # write our hostname ex mail.india.com
83 remove # write domain name ex india.com
press esc then :wq

5) create the users


#useradd u1
#useradd u2
6) restart the service
#service postfix restart
#iptables -F
#setenforce 0
to chk the result
login as user
#su - u1
send the mail to u2
$mail u2@mail.india.com
subject: Testing the mail

Hi,
How are you?
to send the mail
press Ctrl d
to logout from user
$exit

to chk the mail


login as u2
#su - u2
to read the mail
$mail
give the number 1

to come out
$exit
$exit