Sei sulla pagina 1di 48

Linux Command Lines

1. Basic commands and options


2. Permissions – umask
3. Special permissions
4. Logs
5. Process – top
6. Partitions – LVM, Fdisk, Gdisk
7. YUM, RPM Source file installations
8. Virtuallizations
9. Booting Process
10.Find / Grep / Locate – Commands, Differentiate uses
11.Port Numbers SSH, Telnet, FTP, Samba, DNS, DHCP, NFS, ISCSI, POSTFIX etc…
12.Working of DNS
a. Working of NFS
b. Working of SAMBA
c. Working of ISCSI
d. Working of POSTFIX
13.IPTABLES, IPCHAINS, Firewall
14.CRON JOBS
15.LIVE PROJECTS – AMANDA, LAMP, VSFTPD, EXIM etc…
16.Security Linux Features
File System

/usr  Installed software , shared libraries , etc

/usr/bin  To store user commands

/usr/sbin  To store system administration commands

/usr/local  To store locally customized software

/etc  To store configuration files

/var  Directory contains dynamic configuration data, such as FTP


and websites

/run  run time data. The contents of this directory are recreated on
reboot
/home  home directory for regular users

/root  home directory for root user otherwise known as super user

/temp  It stores temporary files and these files will be deleted in 10


days

/boot  files needed in order to start the boot process

/dev  Contains special devices file which are used by the s/m to
access the hardwre

/etc/passwd  user details

/etc/group  group details

/etc/shadow  encrypted passwords are stored here

/var/log/secure  The log files for security and authentication-related messages


and errors

/var/log/maillog  Log file with mail server-related messages

/var/log/cron  Log file related to periodically executed tasks.

/var/log/boot.log  Messages related to system startup are logged here.

/var/log/messages  system message log file

/var/log  The directory to which rsyslog is writing all the log files.

/etc/rsyslog.config  Configuration file for log.

UID Ranges

UID 0  Root

UID 1 to 200  Range of system users assigned to the “system users” assigned to
system purposes by red hat
UID 201 to 999  Is a range of “System users” used by system processes that do not
own files on the file system.
UID 1000 to 60000  is the range for regular users
Linux Command Basics

Command name – Options – Arguments

Vim /etc/services

ls –ld /etc

1. Ls
a. Ls list files with no options
b. Ls –ld /etc
c. ls –l shows file or directory, size, modified date and time, file or
folder name and owner of file and it’s permission
d. ls –a to view hidden files
e. ls –lh list files with human readable format
f. ls –F list files and directories with ‘/’ character at end
g. ls –lr list files in reverse order
h. ls –lS sort files by size
i. ls –help show help page
j. ls –l /tmp list directory information
k. ls –n display UID & GID of files
l.
2. Cd change directory
3. Cp source destination to copy a file from one location to other
4. mv source destination
5. man command name
6. mkdir
a. mkdir –m777 /new set file mode (as CHMOD Command)
b. mkkdir –p /folder1/dir1 with parent directory
c. mkdir –v /dir1 verbose output; print a message for
each
created directory
7. rm dir
a. rmdir –p /dir1
b. rmdir –v /dir1
8. touch
a. touch file1
b. touch file1 file2 file3
c.
9. Clear Clear the screen
10.Passwd –d usersname To delete the password of the user
11.w To know the users which have log’d in.
12.netstat Is a command line tool for monitoring network
connections both incoming and outgoing as well as
viewing routing tables, interface statistics etc
13.rm It’s a command used to remove or delete a file or an
directory.
14.locate Locate command returns search results based on the
file name or the path from the locate database. The
database stores file name and path information.
15.wc command counts the lines, words and characters in a
file
16.head command displays the beginning of a file.
17.tail shows the end of the file.
18. File <filename> command scans the beginning of a files content and
displays what type it is.
19.date show the time and date of the system.
20.pwd shows the present working directory.
21.cp to copy file and directory.
22.passwd to change the password of the current user.
23.ps to list the current process.
24.ps-aux 
25.useradd to add an user.
26.chage password gaining policy.
27.chmod to change the permission.
28.chown to change the ownership.
29.kill to stop the current working process.
30.grep to find the words in a file.
31.find to find files and directorys
32.cat to display the contains of the file.
33.timedatectl to list the current time-related system settings ,
including current time , time zone and NTP
synchronization settings of the system.
34. echo Echo allows a user to repeat, or "echo," a string variable
to standard output.
35. get to download the remote file
36.scp secure copy file
37.rsync synchronize copy a file.
38.tar to take backup of and file and directory.
39.blkid command gives an overview of existing partitions with a
file system on them
40.sudo sudo ("superuser do") allows a user with proper
permissions to execute a command as another user,
such as the superuser.
41.dd Disk duplicate. The man page says this command is to
"Convert and copy a file", but although used by more
advanced users, it can be a very handy command. The
"if" means input file, "of" means output file.
42. dd if=/dev/hdb1 of=/backup/
43.df Show the amount of disk space used on each mounted
filesystem.
44.ln Creates a symbolic link to a file.
45.whereis Show where the binary, source and manual page files
are for a command.
46.Whoami Identify the logged in user
Permissions – UMASK

umask is a command that determines the settings of a mask that controls how file
permissions are set for newly created files.

UMASK value is for the users

666 & 777 UMASK values

This is because only scripts and binaries should have execute permissions, normal and
regular files should have just read and write permissions. Directories require execute
permissions for viewing the contents in it, so they can have 777 as permissions.

Man umask
Info umask

Umask value for root – 022


Umask value for users – 002

Read – 4
Write – 2
Execute -1

0 --Full permissions (Read, Write, Execute)


1 --Write and read
2 --Read and execute
3 --Read only
4 --Write and execute
5 --Write only
6 --Execute onlyadminadmin
7 --No permissions

Special Permissions

STICKY BIT

A Sticky bit is a permission bit that is set on a file or a directory that lets only the owner
of the file/directory or the root user to delete or rename the file. No other user is given
privileges to delete the file created by some other user
Chmod o+t

SUID

EXAMPLE1: PASSWD COMMAND


When we try to change our password we will use passwd command, which is owned by
root. This passwd command file will try to edit some system config files such as
/etc/passwd, /etc/shadow etc when we try to change our password. Some of these files
cannot be opened or viewed by normal user only root user will have permissions. So if we
try to remove SUID and give full permissions to this passwd command file it cannot open
other files such as /etc/shadow file to update the changes and we will get permission
denied error or some other error when tried to execute passwd command. So passwd
command is set with SUID to give root user permissions to normal user so that it can
update /etc/shadow and other files.
EXAMPLE2: PING COMMAND
Similarly if we take ping command, when we have to execute this command internally it
should open socket files and open ports in order to send IP packets and receive IP
packets to remote server. Normal users don’t have permissions to open socket files and
open ports. So SUID bit is set on this file/command so that whoever executes this will get
owner (Root user’s) permissions to them when executing this command. So when this
command start executing it will inherit root user permissions to this normal user and
opens require socket files and ports.

EXAMPLE3: CRONTAB AND AT COMMAND


When scheduling the jobs by using crontab or at command it is obvious to edit some of
the crontab related configuration files located in /etc which are not writable for normal
users. So crontab/at commands are set with SUID in-order to write some data.
Example

Chmod u+s /filename.txt

Chmod 4750 /filename.txt

Here in 4750, four indicates SUID bit set, seven for full permissions for owner, five for
read and execute permissions for group, and no permissions for others.

WHERE IS SUID USED?


1) Where root login is required to execute some commands/programs/scripts.

2) Where you don’t want to give credentials of a particular user, but want to run some
programs as the owner.

3) Where you don’t want to use SUDO command, but want to give execute permission for
a file/script etc.

SGID

SGID (Set Group ID up on execution) is a special type of file permissions given to a


file/folder.

Chmod g+s filename.txt to remove chmod g-s filename.txt

Chmod 2750 filename.txt

Here in 2750, 2 indicates SGID bit’set, 7 for full permissions for owner, 5
for read and execute permissions for group, and no permissions for others.

To check the file permission


Ls –l

How can I find all the SGID set files in Linux/Unix.


find / -perm /2000

The above find command will check all the files which is set with SGID bit(2000)

Permissions

RWX - directory
RW - files

R - 4
W - 2
X - 1
UMASK VALUE of USER - 002
UMASK VALUE of ROOT - 022

Chmod ugo rwx - directories 777


Chmod ugo rw - files 666

User created directories -


LOGS

Common Linux log files names and usage


 /var/log/messages : General message and system related stuff
 /var/log/auth.log : Authenication logs
 /var/log/kern.log : Kernel logs
 /var/log/cron.log : Crond logs (cron job)
 /var/log/maillog : Mail server logs
 /var/log/qmail/ : Qmail log directory (more files inside this directory)
 /var/log/httpd/ : Apache access and error logs directory
 /var/log/lighttpd/ : Lighttpd access and error logs directory
 /var/log/boot.log : System boot log
 /var/log/mysqld.log : MySQL database server log file
 /var/log/secure or /var/log/auth.log : Authentication log
 /var/log/utmp or /var/log/wtmp : Login records file
 /var/log/yum.log : Yum command log file.

LOG FILE

a logfile is a file that records either events that occur in an operating system or other
software runs, or messages between different users of a communication
software. Logging is the act of keeping a log. In the simplest case, messages are
written to a single logfile.

Use of var/log message


It is used to examine or control the kernel ring buffer. messages : It contains global
system messages, including the messages that are logged during system startup.
There are several things that are logged in /var/log/messages including mail, cron,
daemon, kern, auth, etc

Booting Process
It is important to understand the linux boot process to troubleshoot boot problems. The
post describes the high level steps in the boot process. Below flow chart describes basic
boot stages and what happens during each boot stage.

1. BIOS (or firmware phase)

– The BIOS (Basic Input/Output System), performs the POST (power on self test) to
detect, test and initialize system hardware components.
– Loads the MBR (Master boot record).

2. Master boot record (MBR)

– Master Boot Record (MBR) is the first 512 bytes of the boot drive that is read into
memory by the BIOS.
– The next 64 bytes contain the partition table for the disk. The last two bytes are the
“Magic Number” which is used for error detection.
– MBR discovers the bootable device and loads the GRUB2 boot loader into memory and
transfers control over to it.

3. GRUB2 Bootloader

– The default bootloader program used on RHEL 7 is GRUB 2. GRUB stands for GRand
Unified Bootloader. GRUB 2 replaces the older GRUB bootloader also called as legacy
GRUB.
– The GRUB 2 configuration file is located at /boot/grub2/grub.cfg (Do not edit this file
directly).
– GRUB 2 menu-configuration settings are taken from /etc/default/grub when generating
grub.cfg.
– If changes are made to any of these parameters, you need to run grub2-mkconfig to
re-generate the /boot/grub2/grub.cfg file.

– GRUB2 searches the compressed kernel image file also called as vmlinuz in the /boot
directory.
– GRUB2 loads the vmlinuz kernel image file into memory and extracts the contents of
the initramfs image file into a temporary, memory-based file system (tmpfs).
– The initial RAM disk (initrd) is an initial root file system that is mounted before the real
root file system.

initramfs
– The job of the initial RAM file system is to preload the block device modules, such as for
IDE, SCSI, or RAID, so that the root file system, on which those modules normally
reside, can then be accessed and mounted.
– The initramfs is bound to the kernel and the kernel mounts this initramfs as part of a
two-stage boot process.
– The dracut utility creates initramfs whenever a new kernel is installed.
– Use the lsinitrd command to view the contents of the image created by dracut:

4. Kernel

– The kernel starts the systemd process with a process ID of 1 (PID 1).

5. systemd

– systemd is the ancestor of all processes on a system.


– systemd reads the file linked by /etc/systemd/system/default.target

The system target file defines the services that systemd starts.
systemd brings the system to the state defined by the system target, performing system
initialization tasks such as:
1. Setting the host name
2. Initializing the network
3. Initializing SELinux based on its configuration
4. Printing a welcome banner
5. Initializing the system hardware based on kernel boot arguments
6. Mounting the file systems, including virtual file systems such as the /proc file system
7. Cleaning up directories in /var
8. Starting swapping

Port Numbers

21 FTP

22 SSH

23 TELNET

25 SMTP/POSTFIX

42 Name Server Internet Name Service

80 HTTP/www

88 Kerberos Kerberos Network Authentication

115 SFTP

123 NTP Network Time Protocol

389 LDAP Light Weight Directory Access Protocol

443 HTTPS

3306 My Sql My SQL Database Service

3260 ISCSI

139/445 SAMBA – TCP

137/138 SAMBA - UDP

2049 NFS

53 DNS

68 DHCP

110 POP3 Post Office Protocol Ver. 3

995 POP3 S POP3 through Secure Socket Layer

POP3 downloads mail to the single system


143 IMAP Internet Message Access Protocol

873 Rsync Remote sync file transfer service

Domain Name System – DNS


The Domain Name System (aka DNS) is used to resolve human-readable hostnames like
www.Dyn.com into machine-readable IP addresses like 204.13.248.115. DNS also
provides other information about domain names, such as mail services

When you visit http://dyn.com in a browser, your computer uses DNS to retrieve the
website’s IP address of 204.13.248.115. Without DNS, you would only be able to visit our
website (or any website) by visiting its IP address directly, such
as http://204.13.248.115.

How does DNS work?

When you visit a domain such as dyn.com, your computer follows a series of steps to
turn the human-readable web address into a machine-readable IP address.

Step 1: Request information

The process begins when you ask your computer to resolve a hostname, such as
visiting http://dyn.com. The first place your computer looks is its local DNS cache,
which stores information that your computer has recently retrieved.

If your computer doesn’t already know the answer, it needs to perform a DNS query to
find out.

Step 2: Ask the recursive DNS servers

If the information is not stored locally, your computer queries (contacts) your
ISP’s recursive DNS servers. These specialized computers perform the legwork of a
DNS query on your behalf. Recursive servers have their own caches, so the process
usually ends here and the information is returned to the user.

Step 3: Ask the root nameservers

If the recursive servers don’t have the answer, they query the root nameservers.
A nameserveris a computer that answers questions about domain names, such as IP
addresses. The thirteen root nameservers act as a kind of telephone switchboard for
DNS. They don’t know the answer, but they can direct our query to someone that knows
where to find it.

a.root-servers.net………….m.root-servers.net.

Step 4: Ask the TLD nameservers (Top Level Domain – Name Server)

The root nameservers will look at the first part of our request, reading from right to left
— www.dyn.com — and direct our query to the Top-Level Domain (TLD)
nameservers for .com. Each TLD, such as .com, .org, and .us, have their own set of
nameservers, which act like a receptionist for each TLD. These servers don’t have the
information we need, but they can refer us directly to the servers that do have the
information.

Step 5: Ask the authoritative DNS servers

The TLD nameservers review the next part of our request — www.dyn.com — and direct
our query to the nameservers responsible for this specific domain. These authoritative
nameservers are responsible for knowing all the information about a specific domain,
which are stored in DNS records. There are many types of records, which each contain a
different kind of information. In this example, we want to know the IP address
for www.dyndns.com, so we ask the authoritative nameserver for the Address Record
(A).

Step 6: Retrieve the record

The recursive server retrieves the A record for dyn.com from the authoritative
nameservers and stores the record in its local cache. If anyone else requests the host
record for dyn.com, the recursive servers will already have the answer and will not need
to go through the lookup process again. All records have a time-to-live value, which is
like an expiration date. After a while, the recursive server will need to ask for a new copy
of the record to make sure the information doesn’t become out-of-date.

Step 7: Receive the answer

Armed with the answer, recursive server returns the A record back to your computer.
Your computer stores the record in its cache, reads the IP address from the record, then
passes this information to your browser. The browser then opens a connection to the
webserver and receives the website.

This entire process, from start to finish, takes only milliseconds to complete.

Webserver
The primary function of a web server is to store, process and deliver web pages to
clients. The communication between client and server takes place using the Hypertext
Transfer Protocol (HTTP).

Web server is a computer where the web content is stored. Basically web server is used
to host the web sites

1. On the hardware side, a web server is a computer that stores a website's component
files (e.g. HTML documents, images, CSS stylesheets, and JavaScript files) and delivers
them to the end-user's device. It is connected to the Internet and can be accessed
through a web browsers.
2. On the software side, a web server includes several parts that control how web users
access hosted files, at minimum an HTTP server. An HTTP server is a piece of software
that understands URLs (web addresses) and HTTP (the protocol your browser uses to
view webpages).
3. At the most basic level, whenever a browser needs a file hosted on a web
server, the browser requests the file via HTTP. When the request reaches the
correct web server (hardware), the HTTP server (software) sends the requested
document back, also through HTTP.

To publish a website, you need either a static or a dynamic web server.

 A static web server, or stack, consists of a computer (hardware) with an HTTP


server (software). We call it "static" because the server sends its hosted files
"as-is" to your browser.

 A dynamic web server consists of a static web server plus extra software,
most commonly an application server and a database. We call it "dynamic"
because the application server updates the hosted files before sending them to
your browser via the HTTP server.

Web server is mainly used to host a website.

How to run httpd Service

First we have to check the current status of the apache HTTP Server. To be able to use
httpd service, make sure you have the httpd installed.

Command for that # yum install httpd

To run the httpd service # service httpd start

And to start the service automatically at the boot time

# chkconfig httpd on

And to stop the service # service httpd stop


And to prevent the service automatically at the boot time

# chkconfig httpd off

In httpd there are three different ways to restart a running httpd service

# service httpd restart

# service httpd graceful

# service httpd reload

To Verify the service status # service httpd status

When httpd service is started by default it reads configuration from the locations they are

/etc/httpd/conf/httpd.conf : The main configuration file

/etc/httpd/conf.d/ : An auxiliary directory for configuration files that are

included in the main configuration file

Directives in httpd is /etc/httpd/conf/httpd.conf


What are SMTP, POP3 and IMAP?

Overview
SMTP, POP3 and IMAP are TCP/IP protocols used for mail delivery. If you plan to set up
an email server such as hMailServer, you must know what they are used for. Each
protocol is just a specific set of communication rules between computers.

SMTP
SMTP stands for Simple Mail Transfer Protocol. SMTP is used when email is delivered from
an email client, such as Outlook Express, to an email server or when email is delivered
from one email server to another. SMTP uses port 25.

POP3
POP3 stands for Post Office Protocol. POP3 allows an email client to download an email
from an email server. The POP3 protocol is simple and does not offer many features
except for download. Its design assumes that the email client downloads all available
email from the server, deletes them from the server and then disconnects. POP3
normally uses port 110.

IMAP
IMAP stands for Internet Message Access Protocol. IMAP shares many similar features
with POP3. It, too, is a protocol that an email client can use to download email from an
email server. However, IMAP includes many more features than POP3. The IMAP protocol
is designed to let users keep their email on the server. IMAP requires more disk space on
the server and more CPU resources than POP3, as all emails are stored on the server.
IMAP normally uses port 143. Here is more information about IMAP.

DHCP

Dynamic Host Configuration Protocol (DHCP) is a client/server protocol that automatically


provides an Internet Protocol (IP) host with its IP address and other related configuration
information such as the subnet mask and default gateway

Dynamic Host Configuration Protocol (DHCP) is a network protocol that enables a


server to automatically assign an IP address to a computer from a defined range of
numbers configured for a given network.
Configuration Files

File Description

Contains a list of file systems which


NFS /etc/exports may be made available to other
systems on the network via NFS.
/etc/sysconfig/nfs
Samba /etc/samba/smb.conf
SELINUX /etc/sysconfig/selinux
NTP /etc/chrony.conf
ISCSI /etc/iscsi/initiatorname.iscsi
HTTPD /etc/httpd/conf.d
MAIL – POSTFIX /etc/postfix/main.cf
APACHE /etc/httpd/conf/httpd.conf
MARIADB /etc/my.cnf
SSH /etc/ssh/sshd.conf
YUM /etc/yum.conf
/etc/yum.repos.d
USER PASSWORD
RELATED /etc/login.defs
DETAILS
USER DETAILS /etc/passwd
GRUB /etc/grub.conf
Run Levels /etc/rc.d
DNS /etc/named.conf
/etc/resolve.conf
Kernel /var/log/kern.log
Cron Job /etc/chron.conf
The Linux kernel file. File naming
/boot/vmlinuz conventions may include release
information
Device file for the first IDE hard drive
/dev/had
on the system
A parent shell script to run commands
/etc/crontab periodically. It invokes hourly, daily,
weekly, and monthly scripts.
The file system table contains the
HDD Mounting /etc/fstab description of what disk devices are
available at what mount points.
Group Holds information regarding security
/etc/group
Information group definitions.
/etc/grub.conf The grub boot loader configuration file
Contains host names and their
corresponding IP addresses used for
/etc/hosts
name resolution whenever a DNS
server is unavailable
Contains a list of hosts allowed to
/etc/hosts.allow
access services on this computer.
Contains a list of hosts forbidden to
/etc/hosts.deny
access services on this computer.
Describes how the INIT process should
/etc/inittab
set up the system in various runlevels
Contains the pre-login message, often
overwritten by the /etc/rc.d/rc.local
/etc/issue
script in Red Hat and some other rpm-
based Linux distributions
Status information for currently
/etc/mtab
mounted devices and partitions
Contains information regarding
registered system users. Passwords are
/etc/passwd
typically kept in a shadow file for better
security.

/etc/printcap Holds printer setup information

Contains global defaults for the bash


/etc/profile
shell

A list of domain name servers (DNS)


/etc/resolv.conf
used by the local machine

This file contains a list of terminals


/etc/securetty
where root can login

Stores information about the last boot


/var/log/lastlog
process

Contains messages produced by the


/var/log/messages
syslog daemon during the boot process
Sample fstab file looks like this
#
# /etc/fstab
#
# <device> <mountpoint> <filesystemtype><options> <dump> <fsckorder>

/dev/hdb5 / ext2 defaults 1 1


/dev/hdb2 /home ext2 defaults 1 2

fstab file format explination


fstab consists of a number of lines (one for each filesystem) seperated into six fields.
Each field is seperated from the next by whitespace (spaces/tabs).

first field (/dev/hdc) is the physical device/remote filesystem which is to be described.

second field (/mnt/cdrom) specifies the mount point where the filesystem will be
mounted.

third field (iso9660) is the type of filesystem on the device from the first field.

fourth field (noauto,ro,user) is a (default) list of options which mount should use when
mounting the filesystem.

fifth field (0) is used by dump (a backup utility) to decide if a filesystem should be
backed up. If zero then dump will ignore that filesystem. The sixth field (0) is used by
fsck (the filesystem check utility) to determine the order in which filesystems should be
checked.
If zero then fsck won't check the filesystem.
Features of systemd

1. Clean, state forward and efficient design.


2. Simpler boot process.
3. Concurrent and parallel processing at boot.
4. Better API.
5. Simple Unit Syntax.
6. Ability to remove optional components.
7. Low memory footprints.
8. Improved technique to express dependencies.
9. Initialization instruction written in config file and not in shell script.
10.Make use of Unix Domain Socket.
11.Job Scheduling using systemd Calendar Timers.
12.Event Logging with journald.
13.Choice of logging System events with systemd as well as syslog.
14.Logs are stored in binary file.
15.systemd state can be preserved to be called later in future.
16.Track process using kernel’s cgroup and not PID.
17.Users login managed by systemd-logind.
18.Better integration with Gnome for interoperability.

systemd vs init
Yum & RPM

Both tools can perform an install, and RPM will even allow you to install multiple versions
simultaneously, but YUM will tell you that that package is already installed. So no YUM
will not allow you to install multiple versions.

As to yum update, this will react in one of two ways. If you tell it a package that you
want to update, it will attempt to do so, downloading all the necessary dependencies and
installing them too. If you run it without any package name, yum update will attempt to
update every package that's installed on your system.

The Red Hat Package Manager or RPM is the default package manager
for Linux distributions that use packages with the same name. Initially developed by Red
Hat, it eventually found widespread acceptance in a lot of Linux distributions. YUM stands
for Yellowdog Updater Modified and is a front end for Linux distributions that utilize the
RPM package format.

Sl
No. RPM YUM
If we want to install an application(Ex:
apache), rpm need to install all the
packages required for this application, Install an
these packages may vary from 1 rpm to application with single
several rpm’s depending on shared rpm command
1 packages. Ex: yum install httpd
YUM resolves
2 RPM package dependencies is bit tough dependencies with ease
YUM command can
install number of
applications in one
single command
Batch installation of applications is Ex: yum install httpd
3 possible with one command vsftpd
Does YUM install
updates of the existing
RPM can not handle updated software packages by using
4 installation automatically yum install upgrade
Can connect to on-line
repositories to get
latest software before
installing the
5 Can not connect to online repositories applications

Source File Installation


FIND – GREP – LOCATE

FIND is an utility for searching file and folders based on size, access time, modification time.

GREP Global Regular Expressions, it generally searches for a word in a file or in a list of files.

The basic difference is FIND is for searching files and directories at system level while GREP is for searching a
pattern inside a file.

We can perform certain functions also (like rm, cp, mv) by using exec option with find command.
FIND command is slow comparing to LOCATE.

Example :- find

Find / -name “passwd”


Output
/etc/passwd

Locate does not search the files on disk rather it searches for file paths in a database
The database is a file that contains information about the files and their path on your system.
The locate database file is located at:

/var/lib/mlocate/mlocate.db

there is another utility known as updatedb. When you execute updatedb, it scans the whole
system and updates the mlocate.db database file.
So one limitation of the ‘locate’ command is its dependency on the database which can be
updated by another utility ‘updatedb’. Hence, in order to get the latest and reliable results
from ‘locate’ command the database on which it works should be updated at regular intervals.

We can also configure the ‘updatedb’ utility as per our needs. This can be achieved by
updating the updatedb.conf. This is a configuration file that updatedb reads before updating
the database. updatedb.conf is located under /etc/ :

# cat /etc/updatedb.conf
LOCATE
Practical Examples of Locate Command
1. Search a File using locate
To search a particular file using locate, just do the following

$ locate sysctl.conf
/etc/sysctl.conf
/usr/share/man/man5/sysctl.conf.5.gz

The following command searches for httpd.conf in the entire system.

$ locate httpd.conf
/etc/httpd/conf/httpd.conf
/usr/local/apache2/conf/httpd.conf
/usr/local/apache2/conf/httpd.conf.bak

You can also use “locate -0” to display all the output in one line. For example:

$ locate -0 httpd.conf

2. Display only the Count


To get the count of number of matching entry, use locate -c as shown below.

$ locate -c httpd.conf
3

3. Use updatedb to Refresh mlocate Database


Suppose you took a backup of an existing file:

# cd /etc
# cp sysctl.conf sysctl.conf.orig

If you try to search for sysctl.conf using the ‘locate’ utility, you’ll not find the sysctl.conf.orig.

# locate sysctl.conf
/etc/sysctl.conf
/usr/share/man/man5/sysctl.conf.5.gz

The reason is that after the sysctl.conf.orig was create the database on which the locate utility works is not
updated. So lets update the database using the ‘updatedb’ command and execute locate again:

$ updatedb
updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db'

Please note that update db needs to be executed as root.

# updatedb

After updatedb, if you execute locate, you’ll find the sysctl.conf.orig file.

# locate sysctl.conf
/etc/sysctl.conf
/etc/sysctl.conf.orig
/usr/share/man/man5/sysctl.conf.5.gz

4. Change mlocate Database Location


The default database that locate utility reads is /var/lib/mlocate/mlocate.db, but if you wish to link the locate
command with some other database kept at some other location, use the -d option.
For example :

$ locate -d <new db path> <filename>

Note that the database path can also be taken from stdin and if an empty path is mentioned then the default data
base is picked.
5. Check File Existence
Now suppose the file sysctl.conf.orig that we created in example 3 above got deleted, and if you try to locate
sysctl.conf, it will still display the sysctl.conf.orig file.

# cd /etc
# rm sysctl.conf.orig

# locate sysctl.conf
/etc/sysctl.conf
/etc/sysctl.conf.orig
/usr/share/man/man5/sysctl.conf.5.gz

As you see from the above output, locate command shows sysctl.conf.orig even after the file was deleted. This
result is mis-leading.
Ofcourse, you can execute updatedb, and try locate again, which will show proper results.
Or, you can just use ‘locate -e’, which will display only the files that exists in the system, when you are executing
the locate command. i.e Even when the file exist in the mlocate.db, it will still verify to make sure the file is
physically present in the system before displaying it.
# locate -e sysctl.conf
/etc/sysctl.conf
/usr/share/man/man5/sysctl.conf.5.gz

6. Ignore Case in Locate Output


The locate command by default is configured to accept the file name in a case sensitive manner. In order to make
the results case insensitive, we can use the -i option :
In the following example, we created two files with both lowercase and uppercase.

# cd /tmp
# touch new.txt NEW.txt

# updatedb

If you use the locate command only with the lowercase, it will find only the lowercase file.

# locate new.txt
/tmp/new.txt

Use locate -i, which will ignore case, and look for both lowercase and uppercase file.

$ locate -i new.txt
/tmp/NEW.txt
/tmp/new.txt
/usr/share/doc/samba-common/WHATSNEW.txt.gz

7. Restrict the Locate Output


In the following example, locate command displayed several entries.

$ locate passwd
/etc/passwd
/etc/passwd-
/etc/dovecot/conf.d/auth-passwdfile.conf.ext
/etc/pam.d/passwd
/etc/security/opasswd
/etc/vsftpd/passwd
/lib64/security/pam_unix_passwd.so
/usr/bin/gpasswd
/usr/bin/htpasswd
/usr/bin/ldappasswd
/usr/bin/mksmbpasswd.sh
/usr/bin/passwd

If you want to display only certain number of records, use locate -l option and specify how many records you
want to see in the locate command output.
For example, the following displays only 5 records (Even when locate command finds several records..)

$ locate -l 5 passwd
/etc/passwd
/etc/passwd-
/etc/dovecot/conf.d/auth-passwdfile.conf.ext
/etc/pam.d/passwd
/etc/security/opasswd

Basic Commands for Finding Files with names


www.techmint.com
Find Files Using Name in Current Directory

# find . -name tecmint.txt

./tecmint.txt

Find Files Using Name and Ignoring Case

Find all the files whose name is tecmint.txt and contains both capital and small letters in /homedirectory.

# find /home -iname tecmint.txt

./tecmint.txt

./Tecmint.txt

Find Directories Using Name

Find all directories whose name is Tecmint in / directory.

# find / -type d -name Tecmint


/Tecmint

Find PHP Files Using Name

Find all php files whose name is tecmint.php in a current working directory.

# find . -type f -name tecmint.php

./tecmint.php

Find all php files in a directory.

# find . -type f -name "*.php"

./tecmint.php

./login.php

./index.php

Part II – Find Files Based on their Permissions

Find Files With 777 Permissions

Find all the files whose permissions are 777.

# find . -type f -perm 0777 -print

Find Files Without 777 Permissions

Find all the files without permission 777.

# find / -type f ! -perm 777

Find SGID Files with 644 Permissions

Find all the SGID bit files whose permissions set to 644.
# find / -perm 2644

Find Sticky Bit Files with 551 Permissions

Find all the Sticky Bit set files whose permission are 551.

# find / -perm 1551

Find SUID Files

# find / -perm /u=s

Find SGID Files

# find / -perm /g=s

Find Read Only Files

# find / -perm /u=r

Find Executable Files

# find / -perm /a=x

Find Files with 777 Permissions and Chmod to 644

# find / -type f -perm 0777 -print -exec chmod 644 {} \;


Find Directories with 777 Permissions and Chmod to 755

# find / -type d -perm 777 -print -exec chmod 755 {} \;

Find and remove single File

To find a single file called tecmint.txt and remove it.

# find . -type f -name "tecmint.txt" -exec rm -f {} \;

Find and remove Multiple File

To find and remove multiple files such as .mp3 or .txt, then use.

# find . -type f -name "*.txt" -exec rm -f {} \;

OR

# find . -type f -name "*.mp3" -exec rm -f {} \;

Find all Empty Files

To find all empty files under certain path.

# find /tmp -type f -empty

Find all Empty Directories

To file all empty directories under certain path.

# find /tmp -type d -empty

File all Hidden Files

To find all hidden files, use below command.

# find /tmp -type f -name ".*"

Part III – Search Files Based On Owners and Groups


Find Single File Based on User

To find all or single file called tecmint.txt under / root directory of owner root.

# find / -user root -name tecmint.txt

Find all Files Based on User

To find all files that belongs to user Tecmint under /home directory.

# find /home -user tecmint

Find all Files Based on Group

To find all files that belongs to group Developer under /home directory.

# find /home -group developer

Find Particular Files of User

To find all .txt files of user Tecmint under /home directory.

# find /home -user tecmint -iname "*.txt"

Part IV – Find Files and Directories Based on Date and Time

Find Last 50 Days Modified Files

To find all the files which are modified 50 days back.

# find / -mtime 50

Find Last 50 Days Accessed Files

To find all the files which are accessed 50 days back.

# find / -atime 50

Find Last 50-100 Days Modified Files

To find all the files which are modified more than 50 days back and less than 100 days.
# find / -mtime +50 –mtime -100

Find Changed Files in Last 1 Hour

To find all the files which are changed in last 1 hour.

# find / -cmin -60

Find Modified Files in Last 1 Hour

To find all the files which are modified in last 1 hour.

# find / -mmin -60

Find Accessed Files in Last 1 Hour

To find all the files which are accessed in last 1 hour.

# find / -amin -60

Part V – Find Files and Directories Based on Size

Find 50MB Files

To find all 50MB files, use.

# find / -size 50M

Find Size between 50MB – 100MB

To find all the files which are greater than 50MB and less than 100MB.

# find / -size +50M -size -100M

Find and Delete 100MB Files

To find all 100MB files and delete them using one single command.
# find / -size +100M -exec rm -rf {} \;

Find Specific Files and Delete

Find all .mp3 files with more than 10MB and delete them using one single command.

# find / -type f -name *.mp3 -size +10M -exec rm {} \;

GREP
Combination of find and grep :- Example

Find all .mp3 files only

# find . –name “*.mp3” | grep –I JayZ | -vi “remix”


remix”
In this example, we are using find to print all of the files with a *.mp3 extension, piping it to grep –i to
filter out and prints all files with the name “JayZ” and then another pipe to grep –vi which filters out and
does not print all filenames with the string (in any case) “remix”.

Search and Find Files

# dpkg – l | grep – i python


i python
Sample Output

ii python2.7 2.7.3-0ubuntu3.4 Interactive high-level object-oriented language (version 2.7)


ii python2.7-minimal 2.7.3-0ubuntu3.4 Minimal subset of the Python language (version 2.7)
ii python-openssl 0.12-1ubuntu2.1 Python wrapper around the OpenSSL library
ii python-pam 0.4.2-12.2ubuntu4 A Python interface to the PAM library

First, we ran dpkg –l, which lists installed *.deb packages on your system. Second, we piped that output to
grep –i python, which simple states “go to grep and filter out and return everything with ‘python’ in it.”
The –i option is there to ignore-case, as grep is case-sensitive. Using the –i option is a good habit of getting into,
unless of course you are trying to nail down a more specific search
NFS – NETWORK FILE SYSTEM

The Network File System (NFS) is a way of mounting Linux discs/directories over a network. An NFS server can
export one or more directories that can then be mounted on a remote Linux machine. Note, that if you need to
mount a Linux filesystem on a Windows machine, you need to use Samba/CIFS instead.

When to use NFS and when to use Samba

Server O/S Client O/S Use Samba or NFS?


Linux Linux NFS
Windows Linux Samba
Linux Windows Samba
Windows Windows Samba

Protocols used in NFS

All versions of NFS can use Transmission Control Protocol (TCP) running over an IP network, with NFSv4
requiring it. NFSv2 and NFSv3 can use the User Datagram Protocol (UDP) running over an IP network to
provide a stateless network connection between the client and server.

PORTS

Port 111 (TCP and UDP) and 2049 (TCP and UDP) for the NFS server.

NFS – system user - nfsnobody


NFS – package - nfs-utils
NFS – configuration file - /etc/exports
NFS - Kereberos /etc/sysconfig/nfs

NFS Main process - /usr/sbin/nfs-server


NFS Kerberos process - /usr/sbin/nfs-secure-server

Server Side

/etc/exports
/mounting dir. 172.25.x.0/24 (network ip) ro,sync,noroot_squash (options)

showmount –e

Client Side

/etc/fstab
hostname:/dirname /mounting dir nfs defaults 0 0
mount –a
df –Th
NFS Kerberos

Get the certificate from the link


wget –O /etc/krb5.keytab httpd://hostname/pub/keytabs/serverX.keytab

/etc/sysconfig/nfs

13th line “-V 4.2”


Inform the SELINUX that we are using V5

Vim /etc/exports
/mounting dir ipaddress(options, sec=krb5p)

systemctl restart/enable nfs-server


exportfs –r

CLIENT

lab nfskrb5.keytab

wget –O /etc/krb5.keytab http://classroom.example.com/pub/keytabs/desktopX.keytab

systemctl restart/enable nfs-secure


mkdir mountingpoint
/etc/fstab
hostname:/mounting dir /mounting point nfs defaults, sec=krb5p, v4.2 0 0
mount –a

Server

Mkdir /mountingdir/new
ls –ld
Chown ldapuserX:ldapuserX / mountingdir/new

ls –ld /mountingdir/new
ssh –X ldapuserX@client’s hostname
paswd :- Kerberos
#ldapuserX -> cd /mountingdir/new
Touch /mkdir
JOURNALCTL
https://www.loggly.com/ultimate-guide/using-journalctl/

journalctl is also a systemd utility. It’s used for querying and displaying messages from the journal. Since the journal
comprises of one or more binary files, journalctl is the standard way to read messages from it.

New Service in RHEL 7


Rsyslogd bSystemd-journald
Will create a file called log_txt will create a file journals

/run/log/journals
On each reboot journals will change
Journals are created in binary numbers
To Read Journals

Journalctl
Journalctl –b booting realated journals

Time Related Journals

journalctl --since "2015-06-26 23:15:00" --until "2015-06-26 23:20:00"


journalctl –since “1 hour ago”
journalctl --since "2 days ago"
journalctl --since "1 hour ago"
LVM (Logical Volume Manager)

 LVM is a method of allocating hard drive space into logical volumes that can be easily resized instead of partitions.
 For example if you are running out of disk space on your server, you can just add another disk and extend
the logical volumes.
 With LVM the hard drive or set of hard drives are allocated to one or more physical volumes.
 The physical volumes are combined into volume groups.
 Each volume group is divided into logical volumes which are assigned mount points and file system types such as
EXT3, EXT4

To configure LVM

1. Create three LVM partitions


2. Convert them as physical volumes
3. Create volume groups from physical volumes
4. Create logical volumes from volume groups and assign mount points.

Logical Volume Management 3 parts

a) Physical Volume (PV)


b) Volume Group (VG)
c) Logical Volume (LV)

Commands to Scan PV's, LV's and VG's


#lvscan
#pvscan
#vgscan

TO DISPLAY THE VG, LV, PVs

#vgdisplay
#pvdisplay
#lvdisplay

To check physical volume


#pvs

LINUX LVM – (8E)

To convert LVM partitions as physical volumes

#pvcreate /dev/sda<partition numbers>


#vgcreate <vgname> <partitions>

Lvcreate –L +[size]M /dev/vgname/lvname


To format logical volumes

Mkfs –t ext4 /dev/vgname/lvname

To extend size of logical volumes

#umnount <mount point>


#lvresize –L +[size]M /dev/<vgname>/<lvname>

To make filesystem for extended size

#resize2fs /dev/vgname/lvname
#lvreduce –L –[size]M /dev/vgname/lvname

To remove an LVM
#umount <mountpoint>
#lvremove /dev/vgname/lvname

To extend volume group


#vgextend <vgname> <partition name>

To reduce volume groups

#vgreduce <vgname> <partition name>

To remove volume group

#vgremove <vgname>

To remove physical volumes

#pvremove <partitions>
Pvremove /dev/sda{1,2,3}

SWAP (82)

Virtual Memory
Mkswap /dev/vdb_
Swapon –a
Swapoff –a
Swapof –s
FDISK Vs GDISK

fdisk

Max allowed primary partition 4


If we select Extended partition then only we can select logical partition .
We can create “n” number of logical partition with “n” sizes

Gdisk

We can divide the h/disk to 128 sectors.


All are primary partitions.
No logical or extended partition

OSI International Standards Organization

The main concept of OSI is that the process of communication between two endpoints in a telecommunication
network can be divided into seven distinct groups of related functions, or layers

Layer 7: The application layer: This is the layer at which communication partners are identified,
network capacity is assessed, and that creates a thing to send or opens the thing received.

Layer 6: The presentation layer: This layer is usually part of an operating system (OS) and converts
incoming and outgoing data from one presentation format to another.

Layer 5: The session layer. This layer sets up, coordinates and terminates conversations. Services
include authentication and reconnection after an interruption. On the Internet, Transmission Control
Protocol (TCP) and User Datagram Protocol (UDP) provide these services for most applications.
Layer 4: The transport layer. This layer manages packetization of data, then the delivery of the
packets, including checking for errors in the data once it arrives. On the Internet, TCP and UDP
provide these services for most applications as well.

Layer 3: The network layer. This layer handles the addressing and routing of the data (sending it in
the right direction to the right destination on outgoing transmissions and receiving incoming
transmissions at the packet level). IP is the network layer for the Internet.

Layer 2: The data-link layer. This layer sets up links across the physical network, putting packets into
network frames. This layer has two sub-layers, the Logical Link Control Layer and the Media Access
Control Layer. Ethernet is the main data link layer in use.

Layer 1: The physical layer. This layer conveys the bit stream through the network at the electrical,
optical or radio level. It provides the hardware means of sending and receiving data on a carrier
network.

TCP = Transmission control protocol Transport layer protocols.

Its is seen on 4th OS layer .

4th layer of OS is transport layer protocols.

UDP = User datagram protocol For transmitting data between one host to another host.

TCP UDP
Connection oriented (before transferring data it Connection less
setup the connection)
TCP is reliable Doesn’t provide any delivery guarantee

TCP provides delivery guarantee UDP doesn’t provide any ordering or sequencing
guarantee
TCP also guarantee order of message
Heavy weight Light weight

TCP is slow UDP is fast

Flow control (conjunction free) No option for flow control

Using TCP and UDP

TCP = HTTP, HTTPS , TELNET , FTP, and SMTP

UDP =DNS, DHCP, SNMP(sample network management protocol ) and TFTP


Public (external) IP addresses
A public (or external) IP address is the one that your ISP (Internet Service Provider) provides to
identify your home network to the outside world.

It is an IP address that is unique throughout the entire Internet.

Depending on your service, you might have an IP address that never changes (a fixed, or static IP
address).
But most ISPs provide an IP address that can change from time to time (a dynamic IP address). For the
vast majority of users, a dynamic IP address is fine.
When you're setting up your router, if your ISP issued you a static IP address, you enter it into your
router's settings. For a dynamic IP address, you specify DHCP in your router's network settings.
DHCP is Dynamic Host Control Protocol. It tells your router to accept whatever public IP address your
ISP issues.

Private (internal) IP addresses

Just as your network's public IP address is issued by your ISP, your router issues private (or internal) IP
addresses to each network device inside your network.
This provides unique identification for devices that are within your home network, such as your
computer, your printer and so on.
Similar to the arrangement with public IP addresses, each device on your network has its network
configuration settings on DHCP, so it can accept the unique private IP address that your router issues it.
These private IP addresses never leave your network, just as your public IP address is never used inside
your network. The router controls all the network traffic, both within your home network and outside of
it, to the Internet. It is the router's job to make sure that data flows to and from all the correct places.

TAR - Tape Archive


Utility is used to copy some directories or files under a single directory & that directory is
called tarball /tarfile

The tar program is used to create, maintain, modify, and extract files that
are archived in the tar format.

Compression Tool

Gzip

Bzip2

Xz

Gzip – fastest compression tool. Default compression tool in linux


Bzip2 – Compression ratio is high

XZ – slowest compression tool for HD Video/audio images

Syntax

TAR

tar –cf filename.tar file1 file2 //It will create a tar file

tar –xf filename.tar // Untar the tarred file

tar –tf filename.tar // It will display the files which are tar red.

du –h filename/dir.name // to know the directory and sub dir size

Tar
Tar –cf filename.tar file1 file2 Tar –cf filename.tar /dir1 /dir2 Creating .tar
Tar –xf filename.tar Extracting .tar
ZIP COMPRESSION TECHNIQUES
Gzip Bzip2 Xz
.gz .bz2 .xz

tar –czf tarfilename.tar.gz /dir1 /dir2 tar cjf filename.tar.bz2 /dir1/dir2 tar –cJf filename.tar.xz /dir1/dir2

tar xzf tarfilename.tar.gz Tar xjf tarfilename.tar.gz Tar xJf filename.tar.xz

Extract all the tar files in the current working directory

ISCSI

iSCSI (Internet Small Computer System Interface)

iSCSI, which stands for Internet Small Computer System Interface, works on top of the
Transport Control Protocol (TCP) and allows the SCSI command to be sent end-to-end
over local-area networks (LANs), wide-area networks (WANs) or
the Internet. IBM developed iSCSI as a proof of concept in 1998

How ISCSI works


iSCSI works by transporting block-level data between an iSCSI initiator on a server and
an iSCSI target on a storage device.

