Red Hat

Download as pdf or txt
Download as pdf or txt
You are on page 1of 55
At a glance
Powered by AI
The key takeaways are the different types of shells like Unix shell, Linux shell and Bash shell. Bash is the default shell in RHEL. It also discusses the components of GNOME desktop environment.

The different types of shells are Unix shell, Linux shell and Bash shell. Bash is the default shell in RHEL.

The basic commands to manage files from the command line are touch to create empty files, cp to copy files, mv to move files, rm to remove files and mkdir to create directories.

BY

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):

1. How to create Empty file?


#touch <file name>

2. How to create multiple files?


#touch <file name>{1.,20}

3. How to copy a file?


#cp <Source file> <Destination>
Egs: #cp Ram Raj
4. How to move the file?
#mv <Source> <Destination>
Egs: #mv Test / Temp/ or #mv Test1 Test2

5. How to remove the file?


#rm filename

6. How to create a Directory?


#mkdir <directory name>

7. How to create multiple directory?


#mkdir -p<d1><d2><d3>
8. How to delete a directory (Empty)?
#rm -r <directory name>

9. How to delete Directory with content?


#rm -rf <directory name>
Executing basic commands:
#pwd
#ls
#cd
#cd..
#cd../..
#cd -
#cd~
#cd /
#cd videos
#pwd
LINUX FILE SYSTEM HIERARCHY
/ -Super User (Root Directory)
It is the parent of all Directory.
All files on the Linux system are stored on File system
which are organized into a single inverted tree of
directory known as File System Hierarchy.
The Slash ( / ) character is also used as a directory
separator in the file name.
The directory ( / ) is the Root Directory at the top of the
File System Hierarchy.
In RHEL 7.0, there are 2 major changes as given below-
1. RedHat has introduced a new file system called /run.
FILE SYSTEM HIERARCHY RHEL 7.0
/ (ROOT)
___________________________________________|______________________________________________
| | | | | | | | | | | | | | | | | | | |
n /boot /dev /etc /home /Lib /Lib64 /media /mnt /opt /proc /root /run /sbin /srv /sys /tmp /usr /var

/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.

ABSOLUTE PATH RELATIVE PATH

1. It always begins with ( / ) Does not.


Forward slash.
2. Starts at the Root It depends upon the present
Directory. working directory (Pwd)

3.It provides the root map It does not provide .


for the file system Egs: images/images.text
Egs: cd/var/tmp
Getting the help in Red Hat Ent Linux:
#date –help (It will give the Help option for the command)

Using manual pages in Linux:


#man <cmd>
Exp
#man date
It will show the details about the particular command.

Searching for man pages by keyword:


#man –k <keyword>
Egs: #man –k passwd
It will display the list of key word -matching man page topics
with section numbers.
Reading documentation using Info & PInfo
commands:
The Pinfo reader is more advanced than the original info
command.
#info <cmd>
#pinfo <command>
It will display about the particular commands.

Reaching the documentation in usr/share/doc:


#cd /usr/share/doc/
#ls
It will display all the packages or applications
Exp:
#cd /usr/share/doc/
#ls
#cd wget (and press Tab)
#ls
Then you can find so many files where you can get the
details about the cmd and application.

Getting help from RedHat:


