Introduction to Linux Fundamentals
Introduction to Linux Fundamentals
INTRODUCTION TO LINUX
What is Operating System?
As per Wikipedia
An operating system is systemsoftware that manages computer hardware and software
resources, and provides common services for computer programs
In simple words
An operating system(OS) is software that acts as a middleman or a bridge between
computer hardware and the computer user. It provides a user interface and controls the
computer hardware so that software can function
.iso
What is Linux?
Why Learn Linux or its importance?
Linux Flavors
"Linux flavors" = "Linux distributions" = or "distros" for short
• Ubuntu • openSUSE
• Fedora
• Linux Mint
• Debian • Gentoo
• Developers
• Educational institutions
• Government agencies
• Enterprise and businesses
• Tech companies
• Cloud and web servers
• Supercomputers and research facilities
• Telecommunications and networking
• Media and entertainment
L INUX VS. W INDOWS
MODULE 2
DOWNLOAD,
INSTALL AND
CONFIGURE
LINUX
Lab Design
Option 1 Option 2
2004
Community Enterprise Operating System
Greg Kurtzer
Red Hat OS
2014
CentOS vs. CentOS Stream
Question???
Virtual Machine
Virtualization software
Download and Install Linux (CentOS 7)
Skip… 8
Virtual Machine
Go back
• Create a VM VMWare player Oracle VirtualBox
• Download CentOS 8 Stream ISO Virtualization software
• Install CentOS 8 Stream
Download and Install Linux (CentOS 9 Stream)
Go back… 9
Virtual Machine
• Create a VM
• Download CentOS 9 Stream ISO
• Install CentOS 9 Stream
VMWare player Oracle VirtualBox
Virtualization software
Install Linux on Cloud
Option 2
Skip…
Virtual Machine
Cloud Services
D I FFERENT W AYS TO I NSTALL OS
MODULE 3
LINUX
FUNDAMENTALS
Important Things to Remember in Linux
• Linux has super-user account called root
• root is the most powerful account that can create, modify, delete
accounts and make changes to system configuration files
• Linux is case-sensitive system
• ABC is NOT same as abc
• Avoid using spaces when creating files and directories
• Linux kernel is not an operating system. It is a small software within Linux
operating system that takes commands from users and pass them to system
hardware or peripherals
• Linux is mostly CLI not GUI
• Linux is very flexible as compared to other operating systems.
Access to Linux System
There are 2 types of access
1. Console
2. Remote
Putty
Client
RDP Sharing
Linux to Linux
SSH [Link]
Access to Linux System
Important:
Windows 10 or newer version
SSH built-in client
ssh [Link]
Download and Install Putty
If you are using Windows 10 or newer version
then you do NOT have to download or install Putty
Download and Install Putty
Putty is a software which allows you to connect from a Windows system to
Linux system remotely
[Link]
Access to Linux fromMAC
[Link]
Linux
Linux
ssh [Link]
• The newer version of CentOS might not have the ifconfig command, therefore, use
“ip addr” command instead
• To use ifconfig in 7.5 or later version then run = “yum install net-tools”
Access to Linux via SSH
Linux
Command Prompts and Getting Prompts Back
Closet
Shirts Jackets
Accessories Shoes
Pants
Skirts
Introduction to Filesystem
• What is a Filesystem?
• It is a system used by an operating system to manage files. The system
controls how data is saved or retrieved
Closet
Shirts Jackets
Accessories Shoes
Pants
Skirts
Introduction to Filesystem
• Operating system stores files and directories in an organized and
structured way
• System configuration file = Folder A
• User files = Folder B
• Log files = Folder C
• Commands or scripts = Folder D and so on
• "cd" stands for change directory. It is the primary command for moving you around the filesystem.
• “pwd” stands for print working directory. It tells you where you current location is.
• “ls” stands for list. It lists all the directories/files within a current working directory
• Using of TAB key to auto-complete
Linux File orDirectory Properties
Each file or directory in Linux has detail information or properties
The second column is the number of hard links to the file. For a
directory, the number of hard links is the number of immediate
subdirectories it has plus its parent directory and itself
Linux File Types
What is Root?
• There are 3 types of root on Linux system
1. Root account:root is an account or a username on Linux machine and it is the
most powerful account which has access to all commands and files
2. Root as /: the very first directory in Linux is also referred as root directory
3. Root home directory:the root user account also has a directory located in
/root which is called root home directory
Changing Password
Command = passwduserid
Old password: - enter your current password
New password:- enter your new password
Retype new password:- re-enter your new password
File System Paths
• There are two paths to navigate to a filesystem
Absolute Path
Relative Path
• An absolute path always begins with a "/". This indicates that the path starts at the root directory. An
example of an absolute path is
cd /var/log/httpd
• A relative path does not begin with a "/". It identifies a location relative to your current position. An
example of a relative path is:
cd /var
cd log
cd httpd
Creating Files and Directories
• Creating Files
touch
cp
vi
• Creating Directories
mkdir
Copying Directories
• Command to copy a directory
• cp
• To copy a directory on Linux, you have to execute the “cp” command with the “-R”
option for recursive and specify the source and destination directories to be copied
• cp -R <source_folder> <destination_folder>
Find Files and Directories
• find
• locate
Difference Between find and locate
• ln
• ln -s
C O M M A N D S S YNTAX
• Command options and arguments
Options:
Modify the way that a command works
Usually consist of a hyphen or dash followed by a single letter
Some commands accept multiple options which can usually be grouped together after a single hyphen
Arguments:
Most commands are used together with one or more arguments
Some commands assume a default argument if none is supplied
Arguments are optional for some commands and required by others
F ILE P ER MIS S ION S
• UNIX is a multi-user system. Every file and directory in your account can be protected
from or made accessible to other users by changing its access permissions. Every user has
responsibility for controlling access to their files.
-r--r--r--
Permission Using Numeric Mode
• The table below assigns numbers to permissions types
• whatis command
• command –-help
• man command
TAB Completion and Up A r r o w
• Hitting TAB key completes the available commands, files
or directories
• chm TAB
• ls j<TAB>
• cd Des<TAB>
• Output (stdout)- 1
• By default when running a command its output goes to the terminal
• The output of a command can be routed to a file using > symbol
• E.g. ls -l > listings
pwd > findpath
• If using the same file for additional output or to append to the same file then use >>
• E.g. ls –la >> listings
echo “Hello World” >> findpath.
I NPUT A N D O UTPUT R EDIRECTS
• Input (stdin) - 0
• Input is used when feeding file contents to a file
• E.g. cat < listings
mail –s “Office memo” allusers@[Link] < memoletter
• Error (stderr) - 2
• When a command is executed we use a keyboard and that is also considered (stdin -0)
• That command output goes on the monitor and that output is (stdout – 1)
• If the command produced any error on the screen then it is considered (stderr – 2)
• We can use redirects to route errors from the screen
• E.g ls –l /root 2> errorfile
telnet localhost 2> errorfile.
Standard Output to a File (tee)
• “tee” command is used to store and view (both at the same
time) the output of any command
• The command is named after the T-splitter used in plumbing. It
basically breaks the output of a program so that it can be both
displayed and saved in a file. It does both the tasks
simultaneously, copies the result into the specified files or
variables and also display the result.
P IP ES
• A pipe is used by the shell to connect the output of one command directly to
the input of another command.
The symbol for a pipe is the vertical bar ( | ). The command syntax is:
ls -l | more
F ILE M A IN TEN A N C E C O M M A N D S
• cp
• rm
• mv
• mkdir
• rmdir or rm -r
• chgrp
• chown
F ILE D ISPLAY C O M M A N D S
• cat
• more
• less
• head
• tail
Filters / Text Processors Commands
• cut
• awk
• grep and egrep
• sort
• uniq
• wc
cut - Text Processors Commands
cut
• cut is a command line utility that allows you to cut parts of lines from specified files or piped data and
print the result to standard output. It can be used to cut parts of a line by delimiter, byte position, and
character
• What is grep?
• The grep command which stands for “global regular expression print,” processes text line by line
and prints any lines which match a specified pattern
• What is wc command?
• The command reads either standard input or a list of files and generates: newline count, word
count, and byte count
• tar
• gzip
• gzip –d OR gunzip
Truncate File Size (truncate)
• The Linux truncate command is often
used to shrink or extend the size of a file to
the specified size
• Command
• truncate –s 10 filename
C OMBINING A N D S PLITTING F ILES
Split [Link] into 300 lines per file and output to childfileaa,
childfileab and childfileac
Linux vs. W i n d o w s Commands
Command Description Windows Linux
Listing of a directory dir ls -l
Rename a file ren mv
Copy a file copy cp
Move file move mv
Clear screen cls clear
Delete file del rm
Compare contents of files fc diff
Search for a word/string in a file find grep
Display command help command /? man command
Displays your location in the file system chdir pwd
Displays the time time date
MODULE 4
LINUX SYSTEM
ADMINISTRATION
Linux File Editor
• A text editor is a program which enables you to create and manipulate data
(text) in a Linux file
• There are several standard text editors available on most Linux systems
• vi - Visual editor
• ed - Standard line editor
• ex - Extended line editor
• emacs - A full screen editor
• pico - Beginner’s editor
• vim - Advance version of vi
• Since vim is based on the vi, when you will learn how to use the vim editor, you will
automatically learn how to use the vi editor.
• There's also a comprehensive help system and lots of customization options available.
Difference Between vi and vim Editor
“vim” Interactive Learning Tools
• There are many websites that offer free vim interactive training:
• [Link]
• [Link]
• [Link] (Games)
“sed” Command
Files
• /etc/passwd
• /etc/group
• /etc/shadow
Example:
useradd –g superheros –s /bin/bash –c “user description” –m –d
/home/spiderman spiderman
The /etc/[Link] File
• The chage command – per user
• Example
chage [-m mindays] [-M maxdays] [-d lastday] [-I inactive] [-E
expiredate] [-W warndays] user
• File = /etc/[Link]
• PASS_MAX_DAYS 99999
• PASS_MIN_DAYS 0
• PASS_MIN_LEN 5
• PASS_WARN_AGE 7
The chage Command
• Example
chage [-d lastday] [-m mindays] [-M maxdays] [-W warndays] [-I
inactive] [-E expiredate] user
-d = 3. Last password change (lastchanged) : Days since Jan 1, 1970 that password was last changed
-m = 4. Minimum : The minimum number of days required between password changes i.e. the number of days left
before the user is allowed to change his/her password
-M = 5. Maximum : The maximum number of days the password is valid (after that user is forced to change his/her
password)
-W = 6. Warn : The number of days before password is to expire that user is warned that his/her password must be
changed
-I = 7. Inactive : The number of days after password expires that account is disabled
-E = 8. Expire : days since Jan 1, 1970 that account is disabled i.e. an absolute date specifying when the login may no
longer be used.
S w i t c h Users and sudo Access
Commands
• su – username
• sudo command
• visudo
File
• /etc/sudoers
Monitor Users
• who
• last
•w
• finger
• id
Talking t o Users
• users
• wall
• write
Linux Account Authentication
• Types of Accounts
• Local accounts
• Domain/Directory accounts
Account authentication
User authenticated
Client Server
• Application = Service
• Script
• Process
• Daemon
• Threads
• Job
Process / Services Commands
• systemctl or service
• ps
• top
• kill
• crontab
• at.
systemctl command
• systemctl command is a new tool to control system services
• It is available in version 7 and later and it replaces the service command
• Usage example:
systemctl start|stop|status [Link] (firewalld)
systemctl enable [Link]
systemctl restart|reload [Link]
systemctl list-units --all
systemctl command
• To add a service under systemctl management:
Create a unit file in /etc/systemd/system/[Link]
Usage examples:
• ps = Shows the processes of the current shell
• Usage: top
Please note:
Top command refreshes the information every 3 seconds
“kill” command
• kill command is used to terminate processes manually
• It sends a signal which ultimately terminates or kills a particular process or
group of processes
Usage:
kill [OPTION] [PID]
OPTION = Signal name or signal number/ID
PID = Process ID
kill –l = to get a list of all signal names or signal number
Usage:
o crontab –e = Edit the crontab
o crontab –l = List the crontab entries
o crontab –r = Remove the crontab
o crond = crontab daemon/service that manages scheduling
o systemctl status crond = To manage the crond service
Usage:
o at HH:MM PM = Schedule a job
o atq = List the at entries
o atrm # = Remove at entry
o atd = at daemon/service that manages scheduling
o systemctl status atd = To manage the atd service
• top
• df
• dmesg
• iostat 1
• netstat
• free
• cat /proc/cpuinfo
• cat /proc/meminfo
Log Monitoring
Another and most important way of system administration is log monitor
• shutdown
• init 0-7
• reboot
• halt
Changing Sy st em Hostname
• cat /etc/redhat-release
• uname –a
• dmidecode
System Architecture
• Differences between a 32-bit and 64-bit CPU
A big difference between 32-bit processors and 64-bit processors is the number of
calculations per second they can perform, which affects the speed at which they can
complete tasks. 64-bit processors can come in dual core, quad core, six core, and eight core
versions for home computing. Multiple cores allow for an increased number of calculations per
second that can be performed, which can increase the processing power and help make a
computer run faster. Software programs that require many calculations to function smoothly
can operate faster and more efficiently on the multi-core 64-bit processors
• Linux = arch
• Windows = My computer Properties
Terminal Control Keys
Several key combinations on your keyboard usually have a special effect on the terminal.
These "control" (CTRL) keys are accomplished by holding the CTRL key while typing the second key.
For example, CTRL-c means to hold the CTRL key while you type the letter "c".
• exit
Exit out of the shell, terminal or a user session
• script
The script command stores terminal activities in a log file that can be
named by a user, when a name is not provided by a user, the default
file name, typescript is used
Recover Root P assw ord
[Link]
SOS Report
• Package name
• sos-version
• Command
• sosreport
Environment Variables
• What are environment variables?
• An environment variable is a dynamic-named value that can affect the way
running processes will behave on a computer. They are part of the environment
in which a process runs.
• In simple words: set of defined rules and values to build an environment
• E.g.
Playroom
Bedroom
Kitchen
Dining Room
Environment Variables
• To view all environment variables
• printevn OR env
• To view ONE environment variable
• echo $SHELL
• To set the environment variables
• export TEST=1
• echo $TEST
• To set environment variable permanently
• vi .bashrc
• TEST=‘123’
• export TEST
• To set global environment variable permanently
• vi /etc/profile or /etc/bashrc
• Test=‘123’
• export TEST
Special Permissions with setuid, setgid and sticky bit
• All permissions on a file or directory are referred as bits
-r w x r w x r w x
bits chmod
• sticky bit: a bit set on files/directories that allows only the owner or root to delete those files
Special Permissions with setuid, setgid and sticky bit
Sticky bit
• It is assigned to the last bit of permissions
-r w x r w x r w t
• IP
• Subnet mask
• Gateway
• Static vs. DHCP
• Interface
• Interface MAC.
Network Files and Commands
• Interface Detection
• Assigning an IP address
• Interface configuration files
• /etc/[Link]
• /etc/hostname
• /etc/sysconfig/network
• /etc/sysconfig/network-scripts/ifcfg-nic
• /etc/[Link]
• Network Commands
• ping
• ifconfig
• ifup or ifdown
• netstat
• tcpdump
NIC Information
Example:
ethtool enp0s3
Other NICs
lo = The loopback device is a special interface that your computer uses to communicate
with itself. It is used mainly for diagnostics and troubleshooting, and to connect to servers
running on the local machine
virb0 = The virbr0, or "Virtual Bridge 0" interface is used for NAT (Network Address
Translation). Virtual environments sometimes use it to connect to the outside network
NIC Bonding
nic1
nic2
bond0
• # ifconfig
• # systemctl reboot
• # ip address show
System Updates and Repos
• Linux = wget
• Example in Linux:
wget [Link]
• Why???
Most of the servers in corporate
environment do NOT have internet access
curl and ping Commands
• Example of Windows browser
• Linux = curl
• Linux = ping
• Example in Linux:
curl [Link]
curl –O [Link]
ping [Link]
FTP – File Transfer Protocol
• The File Transfer Protocol is a standard network protocol used for the transfer of
computer files between a client and server on a computer network. FTP is built
on a client-server model architecture using separate control and data
connections between the client and the server. (Wikipedia)
Client = A Server = B
FTP
ftpd = 21
FTP – File Transfer Protocol
• Install and Configure FTP on the remote server
• # Become root
• # rpm –qa | grep ftp
• # ping [Link]
• # yum install vsftpd
• # vi /etc/vsftpd/[Link] (make a copy first)
• Find the following lines and make the changes as shown below:
• ## Disable anonymous login ##
• anonymous_enable=NO
• ## Uncomment ##
• ascii_upload_enable=YES
• ascii_download_enable=YES
Client = A Server = B
ssh
scp
sshd = 22
SCP – Secure Copy
• SCP commands to transfer file to the remote server:
• This utility is mostly used to backup the files and directories from one server to
another
Client = A Server = B
ssh
rsync
2M 2M 2M sshd = 22
8M 8-2 = 6 8M
20M 20-8 = 12 20M
rsync – Remote Synchronization
• Basic syntax of rsync command
• # rsync options source destination
Example:
yum update –y
C R EA TE L OCAL R EPOSITORY FROM D V D
Repos
Repos
Redhat or CentOS
Linux repository
Server
• Command
createrepo
Advance Package Management
• Installing packages
• Upgrading
• Deleting
• View package details information
• Identify source or location
information
• Packages configuration files
Rollback Updates and Patches
• Virtual machine
• Physical machine
• Rollback an update
• Downgrading a system to minor version (ex: RHEL7.1 to RHEL7.0) is not
recommended as this might leave the system in undesired or unstable state
ntp
Client Server
DNS = Domain Name System
• Purpose?
Hostname to IP (A Record)
IP to Hostname (PTR Record)
Hostname to Hostname (CNAME Record)
• Files
/etc/[Link]
/var/named
• Service
systemctl restart named
Download, Install and Configure DNS
• Create a snapshot of your virtual machine
• Setup:
• Master DNS
• Secondary or Slave DNS
• Client
• File
/etc/[Link]
• Service
systemctl restart ntpd
• Command
ntpq
chronyd
• Purpose? = Time synchronization
• Package name = chronyd
• Configuration file = /etc/[Link]
• Log file = /var/log/chrony
• Service = systemctl start/restart chronyd
• Program command = chronyd.
New System Utility Command (timedatectl)
• The timedatectl command is a new utility for RHEL/CentOS 7/8 based distributions, which comes as a
part of the systemd system and service manager
• It is a replacement for old traditional date command
Please note:
Redhat/CentOS doesnot provide this daemon in its standard repo. You will have to download it separately.
New System Utility Command (timedatectl)
Lab exercise:
• To check time status
• timedatectl
• To set date
• timedatectl set-time YYYY-MM-DD
• Purpose?
Send and receive emails
• Files
/etc/mail/[Link]
/etc/mail/[Link]
/etc/mail
• Service
systemctl restart sendmail
• Command
mail –s “subject line” email@[Link]
Sendmail
• Sendmail is a program in Linux operating systems that allows
systems administrator to send email from the Linux system
• Service
systemctl restart httpd
systemctl enable httpd
C EN TR A L L OGGER ( RSYSLOG )
Client
• Service or package name = rsyslog
Client
Linux OS Hardening
• User Account
• Remove un-wanted packages
• Stop un-used Services
• Check on Listening Ports
• Secure SSH Configuration
• Enable Firewall (iptables/firewalld)
• Enable SELinux
• Change Listening Services Port Numbers
• Keep your OS up to date (security patching)
OpenLDAP Installation
• What is OpenLDAP?
• OpenLDAP Service
• slapd
• Configuration Files
• /etc/openldap/slapd.d
Trace Network Traffic (traceroute)
• The traceroute command is used in Linux to map the journey that a packet
of information undertakes from its source to its destination. One use for
traceroute is to locate when data loss occurs throughout a network, which
could signify a node that's down.
• Because each hop in the record reflects a new server or router between
the originating PC and the intended target, reviewing the results of a
traceroute scan also lets you identify slow points that may adversely affect
your network traffic.
• Example
# traceroute [Link]
Configure and Secure SSH
• SSH
• SSH stands for secure shell
provides you with an interface to the Linux system. It takes in
your commands and translate them to kernel to manage hardware
pwd
$ bash
csh ksh
# ls
Hardware
cp
• SSH itself is secure, meaning communication through SSH is always encrypted, but there
should be some additional configuration can be done to make it more secure
• Following are the most common configuration an administrator should take to secure SSH
Become root
Edit your /etc/ssh/sshd_config file and add the following line:
ClientAliveInterval 600
ClientAliveCountMax 0
# systemctl restart sshd
The idle timeout interval you are setting is in seconds (600 secs = 10 minutes). Once the interval
has passed, the idle user will be automatically logged out
Configure and Secure SSH
Disabling root login should be one of the measures you should take when setting up
the system for the first time. It disable any user to login to the system with root
account
Become root
Edit your /etc/ssh/sshd_config file and replace PermitRootLogin yes to no
PermitRootLogin no
# systemctl restart sshd
Configure and Secure SSH
You need to prevent remote logins from accounts with empty passwords for
added security.
Become root
Edit your /etc/ssh/sshd_config file and remove # from the following line
PermitEmptyPasswords no
# systemctl restart sshd
Configure and Secure SSH
To provide another layer of security, you should limit your SSH logins to only certain
users who need remote access
Become root
Edit your /etc/ssh/sshd_config file and add
AllowUsers user1 user2
# systemctl restart sshd
Configure and Secure SSH
By default SSH port runs on 22. Most hackers looking for any open SSH servers will
look for port 22 and changing can make the system much more secure
Become root
Edit your /etc/ssh/sshd_config file and remove # from the following line and
change the port number
Port 22
# systemctl restart sshd
Configure and Secure SSH
Access Remote Server without Password (SSH-Keys)
Username?
Password?
Username?
Password?
SSH
Client = MyFirstLinuxVM
Step 1 — Generate the Key
# ssh-keygen
• Cockpit is the easy-to-use, integrated, glanceable, and open web-based interface for your
servers
• The application is available in most of the Linux distributions such as, CentOS, Redhat,
Ubuntu and Fedora
• It can monitor system resources, add or remove accounts, monitor system usage, shut
down the system and perform quite a few other tasks all through a very accessible web
connection
Install, Configure and Manage Cockpit
• Check for network connectivity
• ping [Link]
• What is Firewall
• A wall that prevents the spread of fire
• When data moves in and out of a server its packet information is tested against the
firewall rules to see if it should be allowed or not
• In simple words, a firewall is like a watchman, a bouncer, or a shield that has a set
of rules given and based on that rule they decide who can enter and leave
Connection established
B
A
ftp = 21
Connection refused
B
A
Firewall (iptables – tables, chains and targets) 1/4
• Before working with iptables make sure firewalld is not running and disable it
• service OR systemctl stop firewalld = To stop the service
• systemctl disable firewalld = To prevent from starting at boot time
• systemctl mask firewalld = To prevent it from running by other programs
• To flush iptables.
• iptables -F
Firewall (iptables – tables, chains and targets) 2/4
1. tables = table is something that allows you to process packets in specific ways. There
are 4 different types of tables, filter, mangle, nat and raw
2. chains = The chains are attached to tables, These chains allow you to inspect traffic at
various points. There are 3 main chains used in iptables
INPUT = incoming traffic
FORWARD = going to a router, from one device to another
OUTPUT = outgoing traffic
• chains allow you to filter traffic by adding rules to them
• Rule = if traffic is coming from [Link] then go to defined target
3. targets = target decides the fate of a packet, such as allowing or rejecting it. There are 3
different type of targets
ACCEPT = connection accepted
REJECT = Send reject response
DROP = drop connection without sending any response
Firewall (iptables – tables, chains and targets) 3/4
Table
chains Target
chain
Practical:
• After making all the changes save the iptables. Again make sure firewalld is not running
• iptables-save = The file is save in /etc/sysconfig/iptables
• Firewalld works the same way as iptables but of course it has it own commands
• firewall-cmd
• It has a few pre-defined service rules that are very easy to turn on and off
• Services such as: NFS, NTP, HTTPD etc.
• Start firewalld
• systemctl start/enable firewalld
• All services are pre-defined by firewalld. What if you want to add a 3rd party service
• /usr/lib/firewalld/services/[Link]
• Simply cp any .xml file and change the service and port number
Version of XML
Service
Service
Port
Description
Firewall (firewalld – Practical Examples) 2/3
• To remove a service
• firewall-cmd --remove-service=http
• To add a port
• firewall-cmd --add-port=1110/tcp
• To remove a port
• firewall-cmd --remove-port=1110/tcp
Linux system comes fined tunned by default when you install, however there are a few tweaks
that can be done based on system performance and application requirements
What is tuned?
Nice value is a user-space and priority PR is the process's actual priority that use by Linux kernel. In
Linux system priorities are 0 to 139 in which 0 to 99 for real time and 100 to 139 for users
• Process priority can be viewed through ps command as well with the right options
$ ps axo pid,comm,nice,cls --sort=-nice
Tune System Performance (nice/renince)
8/8
• Wait a second…
• Right now in our home how IPs are assigned to our devices?
• Answer The router or gateway given to you by your ISP provider
• How IPs are assigned in corporate world?
• Answer Dedicated routers run DHCP service to assign IPs on the network
DHCP
Step by steps instructions
• Pick a server to be your DHCP and take a snapshot
• Switch DHCP service from your router/modem to your new DHCP server
• Login to your ISP provided router
• Disable dhcp and enable forwarding to the new dhcp server.
MODULE 6
DISK MANAGEMENT AND RUN LEVELS
S y s t e m Run Level
• System Run Levels
• systemd is the new service manager in CentOS/RHEL 7 that manages the boot
sequence
• Steps:
• Create a new file in /etc/profile.d/[Link]
• Add desired commands in [Link] file
• Modify the /etc/ssh/sshd_config file to edit
#PrintMotd yes to PrintMotd no
• Restart sshd service
• systemctl restart [Link]
D i s k Partition
C:
D:
E:
LVM Configuration During Install
/oracle = 1.0G
/oracle = Full
Few Options:
• Delete older files to free up disk space
• Add new physical disk mount to /oracle2
• Create a new virtual disk and mount to /oracle2
• Or extend /oracle through LVM.
A DD/ E XTEND S WAP S PACE
• What is swap? – [Link]
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs
more memory resources and the RAM is full, inactive pages in memory are moved to the swap
space. While swap space can help machines with a small amount of RAM, it should not be
considered a replacement for more RAM. Swap space is located on hard drives, which have a
slower access time than physical memory
If M < 2
then S = M *2
Else S=M+2
• Commands
• dd
• mkswap
• swapon or swapoff
Implement Advanced Storage Features
• Red Hat 8 introduces the next generation volume management solution called Stratis
• It uses thin provisioning by default
• It combines the process of creating logical volume management (LVM) and creation of
filesystems into one management
• In LVM if a filesystem system gets full you will have to extend it manually whereas stratis
extends the filesystem automatically if it has available space in its pool
• How to manage multiple storage layers using Stratis local storage management
Implement Advanced Storage Features
Physical Disks LVM Logical volumes
Volume Group
Stratis
Filesystem
10G
30G
Pool
Implement Advanced Storage Features
• Install Statris package
yum/dnf install stratis-cli stratisd
• Add 2 x 5G new disks from virtualization software and verify at the OS level
Oracle virtualbox storage setting
lsblk
• Type of RAID
• RAID0
• RAID1
• RAID5
5 5 5 5 5 5 5
+ 5+5=10G = 5,5=5G + + 5+5+5=12G
= =
• dd is a command-line utility for Unix and Unix-like operating systems whose primary
purpose is to convert and copy files
• As a result, dd can be used for tasks such as backing up the boot sector of a hard
drive, and obtaining a fixed amount of random data
• Please note the source and destination disk should be the same size
System Backup (dd Command)…
• To backup or clone an entire hard disk to another hard disk connected to the
same system, execute the dd command as shown
• Restoring this image file to other machine after copying the .img
# dd if=/root/[Link] of=/dev/sdb3
Network File System (NFS)
• NFS stands for Network File System, a file system developed by Sun
Microsystems, Inc.
• It is a client/server system that allows users to access files across a network and
treat them as if they resided in a local file directory
• For example, if you were using a computer linked to a second computer via
NFS, you could access files on the second computer as if they resided in a
directory on the first computer. This is accomplished through the processes of
exporting (the process by which an NFS server provides remote clients with
access to its files) and mounting (the process by which client map NFS shared
filesystem)
Approved
NFS Request
Server Client
Network File System (NFS)…
Steps for NFS Server Configuration
• Once the packages are installed, enable and start NFS services
# systemctl enable rpcbind
# systemctl enable nfs-server
# systemctl start rpcbind, nfs-server, rpc-statd, nfs-idmapd
• Create NFS share directory and assign permissions
# mkdir /mypretzels Read/write all changes to the according filesystem are
immediately flushed to disk; the respective
# chmod a+rwx /mypretzels write operations are being waited for
• Modify /etc/exports file to add new shared filesystem
# /mypretzels [Link](rw,sync,no_root_squash) = for only 1 host
• It works exactly like NFS but the difference is NFS shares within Linux or Unix like system
whereas Samba shares with other OS (e.g. Windows, MAC etc.)
• For example, computer “A” shares its filesystem with computer “B” using Samba then
computer “B” will see that shared filesystem as if it is mounted as the local filesystem
Approved
mount request
Server Client
Samba (smb vs. CIFS)
• Samba shares its filesystem through a protocol called SMB (Server Message Block) which
was invented by IBM
• Another protocol used to share Samba is through CIFS (Common Internet File System)
invented by Microsoft and NMB (NetBios Named Server)
• CIFS became the extension of SMB and now Microsoft has introduced newer version of
SMB v2 and v3 that are mostly used in the industry
• In simple term, most people, when they use either SMB or CIFS, are talking about the same
exact thing
Samba Installation and Configuration
• Take snapshot of your VM
• Install samba packages
• Enable samba to be allowed through firewall (Only if you have firewall running)
• Disable firewall
• Create Samba share directory and assign permissions
• Also change the SELinux security context for the samba shared directory
• Or disable SELinux
• Modify /etc/samba/[Link] file to add new shared filesystem
• Verify the setting
• Once the packages are installed, enable and start Samba services (smb and nmb)
• Mount Samba share on Windows client
• Mount Samba share on Linux client
• Additional instructions on creating secure Samba share.
NAS Device for NFS or Samba
• A storage can be carved on a Linux server, and it can be shared with another
Linux machine through NFS or to a Windows machine through Samba service
Server Client
• NFS/Samba or any NAS service can be setup through a dedicated NAS device
OS
Client
Client
NAS
Client
NAS Device for NFS or Samba
Parallel communication
Serial communication
SATA and SAS
• The main difference between them is that SAS drives are faster and more reliable than SATA drives
• SAS is generally more expensive, and it’s better suited for use in servers or in processing-heavy
computer workstations. SATA is less expensive, and it’s better suited for desktop file storage
• In a SATA cable, all 4 wires are placed within the same cable. In a SAS cable, the 4 wires are
separated into 2 different cables
RHEL 8 RHEL 7
General Availability Date 14-Nov-18 10-Jun-14
Code Name Ootpa Maipo
Kernel Version 4.18 3.10.0-123
End of Support May-2029 30-Jun-2024
Last Minor Release 8.x 7.7
Network Time Synchronization Only Chrony Chrony and ntpd
GUI Interface (Desktop) Gnome 3.28 Gnome 3
MySQL 8.0, MariaDB 10.3,
Default Database PostgreSQL 10 and 9.6, and Redis MariaDB
5.0
Difference Between CentOS/RHEL 7 and 8
RHEL 8 RHEL 7
Firewalld, it uses nftables Firewalld, it uses Iptables
Default Firewall
framework in the backend framework in the backend
Browser, sendmail
Software
GUI, bash, csh
Operating System
Program
CPU, Memory, HD
Intro duction t o Shell
• What is a Shell?
• Its like a container
• Interface between users and Kernel/OS
• CLI is a Shell
S tarti n g a Shell
• Type shell name e.g. csh
• Type exit to exit out of shell
Shell Scripting
• What is a Shell Script?
A shell script is an executable file containing multiple shell commands that are executed
sequentially. The file can contain:
• Shell (#!/bin/bash)
• Comments (# comments)
• Commands (echo, cp, grep etc.)
• Statements (if, while, for etc.)
• Shell script should have executable permissions (e.g. -rwx r-x r-x)
• Shell script has to be called from absolute path (e.g /home/userdir/[Link])
• If called from current location then ./[Link]
Shell S crip t – Basic Scripts
• Creating tasks
• Telling your id, current location, your files/directories, system info
• Creating files or directories
• Output to a file “>”
• Filters/Text processors through scripts (cut, awk, grep, sort, uniq, wc)
Input and Output of Script
• Create script to take input from the user
read
echo
if-t h e n Scripts
• If then statement
• For loops
• do while
while [ condition ]
do
command1
command2
commandN
done
Case S ta temen t Scripts
• Case
• User = /home/user/.bashrc
• Global = /etc/bashrc
alias hh=“hostname”
Shell History
• Command “history”