LUN – Logical Unit Number

A LUN can represent a hard disk drive (HDD), a portion of an HDD or even a full
storage array
If a LUN is provided to a particular m/ch then it should not be given to any other machines

ISCSI Server - Target

ISCSI CLIENT – Initiator

Backstores :- To store where data in the back end (hdd partition)

IQN- ISCSI QUALIFIED NAME – Every iSCSI node must have a node name. Node names
typically take the iSCSI Qualified Name (IQN) format. The IQN-type designator is a logical
name that is not linked to an IP address.
The following is an example format:
iqn.yyyy-mm.backward-naming-authority:unique-device-name

iqn.2014-06.com.example:server

this name is given to the partition, at this time tpg1 is created

PORTALS

Server’s IP address and iscsi port – 3260/tcp

ACL

Clients iqn name


Linux Directory Structure

1. /bin : All the executable binary programs (file) required during booting, repairing, files required to run into
single-user-mode, and other important, basic commands viz., cat, du, df, tar, rpm, wc, history, etc.
2. /boot : Holds important files during boot-up process, including Linux Kernel.
3. /dev : Contains device files for all the hardware devices on the machine e.g., cdrom, cpu, etc
4. /etc : Contains Application’s configuration files, startup, shutdown, start, stop script for every individual
program.
5. /home : Home directory of the users. Every time a new user is created, a directory in the name of user is
created within home directory which contains other directories like Desktop, Downloads, Documents, etc.
6. /lib : The Lib directory contains kernel modules and shared library images required to boot the system and
run commands in root file system.
7. /lost+found : This Directory is installed during installation of Linux, useful for recovering files which may
be broken due to unexpected shut-down.
8. /media : Temporary mount directory is created for removable devices viz., media/cdrom.
9. /mnt : Temporary mount directory for mounting file system.
10. /opt : Optional is abbreviated as opt. Contains third party application software. Viz., Java, etc.
11. /proc : A virtual and pseudo file-system which contains information about running process with a
particular Process-id aka pid.
12. /root : This is the home directory of root user and should never be confused with ‘/‘
13. /run : This directory is the only clean solution for early-runtime-dir problem.
14. /sbin : Contains binary executable programs, required by System Administrator, for Maintenance.
Viz., iptables, fdisk, ifconfig, swapon, reboot, etc.
15. /srv : Service is abbreviated as ‘srv‘. This directory contains server specific and service related files.
16. /sys : Modern Linux distributions include a /sys directory as a virtual filesystem, which stores and allows
modification of the devices connected to the system.
17. /tmp :System’s Temporary Directory, Accessible by users and root. Stores temporary files
for user and system, till next boot.
18. /usr : Contains executable binaries, documentation, source code, libraries for second level program.
19. /var : Stands for variable. The contents of this file is expected to grow. This directory
contains log, lock, spool, mail and temp files.
IP CHAINS IP TABLES FIREWALLD
RHEL 5 RHEL 6 RHEL 7
Does not support NAT n/w area Customized firewall not possible To overcome these problems zones
transmission introduced in RHEL 7
With the private i/p its not possible to @ a time FTP/HTTP is only working, These are 9 Zones are in RHEL 7.
access the internet. So NAT (n/w if we used to start a new process : Switch the zones for our convenient
area transmission) is used, convert need to remove the old rule & rewrite purpose.
private i/p to public i/p the rules
Application – sundry – Firewall
Default zone - public

9 Zones in RHEL 7

 drop: The lowest level of trust. All incoming connections are dropped without reply and only outgoing
connections are possible.
 block: Similar to the above, but instead of simply dropping connections, incoming requests are rejected with
an icmp-host-prohibited or icmp6-adm-prohibited message.

 public: Represents public, untrusted networks. You don't trust other computers but may allow selected incoming
connections on a case-by-case basis.
 external: External networks in the event that you are using the firewall as your gateway. It is configured for NAT
masquerading so that your internal network remains private but reachable.
 internal: The other side of the external zone, used for the internal portion of a gateway. The computers are fairly
trustworthy and some additional services are available.
 dmz: Used for computers located in a DMZ (isolated computers that will not have access to the rest of your
network). Only certain incoming connections are allowed.
 work: Used for work machines. Trust most of the computers in the network. A few more services might be
allowed.
 home: A home environment. It generally implies that you trust most of the other computers and that a few more
services will be accepted.
 trusted: Trust all of the machines in the network. The most open of the available options and should be used
sparingly.

To List The Zones

Firewall-cmd –get-zones
Firewall-cmd –get-default-zone

Firewall-cmd –list-services
Firewall-cmd –add-service=http –permanent
Firewall-cmd –reload
Firewall-cmd –add/remove-port=25/tcp –permanent
Firewall-cmd –list-ports
NTP – Network Time Protocol

Vim /etc/chrony.conf
Timedatectl set-ntp true
Systemctl restart/enable chronyd.service
Timedatectl

Cron Job

Cron jobs can run as often as every minute. However, the utility assumes that the system is running continuously
and if the system is not on at the time when a job is scheduled, the job is not executed.

To install Cron you need to install the cronie package with Cron.

Package name :- cronie

Scheduling Jobs

Normal users can use the crontab command to manage their jobs. This command can be called in four different
ways.

Crontab -l List the jobs for the current user.

Crontab -r Remove all jobs for the current user.

Crontab -e Edit jobs for the current user.

Crontab <filename> Remove all jobs, and replace with the jobs read from <filename>. If no files are specified,
stdin will be used.

Starting and Stopping the Cron Service

To determine if the service is running, use the command service crond status.

To run the crond service in the current session, type the following at a shell prompt as root:

servicecrondstart

To configure the service to be automatically started at boot time, use the following command:

chkconfigcrondon

To stop the crond service, type the following at a shell prompt as root
servicecrondstop

To disable starting the service at boot time, use the following command:

chkconfigcrondoff

To restart the crond service, type the following at a shell prompt:

servicecrondrestart

System cron jobs

Apart from user cron jobs there are also system cron jobs. System cron jobs are not defined using crontab commands
but are instead configured in a set of configuration files. The main difference in these configuration files is an extra
field located between the day-of-week field and the command field, specifying under which user a job should be run.

Vim /etc/chrony.conf

* * * * * username command to be executed

Min hr day of month month day of week

0-59 0-23 1-31 1-12 0-6

* * * * * /bin/echo “hi” >> /root/cron

Will print the “hi” message in the cron file in the root

Cat /root/cron

Vim /root/cron // to view the message


Process- top
Security linux features
LDAP
SSH keygen extension
Source file installation – make file installation
LDAP

Potrebbero piacerti anche