Redhat customer poral
(HTTPS://access.redhat.com)
It provides the customer with access to everything
provided with their subscription through -------------
How to create a file?
There are many ways to create files as given below. [ 3 ways-
Touch, Cat, V1 ]
1. #touch <file name> -It will create the empty file.
2. #cat <file name> -It is used to display the contents of the
file.
3. #cat ><file name> -Then add same content
4. (ctl+d) -To save and exit.
This command will over write the file if again go for the edit.
5. #cat >><file name>
To remodify the same file and adding contents in the same file.
6. #vim <file name> Enter. Then press I (Insert) -Write the
contents
ESC (Press)
Shift:
:wq ( To save and Exit )
Modes of VIM:
1. Command mode (By default mode)
2. Insert mode
3. Execute mode

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.

Linux Text Editors:


1. gedit
2. nano
3. v1/vim

#gedit <file name>


It will display the contents of particular file and also we can edit
Text file. It is just like notepad in Windows.
#nano <file name>
Same like gedit, but it is more advanced than gedit.
USERS AND GROUPS ADMINISTRATION:
What is User?
A person who utilizes resources is called User.
Every file is owned by a particular user.

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+

All users details are stored in a file ( /etc/passwd )


The default Home directory for all the normal users are stored
in directory called ( /Home)
Whenever we create user by the name of that user, a group is
also created which is called the
user itself. …
Configuration files details (Fields):
After creating users, the following files will update:
1. /etc/passwd
2. /etc/group
/etc/passwd:
It is having 7 fields-
Username:X:UID:GID:user info:/home/username:/bin/bash
| | | | | | |
1 2 3 4 5 6 7
1. User name
2. X – Encrypted password which is stored in /etc/shadow file
3. UID – User Identification
4. GID – Group Identification
5. User info – It can help the extra information about the user. It is
also called Comment field.
6. /home/username/ - It is the default home directory for the
normal user when they login.
7. /bin/bash/ - It is the absolute path of a command or shell.
Group Fields details:
/etc/group-
It has 4 fields-
Group name:X:GID:User1,User2
| | | |
1 2 3 4
1. Group name- It is the name of Group.
2. X- It is the Encrypted Group password, generally not used.
3. GID: Group Id- Every group must be assigned a group Id (GID).
4. User1,User2: Group list- It is a list of username who are the
members of the group.
All users passwords are stored in a file
/etc/shadow
It has 9 fields-
User name:X:last password change:m:M:W:I:E:::
| | | | | | | | |
1 2 3 4 5 6 7 8 9
1. User name- It is your login name
2. X- Encrypted password
3. Last password change- It represents the Date of last password change.
4. m- Minimum number of days before a password can be changed.
5. M- Maximum number of days before a password must be changed.
6. W- Warning period that a password is about to expire.
7. I- The number of days after password expires that account is disabled.
8. E- Account Expiration date.
9. ::: -This blank field is reserved for future use.
Group Password Information:
/etc/gshadow:
It is having 4 fields-
Group name:!!:bob:user1,user2
| | | |
1 2 3 4
1. Group name- It is the name of group.
2. !!- It indicates Encrypted password for the group.
3. bob- It is a group Administrator.
4. user1,user2- Group members are listed here.
USER COMMANDS:
#Useradd <user name> -To create a new user
#id -Details about root users
#id <user name> -Details about the particular user
#useradd -u 2014 <user name> -To create a user with specific UID
#userdel <user name> -To delete a user (Only user account get
deleted, not its home directory)
#userdel -r <user name> -User account will be deleted along with
home directory.
#useradd -s /sbin/nologin/ <user name> -It will change the shell of
user,so that user cannot login to the system.
#mkdir /dir1
#useradd -d /dir1/user1 user1 -To create a user with its own specific
home directory (Normally it will be created in /home).
#useradd -It is used for fresh user
#usermod -It is used for existing user
#usermod -l <new user name> <old user name> -To change the users
login name.
GROUP ADMINISTRATION:
Every user can be added to a group
Group is a collection of user
Group is identified by GID
Group information will be stored in a file /etc/group

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.

#cat /etc/login.defs -To check this -------


---
Linux File System Permissions
All the above permissions are same for both files and directory.
#ls -l <file name>
To list the File Permission
#ls -ld<Directory name>
To list the directory permission
Structure of file and directory permissions:
File permissions (for root user) – the default permission (644)
Full permission (666)
-rw - r-- r--
User group others
(owners)
6 4 4
Directory permission – the default permission (755)
Full Permission (777)
drwx r-x r-x
user group others
(owner)
7 5 5

Managing permissions from command line:


How to apply permission?
#chmod –[permission] <file/directory>

Either symbolic way or numeric ways.


Symbolic way
#chmodu+rwx<File name>
To add the permissions.
#chmod g-r <File name>
To remove the permissions.
Numeric way
#chmod 642 <File name>
For changing Managing Ownership:

#chmod<user name><File name>


Example:
#chmod v1 file1
How to change Group Ownership:
#chgrp<Group name <File name>
Note:By default, all files and directory owner and group
owner will be root.
UMASK (User Mask)
It’s Decides the default permission for the file and
directory to be created.
For root user
#umask
022 is the umask for the root user by default
To change the umask value
#umask<user mask value>
Example:
#umask 246
For normal user
#umask
022 is theumask value for the normal user by default.
For file (root user)
Default permission = Full permission - umask value
= 666 - 0022
= 644
For directory: (root user)
Default permission = full permission – umask value
= 777 - 0022
= 755
For file (Normal user)
Default permission = full permission – umask value
= 666 - 0002
= 664
For directory (Normal user)
Default permission = full permission – umask value
= 777 - 0002
= 775
Note: The first field of the umask value is always reserved for
special permission.
To change umask permanently
You have to give the entry in the below file
/etc/bashrc
Special permissions
Set UID (u+s) (4)
Set GID (g+s) (2)
Sticky bit (o+t) (1)

(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 –

#kill -15 4016


#killall -signal <process name>
Eg –
#killall -15 Firefox
How to renice the process:
#renice -n <nice value><Process ID>
eg–
#renice -n 5 2049
To renice the priority of the nice value.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy