Red Hat
Red Hat
Red Hat
Ishan infotech
RH-124 (unit 1)
What is Bash shell?
It is a command line interface which is used to input the instruction into
Linux box. The Linux command line provided by a program called the
shell.
The types of Shell
1. Unix Shell (the default shell for Unix called shell)
2. Linux Shell (the default Shell for RHEL is bash)
What is bash
Bash (bourne-again shell)
The types of shell prompt
1. Root user (#)
2. Normal user ($)
Feature of Bash prompt
1. Tab completion
2. command history
3. Editing the command line
Basic Shell
There are three basic parts of command
1. command (The command to be executed)
2. Options (to adjust the behaviour of the command)
3. Arguments (The targets of the commands)
example:
#date -s yy-mm-dd
here date is command
-s is the option and
yy-mm-dd is arguments
examples of some simple commands
#date
To check date & time
#passwd
to change the root password
#passwd <username>
to change the password to normal user
#file <filename>
to check the file type
#head <filename>
to display first 10 lines from the file.
#tail <filename>
to display the last 10 lines from the file
#wc -l <filename>
to count number of lines in a file.
#wc -w <filename>
to count number of words in a file.
#wc -m <filename>
to count number of character in a file.
#wc -c <filename>
to display bytes of data in a file.
#ls
to listing the contents
#ls -l #ls –ld #ls –a #ls –ll #ls –R #ls -r #ls -lrt
#pwd
to check the current path location
#su
switch user for (root)
#su <username>
switch normal user
#echo welcome to Linux
it will print the same statements
#which <ping>
it will display the entire pathe of the command.
what is GNOME
It is default desktop environment for RHEL.
GNOME- Graphical Network Object Model Environment.
RHEL-6.0- GNOME2
RHEL-7.0- GNOME3
The Component of GNOME
-Toolbar
-Application
-Place menu
-Windows list
-Message tray
-Workspace- it is desperate desktop screens which have
different application windows (bydefault4)
MANAGE FILES FROM COMMAND LINE:
Create, copy, move, remove Files and Directory using Command
Line Interface (CLI):
/bin
/boot
/dev
/etc
/home
/lib
/lib64
/media
/mnt
/opt
/proc
/root
/run
/sbin
/srv
/sys
/tmp
/usr
/var
Difference between absolute path and relative path:
The Path of a file or a directory to its Unique File System location.
Command mode:
J -Jump down
k -Jump up
l -Jump right
h -Jump left
b -Moves word to word back
w -Moves forward word to word
G -Go to the end of file
gg -go to the top of file
yy -(yank) -- To copy the lines from the file (Single file)
5yy -It will copy 5 lines from the file
p -Paste below
P -Paste above
dd -To delete (Single line)
5dd -5 lines delete
u -Undo
ctl+r -Redo
Insert mode:
A –Append to the end of a line
i, I (Insert bottom) – To insert into VIM
o – To create one blank line below
O – To create one blank line above
:se nu – To set the line number
:se no nu – To no set line number
Execute mode:
To come out from the file, first press Esc button, then press (Shift:)
to go to Execute mode.
:q -Quit.
:q! -Quit forcefully.
:wq -Save and Exit.
:wq! or !x or Press Shiftzz –Save and exit forcefully.
How to open multiple files in VIM editor?
#vim -o <file1> <file2>
#vimtutor
It will give you details about the vim editor workings.
Types of User:
1. Super user (Root user)
2. System user (ftp, ssn)
3. Normal user (Mani)
These 3 are main users and apart from these, we have
additional few users like
4. Network user
5. Sudo user
Every user can be identified by its UID.
UID – User Identification
1. Root user UID – Infinity …
2. System user UID – 1 to 999 …
3. Normal user UID – 1000+
GROUP COMMANDS:
#groupadd <group name> -To create a new group
# groupadd -g 2049 <group name> -To create a group with
specific GID
#groupdel <group name> -To delete a group
existing new
#useradd -g <group name> <user name> -To create a user with
own primary group.
#useradd -G <group name exist> <new user name> -To create a
user with secondary group.
#gpasswd -M V1,V2,V3 <group name> -To add multiple users to a
particular group. Both users and group should be created
before.
#gpasswd -d u1,u2 <group name> -It will delete particular users
from the group.
#gpasswd -a <user name> <group name> -To add the user again
to the group. If you remove any user from the group and again if
you want to add same user in group, then you can give this
command.
Managing users password:
Password Ageing Policy:
chage is the command to display and adjust the user’s
password ageing attributes.
#chage <options> <user name>
#chage -l <user name> -It will display the password
ageing attributes for the particular user
#chage -m 3 -M 10 -W9 <user name> -To apply the
attributes of the password ageing policy.
#chage -E yy-mm-dd username -To set the expiry date
of user.
#chage -d <user name> -It will force the user to
change the password at next login. ------
Password Ageing Attribute details:
#chage -l -It will list you the options available for the change of users
password policy where below are the descriptions about each options:
-l -It will show the list of account ageing information.
-d -It will save the date of last password change
-m -Minimum number of days the password should be changed.
-M -Maximum number of days the password must be changed.
-W -
-------
-I -It will set the inactive
-E -Password expiry date for the user account.
/etc/login.defs -It is the files where all password ageing attributes are
stored.
(Symbolic) (Numeric)
SUID
SUID stands for set user id.
It allows application to be run by normal user with the privileges of root
user.
Example: Application ping has suid enabled by default the owner is root,
but normal user also can run the ping command with privilege of root
user.
Commands for special permissions:
#ls -l /usr/bin/ping
To check the default permission of the ping cmd.
-rwsr-xr-x
u g o
To apply the special permission:
#chmodu+s<Application of the cmd>
#chmod u-s /usr/bin/ping
#su – student
$ping 192.18.10.x
It will show the operation not permitted, which means that if we
remove the default suid permission from the ping application then
the normal user cannot run the ping cmd.
sgid (g+s) [2]
Sgid stand for set group id.
It is used for group in heritance.
when sgid is applied to directories, sub directories and files
created by some user on those particular directory would have the
primary group of the parent directory irrespective to owners
primary group.
Example:
#mkdir -p /raj/redhat
#groupadd sales
#chgrp sales /raj/redhat
#touch f1
#ls -l -f1
#chmodg+s /raj/redhat
#cd /raj/redhat
#touch f2
#ls -l f2
It will show “sales” as the group owner for all the file and directory
got created inside this parent directory.
Stickybit (o+t) [1]
it is applied to restrict other for deleting each other file.
When stickybit is applied only owner of the file & root user can
delete them.
Root user can delete them even if the stickybiit is applied.
Monitoring and Managing Linux Process
Understand process, priority and signal concept
Process
It is an instance of running program, that is being executed.
It contents the program code and its current activity.
Every process can be identify the PID (Process ID).
Types of process:
Foreground process.
Background process.
Process states code:
D Uninterruptable sleeping process
R Running or runnable process.
S Interruptible sleeping process.
T Terminated process.
X Dead process.
Z Zombie process.
Note: in RHEL 6.0 “init” is the first process and in RHEL 7.0 they have
introduce new init system called “system”.
Priority
Every process is having priority for execution in linux we call it
nice value, that decide the priority of the process.
Its range from (-20 to +19)
Higher the priority , lower is nice value and vice versa.
Signal
Signal are used to communicate with the process while
process is in execution inside the processor.
So signal are used to manage, monitor, terminate the
processes.
Signals can be number or name.
#man 7 signal
To view the information about the signals.
There are 64 signals.
Commands to Manage the Process
Listing process
There are two way to monitor and manage the process.
p8 (static)
top (Dynamic)
p5 commands:
#p5
To list the process status.
#p5 -a
To list the all process.
#p5 -all
To list all user process.
#p5 -aux
To list both foreground and background process.
#ps -e
To list the every process.
#p5 -ef
To list every full process.
#p5 -elf
To list more detail about the process.
#p5 -e0 pid, ni, cmd, pri<cmd name>or<PID>
To customize the p5 cmd. Whatever we have monitor in
that cmd detail will display.
Top Commands
#top
It will check the process online information; it will update information in
every 3 second.
Command Actions
Press H
For help
Press F
Find the particular process.
Press K
To kill the process, after that give PID and Signal
……………………………………………………
Press R
To renice the process, after press R give the PID and give the nice value
to change the priority of the process.
Press Q
To carry out of the top utility.
How to kill the process with the p5 cmd
#Firefox
eg – here we are starting one process called firefox,
Then we can check process running status.
#p5 -aux <Firefox> or it<PID of Firefox>
#kill -signal <PID>
To kill the particular process with PID
eg –