RH134 Notes
RH134 Notes
RH134 Notes
Commands Description
[root@server ~] # ls Default Kickstart configuration file location
# yum install -y system-config-kickstart Install GUI package of kickstart
# yum install -y vsftpd Install FTP for network access
# systemctl start vsftpd Start FTP services
# systemctl enable vsftpd Start Ftp services on boot
# mount /dev/cdrom /var/ftp/pub/ Mount Centos or RedHat DVD to FTP folder
# setenforce 0 Temporary disable SELinux Security
# systemctl stop firewalld Stop Firewall temporary OR
# firewall-cmd --permanent --add-service=ftp Add the firewall for FTP
# firewall-cmd --reload After add role reload the firewall
# system-config-kickstart Open Kickstart from command line
Applications> System Tools> Kickstart OR Open kickstart from GUI
# cp ks.cfg /var/ftp/ Copy the save kickstart file to FTP path
# chmod 755 /var/ftp/ks.cfg Set permission on kickstart file
# ksvalidator /var/ftp/ks.cfg Check for kickstart file syntax
ks=ftp://192.168.147.151/ks.cfg Press Tab on client and type FTP location
ks=ftp://192.168.147.151/ks.cfg Press tab on client and type FTP location with
ip=192.168.147.3 netmask=255.255.255.0 static IP and gateway configuration
gateway=192.168.147.2
ks=http://server/directory/ks.cfg Kickstart installation using http
ks=ftp://server/directory/ks.cfg Kickstart installation using ftp
ks=nfs: server:/directory/ks.cfg Kickstart installation using nfs
ks=hd: device:/directory/ks.cfg Kickstart installation using hd
ks=cdrom:/directory/ks.cfg Kickstart installation using CDROM
Go to Applications → System Tools → Kickstart for graphical mode or else run # system-config-
kickstart command to open.
1- Choose “Basic Configuration” and choose Default Language, Keyboard layout, Time
Zone, Root Password and Encrypt root password. Select Reboot system after
installation.
2- Select the “Installation Method” Installation Method -Perform new installation.
Installation source FTP, FTP Server: 192.168.147.151, FTP Directory: pub.
3- Select “Boot Loader Options” and choose the required Installation Type: Install new
boot loader, grub password if want set and Install option: Install boot loader on Master
Boot Record (MBR).
4- Choose “Partition Information” and create the partitions details for /boot partitioning.
Now click Add Enter the details for /boot and / partitioning.
5- Select “Network Configuration” and add the Network Device as per requirement.
Choose the DHCP or static IP. Add Network Device: Network Device Name: eth0,
Network Type: DHCP and press OK.
6- Select “Authentication”, Firewall Configuration, Display Configuration, Package
Selection, Pre-Installation Script, Post-Installation Script and finally Save the file.
7- Open the “anaconda-ks.cfg” file and copy the %packages lines to the “ks.cfg” file during
the installation process.
8- Copy or save the ks.cfg file from /root/ks.cfg to the ftp path /var/ftp/.
9- Bootup the client machine with Centos/RHEL 7 installation ISO image.
10- Press the “Tab” button to inject the kickstart configuration file. Type the command
ks=ftp://192.168.147.151/ks.cfg & press “Enter” to continue with the installation.
Regular Expressions:
Regular Expressions are special characters which help search data, matching complex patterns.
A Regular Expression, often shortened to “regex” or “regexp”. Regular Expression enhance the
ability to meaningfully process text content, especially when combined with other commands.
Usually, Regular Expressions are included in the Grep command.
Patterns that exactly specify the characters to be matched are called "literals" because they
match the pattern literally, character-for-character.
The period character and the special meta-character (.) is used in regular expressions to mean
that any single character can exist at the specified location.
Anchors are special characters that specify where in the line a match must occur to be valid.
Use the "^" anchor before the literal string. Similarly, the "$" anchor can be used after a string
to indicate that the match will only be valid if it occurs at the very end of a line.
One of the most commonly used meta-characters is the "*", which means "repeat the previous
character or expression zero or more times".
We can escape characters by using the backslash character (\) before the character that would
normally have a special meaning.
One of the easiest and most useful abilities that extended regular expressions open up is the
ability to group expressions together to manipulate. Group expressions together using
parentheses.
A bracket expression is a list of characters enclosed by [and]. It matches any single character in
that list.
Symbol Descriptions
. Match a single character of any value
^ Anchors symbol to match a starting at the beginning of line
$ Anchors symbol to match end of the line
* Matches up zero or more times the preceding character
\ Represent special characters
() Groups regular expressions
? Matches up exactly one character
[] Range of character
^$ Count of empty lines
Grep Command:
The grep command which stands for “Global Regular Expression Print,” The grep command is
used to search text or searches the given file for lines containing a match to the given strings or
words. Use grep to search for lines of text that match one or many regular expressions, and
outputs only the matching lines. Grep is a powerful file pattern searcher in Linux.
Commands Description
# yum install grep Install grep package
# grep “linux” file Search the given string in specified file
# grep -i "linux" file Case insensitive search
# grep -v linux file Display don't contain a specified string
# grep “fast. *host” file Regular expression anything
# grep -n "word*" file Displaying the line numbers contains matches
# grep -color "linux" file Highlighting matched search
# grep ^root /etc/passwd Display lines starts with root word
# grep bash$ /etc/passwd Display line ends with bash word
# grep -r linux /etc Search pattern recursively
# grep -c 'test' file Counting the lines when word match
# grep c.t /usr/share/dict/words Contains any single character between c and t
# grep c..t /usr/share/dict/words Contains any two characters between c and t
# grep -A 2 'test' file Display 2 lines after the regex match
# grep -B 2 'test' file Display 2 lines before the regex match
# grep -C 2 'test' file Display 2 lines before & after the regex match
# grep c[aou]t /usr/share/dict/words Contains any one character found in bracket
# grep -e cat -e tele /usr/share/dict/words Contains either string in the file
# grep "^[A-Z]" file Find every line that begins with a capital letter
AT Command:
The “at” command schedules a command to be run once at a particular time. It reads
commands from standard input or script or file which can be executed later once. The “at”
command can’t be used for any recurring tasks. For recurring tasks Linux crontab is use. For
normal users, permission to use “at” command is determined by the files /etc/at.allow and
/etc/at.deny. If the file /etc/at.allow exists, only usernames mentioned in it are allowed to use
at. If /etc/at.allow does not exist, /etc/at.deny is checked, every user name not mentioned in it
is then allowed to use at. If neither exists, only the superuser is allowed use of “at”.
Run AT Command:
To start “at” command run “at” the command line, passing it the scheduled time as an option.
It will place you at a special prompt, type the command or series of commands to be run at the
scheduled time. When done, press Control-D on a new line, and the command will be placed in
the queue.
Commands Description
# yum install at Install at package
# systemctl start atd Start at command service
# systemctl enable atd Enable at package service on boot
# systemctl status atd Check at command status
# at 4:30pm November 20 At command passing scheduled time
at> touch output.txt Passing touch command to create file
at> date > output.txt Passing another command to save in file
at> ctrl + D Press Ctrl + D to terminate at command
# at 4:30pm November 20 enter At command passing scheduled time
at> whoami > /name.txt Passing the whoami command to save in file
at> date > /date.txt Passing another date command to save in file
at> ctrl + D Press ctrl + D to get out from at command
# at now + 1 minute at> cal >/cal.txt Just after one minute calendar int file
# at now + 30 minutes Just after 30 minutes
# at now + 1 hour Just after 1 hour
# at now + 1 week Just after 1 week
# at now + 2 week Just after 2 weeks
# atq View currently-queued at jobs
# at -l List each of the scheduled jobs
# at -c JOBID List job contents
# atrm 1 OR # at -r 1 Remove the at job number 1
Crontab Command:
Linux crontab is similar to windows task schedules. Crontab are very useful for routine tasks like
scheduling system scanning, daily backups etc. Crontab executes jobs automatically in backend
on specified time interval. For scheduling one time tasks you can use at command in Linux.
Cron is a scheduler that can run commands at regular intervals. It's often referred to as crontab
which is name of its configuration file and the tool used to edit the configuration file.
Crontab file consists of command per line and have six fields actually and separated either of
space or tab. The beginning five fields represent time to run tasks and last field is for command.
[Minute] [Hour] [Day_of_the_Month] [Month_of_the_Year] [Day_of_the_Week] [Command]
To configure cron jobs modify the /etc/crontab file. Allowed special character are (*, -, /, ?, #).
Character Description
Asterisk (*) Match all values in the field or any possible value
Hyphen (-) To define range
Slash (/) 1st field /10 meaning every ten minutes or increment of range
Comma (,) To separate items
Commands Description
# yum install cronie Install cron package
# systemctl restart crond Restart cron service
# systemctl status crond Check whether the crond service is running
# cat /etc/crontab Checking crontab format
# crontab -e Add or update job in crontab (e=edit)
# crontab -u username -e Add or update job in crontab for another user
# crontab -l View crontab entries of current user (l=list)
# crontab -u username -l View crontab entries of another user (l=list) (u=user)
# crontab -r Remove crontable entries (r=remove)
# crontab -e Add job to cron table
0 1 * * 5 /scripts/script.sh Schedule the script to run at 1AM every Friday
minute: 0, hour: 1, Day of month: * (Every day of
month), Month: * (Every Month) & Day: 5 (Friday)
# crontab -e Add job to cron table
* * * * * touch /test.txt Runs every minute, to create test.txt file
# crontab -e Add job to cron table
30 6 * * * <Command> Runs at 6:30 am every day
# crontab -e Add job to cron table
30 18 * * * <Command> Runs at 6:30 pm every day
# crontab -e Add job to cron table
00 11 * * * rm -f /var/tmp/* Runs at 11 am every day to remove all file from temp
Process Definition:
A process is a running program. So, any running program or a command given to a Linux system
is called a process. Linux can run a lot of processes at a time, which can slow down the speed of
some high priority processes and result in poor performance. The default value of all the
processes is 0.
Priority of Process:
When talking about processes priority is all about managing processor time. PR is the process's
actual priority, as viewed by the Linux kernel. The priority of a process denotes how much
processor time allocated to that process.
SELinux:
Security Enhanced Linux (SELinux) is an additional layer security for the system. A primary goal
of SELinux is to protect user data from system services that have been compromised. It as a set
of security rules that determine which process can access which files, directories & ports, with a
special security label called SELinux context.
SELinux Example:
Suppose we are running a web server which hosts several websites. To allow access on
websites we have to open several ports in firewall. Hackers may use these ports to crack the
system through the security exploits. And if that happens, hackers will gain the access
permission of web server process. To serve web pages, usually a web server process has read
permission on document root and write permission on the /tmp and /var/tmp directory. With
this permission, hackers can write malicious scripts in /tmp directory which can be used to hack
other services available on server. This way one infected process can cause a huge security rick
to all services running on server. If SELinux is enabled, hackers will not be able to access the
other services available on sever as well as they will not be able to write anything in /tmp or
/var/tmp directory.
SELinux Modes:
SELinux works in three modes; Disable, Permissive and Enforcing. In disable mode SELinux
remains completely disable. If SELinux is enabled, it will be in either Permissive mode or in
Enforcing mode. In permissive mode SELinux will only monitor the interaction. In enforcing
mode SELinux will also filter the interaction with monitoring. No reboot is required to go from
enforcing to permissive or back again. A system reboot is required to disable SELinux entirely,
or to get from disabled mode to enforcing or permissive mode. If configuration file value is set
to disable, after reboot, Linux will not load any libraries associated with SELinux. So, it will not
allow switch between enable and disable mode in running session.
SELinux Policy:
To protect the system SELinux uses the policy. A SELinux policy is basically a set of rules that
defines which process can access which files, directories and ports. With these rules set an
application will be able to access only the certain types of files and process which it requires to
function, nothing extra. SELinux uses context to identify the associated resources with an
application or process.
SELinux Context:
A context is the collection of security related information assigned on each object file,
directory, application, port, process etc of Linux file system. SELinux uses context to make
access control decision. To view the context of an object we can use Z flag with regular listing
command. Context always consists of four parts; User Part, Role Part, Type Part and Sensitivity
Part. Each part is separated by a colon (:).
User Part:
User Part is the first part. It ends with _u in the context label. In context label, it represents
SELinux user account. Each Linux user account is mapped with a SELinux user account. SELinux
does this mapping in policy.
Role Part:
Role Part is the second part in context label. It ends with _r. In SELinux policy role defines what
a subject can do with an object in specified domain. A subject is a user or a daemon or a
process which access the object. An object is a resource such as file, directory, process,
hardware device or network application which is accessed by subject. A domain defines what a
subject can do and what it can’t do. It is just like a bubble around the subject.
Type Part:
Type Part is third part in context label. It ends with _t. This part defines what kind of object is it.
For example, a type for file defines what kind of file is it such as /etc directory file, web page
file, hardware device file or network file.
Sensitivity Part:
Sensitivity Part is fourth and last part of security context label. This part defines multiple layer
of security. This part is used only when SELinux policy type is set to MLS mode.
SELinux Booleans:
SELinux Booleans are just like a switch which can be on or off as per requirement. SELinux
provides several ready to use Booleans to secure the default Linux environment. SELinux
Booleans are SELinux policy setting. A SELinux Boolean can be either on or off. If Boolean is on,
SELinux will permit the associate action. If Boolean is off, SELinux will deny the associate action.
Commands Description
# getenforce View the current status of SELinux
# sestatus OR details view of SELinux Status
# setenforce 0 Put SELinux in permissive mode OR
# setenforce permissive Put SELinux in permissive mode
# setenforce 1 Put the SELinux in enforcing mode OR
# setenforce enforcing Put the SELinux in enforcing mode
# vim /etc/selinux/config SELinux configuration file location
SELINUX = enforcing Permanently put SELinux in enforcing mode
SELINUX = permissive Permanently put SELinux in Permissive mode
SELINUX = disabled Permanently put SELinux in Disable mode
# ls –lZ View the context of files and directories
# netstat –Ztulpen View the context of network ports
# ps Zaux View the context of running process
# id -Z View the context of current user
# yum -y install httpd Install web server package
# systemctl start httpd Start web server services
# systemctl enable httpd Start Web Server services on boot
# cd /var/www/html Change to HTTP Sever default document root
# vim index.html Create index.html file
<h1> SELinux LAB Work</h1> Write some heading and bold text in
<b> This is just Test </b> index.html file
Disk Partitions:
Disk partitioning allows a hard drive to be divided into multiple logical storage units referred to
as partitions. By separating a disk into partitions, system administrators can use different
partitions to perform different functions. A hard disk needs partition table before it can be
used. There are two types of partition table MBR and GPT. If system is equipped with BIOS, only
MBR partition table can be used while if system is equipped with UEFI, any partition table can
be used.
BIOS / UEFI:
When the computer power on, the first program which starts is either a BIOS or a UEFI. This is
the starting point of computer. It performs a series of diagnostic test to detect and connect
CPU, Memory, Keyboard, Hard disks and other peripherals. This process is known as Power on
Self-Test (POST). If all peripherals are connected without any issue, BIOS/UEFI will find and
execute the boot loader program.
BIOS UEFI
BIOS stands for Basic Input Output System Stands for Unified Extensible Firmware Interface
BIOS is the classical approach to detect and UEFI is the modern way to start the system. It is
connect peripherals in system developed as the replacement of BIOS
BIOS was invented for PC in 1982 UEFI became available for all in 2007
BIOS provides very basic functionality. It UEFI provides backward compatibility, pre-boot
does not provide any troubleshooting environment which has its own shell, drivers
utility and applications. This environment includes
basic features for troubleshooting such as
remote diagnosis, emergency mode, Internet
connectivity and storage backup.
All settings are stored in CMOS Memory All settings are stored in Flash memory
BIOS doesn’t include driver for modern Usually UEFI can detect all modern devices
BIOS cannot boot from a partition which is The UEFI firmware can boot from a drive which
larger than 2TiB is up to 9ZiB in size
The BIOS runs in 16-bit processor mode, UEFI can run in 32-bit or 64-bit mode
and has only 1 MB of space to execute in
BIOS supports only MBR partition scheme UEFI supports both MBR and GPT partition
Commands Descriptions
# gdisk /dev/sdc Create the GPT partitions of disk sdc
Command (? for help): p Current layout of disk
Command (? for help): n Create new partition
Command (? for help): l List known partition types
Command (? for help): w Write table to disk and exit
# partprobe /dev/sdc Force the kernel to reread the partition table
# fdisk -l View all Disk Partitions in Linux
# fdisk -l /dev/sdc View Specific Disk Partition in Linux
# mkfs.ext3 /dev/sdc1 OR Format created partition with ext3 file
# mkfs -t ext3 /dev/sdc1 system both method can be used
# mkfs -t ext4 /dev/sdc2 Format partition with ext4 file system
# mkfs -t xfs /dev/sdc3 Format partition with xfs file system
# mkfs -t xfs /dev/sdc4 Extended partition can’t be format
# mkdir /data1 Create directory named data1
# mount /dev/sdc1 /data1/ Temporary mounted partition drive
# umount /data1/ OR # umount /dev/sdc1 Unmounted partition drive
# vim /etc/fstab Permanently mount partition in fstab
/dev/sdc1 /data1 ext3 defaults 0 0 Sdc1 partition in data1 folder
# mount -a Re-read the fstab file check for error
# e2label /dev/sdc1 data1 Give data1 label to sdc1 partition
# blkid /dev/sdc1 Find UUI of sdc1 partition
# vim /etc/fstab Open fstab file for configuration
LABEL=data1 /data1 ext3 defaults 0 0 Mount partition using label permanently
# vim /etc/fstab Open fstab file for configuration
UUID=2cc90e10-8a48-4cbe-8b8b- Mount partition using UUID permanently
dd1097ed0ae9 /data1 ext3 defaults 0 0
# umount /data1/ OR # umount /dev/sdc1 Unmounted partition drive before delating
# fdisk /dev/sdc Select sdc drive to delate
Command (m for help): d Delete all partition one by one
Command (m for help): w Save the changes
# lsblk List of block devices to check devices
command to activate a formatted swap space. To deactivate a swap space using the swapoff
command. Swap space priorities are displayed with swapon -s command.
Commands Description
# fdisk /dev/sdc Create the partitions of disk sdc
Command (m for help): p Current layout of disk
Command (m for help): n Create new partition
Command (m for help): l List known partition types
Command (m for help): t Change a partition's code
Hex code (type L to list all codes): 82 Partitions type identifier for swap space
Command (m for help): w Write table to disk and exit
# partprobe /dev/sdc Force the kernel to reread the partition table
# swapon -s OR # free -m Display the status of swap space
# mkswap /dev/sdc1 Format a partition for swap space
# swapon /dev/sdc1 Temporary Activate new swap partition
# swapoff /dev/sdc1 deactivate the swap space
# vim /etc/fstab Permanently mount swap partition in fstab
/dev/swap swap swap defaults 00 swap partition in swap folder
# swapon -a Activate all swap spaces listed in the fstab
# fdisk /dev/sdc Select sdc drive to delate
Command (m for help): d Delete all partition one by one
Command (m for help): w Save the changes
# dd if=/dev/random of=/swap_file bs=1M create swap space from file
count=1024 create a swap file
# mkswap /swap_file Put swap signature in the file
# chmod 0600 /swap_file Set permission on swap file
# swapon /swap_file Activate the swap space
# swapon -s Check swap space activation
# swapoff /swap_file Deactivate the swap space
# rm -rf /swap_file To delete the swap space file
Advantages of LVM:
Volumes can consist of more than one disk. Easy resize operation and replacement of failing
disks. Advanced options such a working with snapshots, which allows you to create backups
even if they are open. Easy to add new volumes up to 256 logical volume.
Filesystem (FS):
To use a partition for data storage we need to create a file system on it. File system is a logical
container that is used to store the files and directories. Each partition must be formatted with
file system before it can be used for data storage. Red Hat Linux supports several file system
types such as EXT, EXT1, EXT2, EXT3, EXT4, XFS etc.
File systems are built on top of logical volumes. The command mkfs can be used to create file
system on top of a logical volume. Once the file system is created mount the logical volume as
per requirement.
Usage of NFS:
File / Folder sharing between Linux systems. Allows to mount remote filesystems locally. Can be
acted as Centralized Storage system. It can be used as a Storage Domain (Datastore) for
VMware and another Virtualization Platform. Allows applications to share configuration and
data files with multiple nodes. Allows to have updated files across the share.
Server Side NFS Configuration:
Commands Description
# yum install nfs-utils libnfsidmap Install nfs package utilities
# systemctl enable rpcbind Enable rpcbind service on boot
# systemctl enable nfs-server Enable nfs-server service on boot
# systemctl start rpcbind Start rpcbind service
# systemctl start nfs-server Start nfs-server service
# systemctl start nfs-idmap Start nfs-idmap service
# systemctl stop firewalld Stop firewall temporary
# setenforce 0 OR # setenforce Permissive Disable SELinux Temporary
# firewall-cmd --permanent --add-service=nfs Incase using Firewall add service NFS
# firewall-cmd --permanent --add- Incase using Firewall add service mounted
service=mountd
# firewall-cmd --permanent --add- Also add service rpc-bind
service=rpc-bind
# firewall-cmd --reload Reload firewall configuration to take effect
# mkdir /nfsshare Create a shared directory for NFS
# chmod 777 /nfsshare/ Set full permission on shared directory
# vi /etc/exports Edit Export file put share directory
/nfsshare 192.168.147.144(rw, sync, Share folder, NFS client IP, & permission
no_root_squash) OR OR
/nfsfileshare 192.168.147.144 (rw) OR Share folder, NFS client IP and permission
/nfsfileshare 192.168.147.0 (rw) Share, NFS client network & permission
# exportfs -r Exporting the share
# systemctl restart nfs-server Restarting NFS Server service
Commands Description
/nfsshare Shared Directory
192.168.147.0/24 IP address range of clients
rw Writable permission to shared folder
sync Synchronize shared directory
no_root_squash Enable root privilege
no_all_squash Enable user’s authority
Fstab Mounting:
Fstab is Linux operating system’s file system table. Fstab is an alternate method to mount NFS
permanently, filesystem will be mounted automatically after the reboot even use the filesystem
or not all the time mounted. It contains information about major filesystems on the system. The
fstab file is located at: /etc/fstab
Autofs Mounting:
Autofs is a service offered us to automatically mount the filesystem when they need. It can also
unmount the filesystem when not in use for a particular predefined timeout value. If mount
the NFS filesystem using autofs, filesystem will be mounted when someone is accessing it and
automatically unmount when not in use after the timeout value. Booting time is significantly
reduced because no mounting is done at boot time. The main configuration file for Autofs is the
/etc/auto.master file, referred as the master map. The master map file contains list of a mount
and the location of its map.
Commands Description
# rpm -qa autofs Verifying autofs package is install or not
# yum install -y autofs Install autofs package
# systemctl start autofs Start autofs service
# systemctl enable autofs Enable autofs service on boot
# vim /etc/auto.master Edit master map configuration file
/autofs /etc/auto.nfs --timeout=60 Local directory, Map file location, timeout
# cp /etc/auto.misc /etc/auto.nfs Copy and edit default auto file
# vim /etc/auto.nfs OR Create map file auto.nfs
nfsshare -rw 192.168.147.128:/nfsshare Mount Point, Mount Option, Share Location
# systemctl restart autofs Restart autofs service
# cd /autofs/nfsshare Accessing share directory
# df -hT OR # df -kh Display file system type in human-readable
# mount -av Display all mount filesystems
SMB:
SMB stands for Server Message Block. It’s a Windows file sharing protocols. The smbd server
daemon provides file sharing and printing services to Windows clients. The initials of smbd
stand for Server Message Block Daemon. It allows us to share files, folders, and printers
between Linux server and Windows clients.
Samba:
Samba is an open source implementation of the Server Message Block (SMB) protocol. It allows
the networking of Microsoft Windows, Linux, UNIX, and other operating systems together,
enabling access to Windows-based file and printer shares. Samba, can also be used to setup a
domain controller on Linux server, and integrate Windows clients to the Domain controller. The
technology used by SMB protocol is called SAMBA.
Samba Client:
When an RHEL system accesses resources on a Windows system, it is using the Samba Client.
Use Samba Client utility to transfer files between a Windows 'server' and a Linux client. An RHEL
system, by default, has the Samba Client installed.
Samba Server:
When an RHEL system serves resources to a Windows system, it uses the package Samba Server
or simply Samba. This is not installed by default.
NMBD:
Nmbd stand for NetBIOS Message Block Daemon. Nmbd is a server that understands and can
reply to NetBIOS over IP name service requests.
Autofs Mounting:
Autofs is a service offered us to automatically mount the filesystem when they need. It can also
unmount the filesystem when not in use for a particular predefined timeout value. If mount
the NFS filesystem using autofs, filesystem will be mounted when someone is accessing it and
automatically unmount when not in use after the timeout value. Booting time is significantly
reduced because no mounting is done at boot time. The main configuration file for Autofs is the
/etc/auto.master file, referred as the master map. The master map file contains list of a mount
and the location of its map.
Anonymous Share:
Commands Description
# rpm -q samba OR Quarry samba is install or not
# yum list installed | grep samba Another way to check samba is install or not
# yum install samba samba-client samba- Install samba packages
common OR
# yum install samba* Easy way to install samba packages
# cp /etc/samba/smb.conf Take backup of samba configuration file
/etc/samba/smb.conf.bak
# mkdir /any_share Create share directory named any_share
# chmod 777 /any_share Set full permission on share directory
# chown -R nobody: nobody /any_share Change group to nobody
# vim /etc/samba/smb.conf Edit the Samba configuration file in the end
[Any Share] Share Name is whatever title you choose
path = /any_share Full path of share Directory
browsable = yes The share appears available to all users
writable = yes Writable permission to yes
guest ok = yes Specifies this share as publicly accessible
guest only = yes Allow guest to access share
read only = no To modify or copy files to the directory
public = yes The share is publicly accessible
# systemctl restart smb Restart samba service
# systemctl enable smb Enable samba service on boot
# systemctl restart nmb Restart nmb service
# systemctl enable nmb Enable nmb service on boot
# testparm Check samba configuration settings
# systemctl stop firewalld Stop firewall temporary
# firewall-cmd --permanent --zone=public -- OR Add samba to firewall
add-service=samba
# firewall-cmd --reload Reload Firewall services
# chcon -t samba_share_t any_share Add samba to SELinux
# setenforce 0 OR Disable Temporary
\\192.168.147.151 For Windows user to access samba share
smb://192.168.147.151 For Linux user to access samba share
# smbclient -L localhost Check list of shares on local system
#smbclient -L 192.168.147.151 OR check list of shares on local system by IP
Secured Share:
Commands Description
# mkdir /secure_share Create share directory named secure_share
# chmod 777 /secure_share Set full permission on share directory
# useradd smbuser Create user named smbuser
# groupadd smbgroup Create group name smbgroup
# usermod smbuser -G smbgroup Add user smbuser to group smbgroup
# smbpasswd -a smbuser Set smb password for user
# chown -R smbuser: smbgroup Give permission to user on share directory
/secure_share
# systemctl stop firewalld Stop firewall temporary
# firewall-cmd --permanent --zone=public -- OR Add samba to firewall
add-service=samba
# firewall-cmd --reload Reload Firewall services
# chcon -t samba_share_t secure_share Add samba to SELinux
# setenforce 0 OR Disable Temporary
# vim /etc/samba/smb.conf Edit the Samba configuration file in the end
[Secure Share] Share Name is whatever title you choose
path = /secure_share Full path of share Directory
browsable = yes The share appears available to all users
writable = yes Writable permission to yes
guest ok = no Require password to access share
read only = no To modify or copy files to the directory
hosts allow = 192.168.147.0/24 Host to allowed share access
valid users = smbuser ahmad @smbgroup Users list to login to share
# systemctl restart smb Restart samba service
# systemctl enable smb Enable samba service on boot
# systemctl restart nmb Restart nmb service
# systemctl enable nmb Enable nmb service on boot
# testparm Check samba configuration settings
\\192.168.147.151 For windows user to access samba share
smb://192.168.147.151 For Linux user to access samba share
# smbclient -L localhost Check list of shares on local system
#smbclient -L 192.168.147.151 OR check list of shares on local system by IP
Command Descriptions
guest ok = yes No password is required to connect to the service
guest ok = no Password is required to connect to the service
guest only = yes Only guest connections to the service are permitted
guest only = no Guest connections to the service are not permitted
hosts allow = ahmad, user comma, space, or tab to set of hosts which are permitted
hosts allow = none All hosts permitted access
hosts deny = user2 hosts listed here are NOT permitted access to services
browseable = yes Share is seen in the list of available shares in the browse
browsable = yes Synonym for browseable
valid users = ali, @users List of users allowed to login to this service
read only = yes Users not create or modify files in the service's directory
read only = no Users can create or modify files in the service's directory
map to guest = Bad User User logins with an invalid password are rejected
map to guest = Bad Password User logins with an invalid password are treated as a guest
map to guest = Never User login requests with an invalid password are rejected
public = yes Synonym for guest ok
Reboot:
Reboot is a way of restarting your computer while in a working state, using your computer
hardware, like the computer can be restart by using power button or through the GUI. It can be
used to shut down or reboot Linux. Hard or Cold Reboot to power physically shut down & then
turned back on. Soft or Warm Reboot the system gets restarted by losing any kind of power.
Shutdown:
Shutdown command is used to shut down a system or restart it. It is commonly used to shut
down or reboot both local and remote machines. Syntax: shutdown [Option] [Time] [Message]
Commands Descriptions
# reboot Reboot or restart the system
# reboot -f Forcefully reboot the system like pressing button
# systemctl reboot Reboot or restart the system
# shutdown -r now Reboot or restart the system
# shutdown -r +5 “Any Message” Reboot system after 5 minutes display message
# init 6 Reboot the system
# telinit 6 Reboot the system
# halt Shutdown the system
# systemctl halt Shutdown the system
# shutdown -h now Shutdown the system now
# shutdown -h +5 “Any Message” Shutdown system after 5 minutes display message
# shutdown -c Cancelled the shutdown
# init 0 Shutdown the system
# telinit 0 Shutdown the system
# poweroff Poweroff the system
# systemctl poweroff Poweroff the system
# systemctl --no-wall poweroff Poweroff the system
# reboot -p Poweroff the system using reboot command
# systemctl suspend Suspend the system
# systemctl hibernate Hibernate the system
# systemctl hybrid-sleep Hibernate and suspend the system
Systemd Target:
Each Target designates a different system configuration and allows access to a different
combination of processes. Targets determine how much of the systems services are actually
running. Should it start with GUI Mode or should it start with Text Mode is decided by Target.
Target units have a (. target) extension and similar to run levels, Target units allow you to start a
system with only the services that are required for a specific purpose. RedHat Enterprise Linux 7
is distributed with a set of predefined targets. The default target unit is represented by the
/etc/systemd/system/default.target file. This file is a symbolic link to the current default target
unit. Even after the Linux system is booted to a target, you can change it to another target. It is
possible for a target to be a part of another target; for example, the graphical.Target includes
multi-user. target, which in turn depends on basic. target and others.
Multi-User.Target:
In this type of target system starts in Text Mode with Multi User Access, Networking and all
active Services. System supports multiple users, text-based logins only.
Graphical.Target:
In this type of target system starts with Graphical User Interface (GUI) with Multi User Access,
Networking & all active Services. System supports multiple users, graphical & text-based logins.
Commands Description
# systemctl get-default View the default target
# systemctl list-units --type=target View all currently loaded targets
# systemctl list-units --type target --all View all loaded active and inactive targets
# systemctl set-default multi-user.target Set default target to multi user target
# systemctl set-default rescue.target Set default target to rescue.target mode
# systemctl isolate multi-user.target Switch the target while system is running
# systemctl default Set current target to default without reboot
# systemctl isolate default.target OR Set current target to default without reboot
Netfilter:
The Linux kernel includes Netfilter, which allows kernel modules to inspect every packet
traversing the system. Tools like iptables, ip6tables, ebtables and firewalld are used to manage
Netfilter.
FirewallD:
FirewallD is the Dynamic Firewall Manager of Linux systems. It allows and deny particular port
to particular network and IP Address. FirewallD is available in GUI and CLI, CLI tool is firewall-
cmd. firewall-cmd is the command line client of the firewalld daemon. It provides interface to
manage runtime and permanent configuration.
Firewalld uses two configuration sets: Runtime and Permanent. Any changes made in the
Permanent configuration will not become active until the firewalld service is restarted or
reloaded. Likewise, any changes made in the Runtime configuration will get lost ones the
service is restarted or reloaded of the firewalld service.
Firewalld classifies the network into zones (private, public, DMZ) and each zone includes
interfaces. The default zone is set to public and interfaces are assigned to public if no changes
are made. A network zone defines the level of trust for network connections.
In order to use firewalld as a default disable and mask iptables and ip6tables permanently.
Firewalld comes with pre-defined services by default, there are many services are available and
we can take these services as example to add our services by simply copying them. Services are
set of rules with ports and options which is used by Firewalld. Services which are enabled, will
be automatically loaded when the Firewalld service up and running.
Go to Applications Menu -> Sundry -> Firewall to open GUI version of Firewall
Commands Description
# systemctl disable iptables Disable iptables service
# systemctl disable ip6tables Disable ip6tables service
# systemctl stop ip6tables Stop ip6tables service
# systemctl stop iptables Stop iptables service
# systemctl mask ip6tables Mask ip6tables service
# systemctl mask iptables Mask iptables service
# yum install -y firewalld firewall-config Install firewall packages CLI and GUI
# firewall-cmd --version Check firewall version
# systemctl start firewalld Start firewall service
# systemctl enable firewalld Enable firewall service
# systemctl status firewalld Verify Service Status of Firewall
# firewall-cmd --state Check firewalld daemon is running
# systemctl stop firewalld To stop the firewall service
# systemctl disable firewalld To disable the firewall service
# firewall-cmd --reload Reload firewall configuration
# firewall-config GUI tool to manage firewalld
# firewall-cmd --get-default-zone Check default zone
# firewall-cmd --set-default-zone=home Change default zone to home
# firewall-cmd --get-active-zones Check the zone used by network interface
# firewall-cmd --list-all-zones All configurations for all zones
# firewall-cmd --zone=public --list-all All configurations for a specific zone
# firewall-cmd --get-services List out currently loaded services on firewall
# firewall-cmd --permanent --get-services List permanent loaded services on firewall
# firewall-cmd --panic-on Disable incoming and outgoing packets
# firewall-cmd --panic-off Enable incoming out going packets
# firewall-cmd --query-panic Check panic mode is enabled or disabled
# firewall-cmd --list-all List all open ports and services
# firewall-cmd --zone=public --list-ports List all ports from specified zone
# firewall-cmd --permanent --add- Add Ports to firewall rules
port=22/tcp
# firewall-cmd --permanent --zone=public -- Add Ports to specified firewall zone rules
add-port=22/tcp
# firewall-cmd --permanent --remove- Remove Ports to firewall rules
port=22/tcp
# firewall-cmd --list-services List all Services to firewall rules
# firewall-cmd --list-services --zone=public List all services of specified firewall zone
# firewall-cmd --permanent --add- Add services to firewall rules permanently
service=https
# firewall-cmd --permanent --remove- Remove services from firewall rules
service=https permanently
# firewall-cmd --remove-service=https Remove services from firewall rules runtime
# vim /etc/firewalld/zones/public.xml Adding & removing services/ports using XML
# cat /etc/firewalld/zones/public.xml Firewalld configuring ports / services XML file
# ls /usr/lib/firewalld/services/ Default system services
# man firewalld Firewalld help manual
# firewall-cmd --help Get help of firewalld