Sei sulla pagina 1di 42

Introduction to Red Hat

Enterprise Linux
Deepesh Sinnya
M.E Computer NCIT
RHCE,RHCSA
Cypher Technology P. Ltd.
dsinnya@gmail.com, deepesh@cyphertechnepal.com
So what is Linux?
 It’s an operating system or OS.

 It comes in many distributions.

 For this training course we will be using CentOS 7.


Time for a quick history lesson.
 Linux is an offshoot of Unix OS developed by Bell Labs in 1969.
 Aim of allowing multiple users to work simultaneously.
 Early 90’s Unix had become so important Linux was developed.
 In 1991 Linux Torvalds released source code for freeware kernel called Linux.
 Most of Linux distribution are open-source and have community support.
 Red-Hat Linux Distribution-> Red HatEnterprise Linux (RHEL)
 RHEL is paid and supported version.
Some Linux /Unix Flavour
 Sun Solaris –> Sun Microsystem (Now Oracle)
 AIX -> IBM
 XGUIX -> Microsoft
 Linux -> Linux Torvalds.
Linux /Unix Principle
 Everything is a file including Hardware.
 Configuration files are in text form.
 Avoid using GUI.
 Small single purpose Programmed.
 Small programs can be combined to perform complex task.
Accessing RHEL
 We can access Red Hat Enterprise Linux via GUI, In many ways this is very similar
to the Windows or Mac OSX OS ‘s.
 To access the terminal you will need to look for the below icon on the launch bar
on the left.
Accessing Terminal
 Clicking on terminal icon results in following window.

 Terminal can be remotely accessed via ssh with suitable tool. (putty, other bash
shell)
The Basics

Basic commands, flags and getting around.


The Basics
 So now we are in the Terminal how do we get the computer to do something?

 You give the computer a command.

 Start with some of the informative commands then move onto navigational
commands.
The Basics
Command Details
who This will display information about who is logged on, both
yourself and others.
whoami This will display information about the current user i.e. You!
ls ls is short hand for LiSt. It will display all the visible files
within the directory that you are currently in. The files will
be listed alphabetically by default but this can be altered with
flags.
pwd This will Print the Working Directory. A fancy way of asking
the computer to display information about where you are and
what directory you are currently working in.
apropos Keyword This command followed by a keyword will provide you with
information on commands that are related to that keyword.
man Command This will provide you with the manual for the given command.
The Basics
 Using these commands you can gather information about the digital world around
you, using flags will give you even more control.

 We will place the flags behind the ls command for demonstrative purposes
The Basics
Flag Details
ls -a LiSt All – This will list all of the files in the directory including the
hidden dot files.
ls -l LiSt Long – This will list all the files and/or subdirectories with
detailed information such as file size, date modified etc.
ls -t LiSt Time – This will sort the list into a chronological order based on
modification time.
ls -tu This list will list them chronologically based on the last access date.
ls -R This list will include the content of subdirectories.
ls –S LiSt Size – This list will be based on the size order.
ls –h LiSt Human – this will make the list human readable format for
example the size would be 1.0MB instead of 1004638
ls -r LiSt Reversed – This will list the files in a reverse alphabetical order.
The Basics
 The commands for getting around the directories and file structures are really
simple.
 Inverted tree like design with the root directory at the top, the user home
directory and other essential folders below that, and the general
directories/subdirectories below this.
The Basics
The Basics
Command Details
cd .. Change Directory - to one level up the tree.
cd ~ Change Directory - to the home directory
mkdir Make DIRectory – this creates a new directory within the
current working directory
rmdir Directory ReMove DIRectory – This will remove the named directory,
It must be within the current working directory
rm –r Directory ReMove – the r flag on this command will along with its
contents
rm –i Directory ReMove – the i flag on this command will make it so there
is user interaction, i.e. the computer will ask for
confirmation
rm –ir Directory ReMove – the combination ir will remove all files within
the directory and ask for confirmation for each file within
it.
mv filename new_filename MoVe – This will move the file to a new location
cp filename new_filename CoPy – This will make a copy of the file under the
specified name.
SSH (Secure Shell):
 SSH provides a secure channel for data transmission
 Provides a secure pipe to open up a command interpreter
 Latest version of SSH –SSH3
Accessing Linux terminal via SSH
 SSH Supports secure remote logins, secure remote command execution, secure
file transfers
 Default SSH port ????
 Has a client server architecture – SSH server program and client program.
 Make sure the SSH service is up and running on the server we are trying to access.
Accessing Linux terminal via SSH
 Then access the remote server terminal using SSH via (bash shell or terminal
emulator like putty.)
Accessing Linux terminal via SSH
 Following example shows us how to access remote terminal via bash shell.
Using Grep Utility:
 The ‘grep’ command searches for a pattern in a file (or standard input). It
supports regular expressions. It returns a line if it matches the pattern in
that line. So, if we wish to find the lines containing the word ‘nologin’, we
use ‘grep’ as follows

 More examples:
 $grep bash /etc/passwd -> greps out user with bash shell
 $grep ^# /etc/profile -> shows comment line only in the file profile
Using find Utility:
 The find command in UNIX/LINUX is a command line utility for walking a file
hierarchy. It can be used to find files and directories and perform subsequent
operations on them.
 It supports searching by file and directories that matches given criteria like
name,size,modification date, owner and permissions. By using the ‘-exec’ other
UNIX commands can be executed on files or folders found.

Syntax
find <path> [option] <Argument>
Examples:
1. Find all the files inside /etc directories that have been modified with in last
7 days:
# find /etc –mtime -7 -> -mtime option is from modification time search
2. Find all the files inside the whole system that have .conf extension.
# find / -name *.conf
Using find Utility:
3. Find all the files inside /var/log directory that are larger than 10 KB
# find /var/log –size +10KB

4. Find files in /home under student ownership


# find /home –user student –and –perm 664 –exec cp -r {} /root/stdbackup1
\;
Compression Utility:
 We can compress folders in Linux using compression utilities.
 gzip is a standard compression utility in RHEL/CENTOS.
 Bzip2 is newer compression utility used in RHEL/CENTOS.

Example:
Create a compressed archive of /etc/ as /root/etc.tar.gz
# tar -zcvf /root/etc.tar.gz /etc ->using gzip
gzip compress verbose file

# tar -jcvf /root/etc.tar.bz2 /etc ->using bzip


bzip compress verbose file
Compression Utility:
 Extraction:
 Change directory to extraction point:
 #cd /extractionpoint -> here we take directory extraction point just under /

# tar -zxvf /root/etc.tar.gz -> to extract gzip


extraction

# tar –jxvf /root/etc/tar.bz2 -> extract bzip2

extraction
Managing Services:
 To view status of a service in RHEL 7/ CENTOS 7:
# systemctl status <service name>
 To start a service in RHEL 7/ CENTOS 7:
# systemctl start <service name>
 To stop a service in RHEL 7/ CENTOS 7:
# systemctl stop <service name>
 To restart a service in RHEL 7/ CENTOS 7:
# systemctl restart <service name>
 To enable start a service after system restart in RHEL 7/ CENTOS 7:
# systemctl enable <service name>
 To disable start a service after system restart in RHEL 7/ CENTOS 7:
# systemctl disable <service name>
Managing Services:
 In CENTOS 6 and older version
#service <service name> start /restart / stop

 To enable or disable service on system restart

# chkconfig <service name> on/off


Firewall in CENTOS7:
 In CENTOS 7 firewalld is the default system firewall.
 To list the firewall zones in
# firewall-cmd –list-all-zones | less
 Public is the default zone.
 To allow service through a firewall permanently.
#firewall-cmd --permanent --add-service= smtp
#firewall-cmd --permanent –add-service= ssh
 To refresh newly added service
#firewall-cmd --reload
#firewall-cmd –-list-all -> to verify if the services have been added.
 To add port in a firewall zone permanently.
#firewall-cmd --permanent --add-port= 8080/tcp
#firewall-cmd --permanent –add-service= 22/tcp
# firewall-cmd –-reload
# firewall-cmd –list-all -> to verify
Firewall in CENTOS7:
 To remove ports and services:
#firewall-cmd –-permanent --remove-service = http
#firewall-cmd –-permanent –remove-port = 8080/tcp
#firewall-cmd –-reload
# firewall-cmd -–list-all
User, Group and Permission:
 Types of User in terms of ownership:
1. Owner -> u
2. Group Member -> g
3. Others -> o
All -> a
 Types of permission:
1. Read -> symbol (r) -> numeric value of read permission (4)
2. write -> symbol (w) -> numeric value of write permission (2)
3. Execute -> symbol (x) -> numeric value of Execute permission (1)
4. no permission -> symbol (-) –> numeric value (0)
5. Full permission -> symbol (rwx) -> numeric value (7)
User, Group and Permission:
-r-xr-xr-x 1 root root 68524 2011-12-19 07:18 /usr/bin/top

---------- --- ------- ------- -------- ------------ -------------


| | | | | | |
| | | | | | File Name
| | | | | |
| | | | | +--- Modification
Time/Date
| | | | |
| | | | +------------- Size (in bytes
| | | |
| | | +----------------------- Group
| | |
| | +-------------------------------- Owner
| |
| +-------------------------------------- “link count”
|
+---------------------------------------------- File Permissions
User, Group and Permission:

Group
The name of the group that has permissions in addition to the file's owner.
Owner
The name of the user who owns the file.
File Permissions
The first character is the type of file. A "-" indicates a regular
(ordinary) file. A "d” indicate a directory. Second set of 3 characters
represent the read, write, and execution rights of the file's owner. Next 3
represent the rights of the file's group, and the final 3 represent the rights
granted to everybody else.
User, Group and Permission:
 Example for assigning permission to file/directory:
# chmod u=rwx, g=rx, o=r file1
same thing can be done using following command:
#chmod 754 file1
Why is value 754?
7=r+w+x=4+2+1
5=r+x=4+1
4=r=4
 Changing ownership:
#chown dsinnya:root file1 ->changes owner of file to dsinnya and assings it to
group root.
file owner group
User, Group and Permission:
 Cat /etc/passed ->user’s database file
Format:
username : x : UID :GID:<comment>:<Home Directory>:<shell>

represents encrypted password


 Adding group:
#groupadd friends
#groupadd staff
 Adding users:
#useradd –g friends –s /sbin/nologin –u 3000 anand
#useradd –G staff ram
#passwd anand -> to add password for user anand
#passwd ram -> to add password for user ram
# useradd –help -> for information on adding user. (please self explore).
User, Group and Permission:
More examples:
#mkdir /var/developers
# ls –ld /var/developers

Lets set owner as root and group as staff for /var/developers


# chown root:staff /var/developers

Setting sticky bit


# chown g+s /var/developer -> this will allow files in directory to inherit group permission
Working with network in centos7:
For our ease we have text user interface in centos 7 to set our IP address of the
either via DHCP our statically. Hit nmtui on terminal and press enter to get
following:
#nmtui
Working with network in centos7:
We can configure the IP address either statically or to allow system to get it from a
dhcp server.
Working with network in centos7:
In centos 7 we can use configuration file to set IP address:
Path to configuration file is:
#vi /etc/sysconfig/network-script/ifcfg-ens33 (depends on interface used)

This configuration is to get ip


address dynamically.

Here BOOTPROTO=dhcp thus IP


address is acquired from dhcp
server.
Working with network in centos7:
Let us configure static IP address:
Path to configuration file is:
#vi /etc/sysconfig/network-script/ifcfg-ens33 (depends on interface used)

Here BOOTPROTO=static to
configure static IP
Also following are our added
static parameter
ADDR0=192.168.174.132
NETMASK0=255.255.255.0
GATEWAY0=192.168.174.2
DNS1=8.8.8.8
Package management:
Yellow Dog Updater, Modified (YUM):
The YUM tool was developed for the Yellow Dog Linux system as a replacement for
the Yellow Dog Updater (YUP). RedHat found the YUM tool to be a valuable addition
to their systems. Today, YUM is the default package and repository management
tool for a number of operating systems.
You can use the following commands to interact with YUM:
#yum install package-name(s) - Installs the specified package(s) along with any
required dependencies.
# yum remove package-name(s) - Removes the specified package(s) from your
system.
# yum search search-pattern - Searches the list of package names and descriptions
for packages that match the search pattern and provides a list of package names,
with architectures and a brief description of the package contents. Note that
regular expression searches are not permitted.
#yum deplist package-name(s) - Lists all of the libraries and modules that the named
package depends on, along with the names of the packages (including versions) that
provide those dependencies.
Package management:
#yum check-update - Refreshes the local cache of the yum database so that
dependency information and the latest packages are always up to date.
#yum info package-name(s) - The results of the info command provides the name,
description of the package, as well as a link to the upstream home page for the
software, release versions and the installed size of the software.
#yum reinstall package-name(s) - Erases and then downloads a new copy of the
package file and re-installs the software on your system.
#yum update optional-package-name(s) - Downloads and installs all updates
including bug fixes, security releases, and upgrades, as provided by the distributors
of your operating system. Note that you can specify package names with the
update command.
#yum upgrade - Upgrades all packages installed in your system to the latest
release.
Package management:
Installing Web server:
#yum –y install httpd
#systemctl start httpd
#systemctl enable httpd
#firewall-cmd –-permanent –-add-service=http
#firewall-cmd –-permanent –-add-service=https
#firewall-cmd –-reload
#firewall-cmd –-list-all

This should install our web server.


Package management:
RPM Package Manager (RPM)

YUM is simply front-ends to a lower-level tool called RPM, similar to apt-get’s relationship
with dpkg in case of Ubuntu. You will likely not need to interact with RPM very often, but
there are a few commands that you may find useful.
The following commands should be run as root. The flags are expanded here, but the
abbreviated syntax is also included:
# rpm -ivh filename.rpm - Installs an rpm from the file. rpm is also capable of installing RPM
files from http and ftp sources as well as local files.
# rpm --erase package-name(s) or # rpm -e - Removes the given package. Usually will not
complete if package-name matches more than one package, but will remove more than one
match if used with the --allmatches flag.
# rpm --query --all or # rpm -qa - lists the name of all packages currently installed.

Potrebbero piacerti anche