Official CompTIA Linux+ Student Guide
Official CompTIA Linux+ Student Guide
CompTIA
Linux+
Student Guide
(Exam XK0-005)
Acknowledgments
Notices
Disclaimer
While CompTIA, Inc. takes care to ensure the accuracy and quality of these materials, we cannot guarantee their accuracy,
and all materials are provided without any warranty whatsoever, including, but not limited to, the implied warranties of
merchantability or fitness for a particular purpose. The use of screenshots, photographs of another entity’s products, or
another entity’s product name or service in this book is for editorial purposes only. No such use should be construed to imply
sponsorship or endorsement of the book by nor any affiliation of such entity with CompTIA. This courseware may contain links
to sites on the Internet that are owned and operated by third parties (the “External Sites”). CompTIA is not responsible for
the availability of, or the content located on or through, any External Site. Please contact CompTIA if you have any concerns
regarding such links or External Sites.
Trademark Notice
CompTIA®, Linux+®, and the CompTIA logo are registered trademarks of CompTIA, Inc., in the U.S. and other countries.
All other product and service names used may be common law or registered trademarks of their respective proprietors.
Copyright Notice
Copyright © 2022 CompTIA, Inc. All rights reserved. Screenshots used for illustrative purposes are the property of the software
proprietor. Except as permitted under the Copyright Act of 1976, no part of this publication may be reproduced or distributed
in any form or by any means, or stored in a database or retrieval system, without the prior written permission of CompTIA,
3500 Lacey Road, Suite 100, Downers Grove, IL 60515-5439.
This book conveys no rights in the software or other products about which it was written; all use or licensing of such software
or other products is the responsibility of the user according to terms and conditions of the owner. If you believe that this
book, related materials, or any other CompTIA materials are being reproduced or transmitted without permission, please call
1-866-835-8020 or visit https://help.comptia.org.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Table of Contents
Table of Contents
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Table of Contents
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Solutions......................................................................................................................... S-1
Glossary...........................................................................................................................G-1
Index................................................................................................................................. I-1
Table of Contents
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Course Description
Course Objectives
This course can benefit you in two ways. If you intend to pass the CompTIA Linux+
(Exam XK0-005) certification examination, this course can be a significant part of
your preparation. But certification is not the only key to professional success in
the field of systems administration. Today’s job market demands individuals with
demonstrable skills, and the information and activities in this course can help you
build your sysadmin skill set so that you can confidently perform your duties in any
intermediate-level Linux systems administration role.
On course completion, you will be able to:
• Configure, manage, and troubleshoot Linux systems.
Target Student
The Official CompTIA Linux+ (Exam XK0-005) is the primary course you will need to
take if your job responsibilities include Linux system administration, installation,
and security within your organization. You can take this course to prepare for the
CompTIA Linux+ (Exam XK0-005) certification examination.
Prerequisites
To ensure your success in this course, you should have at least 12 months of
hands-on experience working with Linux servers. CompTIA A+, Network+, and
Server+ certifications, or the equivalent knowledge, are strongly recommended.
The prerequisites for this course might differ significantly from the prerequisites for
the CompTIA certification exams. For the most up-to-date information about the exam
prerequisites, complete the form on this page: www.comptia.org/training/resources/
exam-objectives.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
As You Learn
At the top level, this course is divided into Lessons, with each representing an area
of competency within the target job roles. Each Lesson is composed of a number of
topics. A Topic contains subjects that are related to a discrete job task and mapped
to objectives and content examples in the CompTIA exam objectives document.
Rather than follow the exam domains and objectives sequence, lessons and topics
are arranged in order of increasing proficiency. Each topic is intended to be studied
within a short period (typically 30 minutes at most). Each topic is concluded by one
or more activities, designed to help you apply your understanding of the study
notes to practical scenarios and tasks.
In addition to the study content in the lessons, there is a glossary of the terms and
concepts used throughout the course. There is also an index to assist in locating
particular terminology, concepts, technologies, and tasks within the Lesson and
topic content.
In many electronic versions of the book, you can click links on key words in the topic
content to move to the associated glossary definition and on page references in the
index to move to that term in the content. To return to the previous location in the
document after clicking a link, use the appropriate functionality in your eBook viewing
software.
As You Review
Any method of instruction is only as effective as the time and effort you, the
student, are willing to invest in it. In addition, some of the information that you
learn in class may not be important to you immediately, but it may become
important later. For this reason, we encourage you to spend some time reviewing
the content of the course after your time in the classroom.
Following the lesson content, you will find a table mapping the lessons and topics to
the exam domains, objectives, and content examples. You can use this as a checklist
as you prepare to take the exam and review any content that you are uncertain
about.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
As a Reference
The organization and layout of this book make it an easy-to-use resource for future
reference. Guidelines can be used during class and as after-class references when
you’re back on the job and need to refresh your understanding. When taking
advantage of the glossary, index, and table of contents, you can use this book as a
first source of definitions, background information, and summaries.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
Working with Linux begins with an understanding of licensing and the operating
system’s history. The open-source nature of Linux has resulted in many different
distributions, so it’s important to understand how distributions differ from each
other. Linux servers are primarily managed from the command line, using shells
such as Bash. Bash enforces a particular syntax, or way of structuring commands.
In addition, Linux holds its configurations in text files, so it’s critical that sysadmins
can edit these files to manage system settings. Man pages are available as
quick reference documents to help administrators recall the function of specific
commands and any available options.
Misconfigurations or physical failures may provide troubleshooting opportunities,
so sysadmins should follow a standard methodology to help narrow the scope of
problems, solve the root cause of the issue, and manage documentation related to
configuration issues.
Lesson Objectives
In this Lesson, you will:
• Identify Linux characteristics.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 1A
Identify Linux Characteristics
2
Some examples of open-source licenses include the Apache License 2.0, the GNU
General Public License, and Mozilla's Public License. While the exam does not focus on
the specifics of these licenses, they are a good sample of the open-source requirements
and permissions.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Of the three primary operating systems in the marketplace today (Linux, macOS,
and Windows), two can trace their roots back to Unix. The macOS kernel evolved
from a Unix flavor named BSD and shares many of the same standards and some
software as Linux. However, Apple’s OS is not FOSS. Microsoft Windows also uses a
proprietary kernel with a more restrictive licensing method.
The timeline of early OS development. Unix, released in 1969, directly generated the Linux and the
macOS systems.
• Learning curve: Some find that Linux has a steeper learning curve than
Windows or macOS does.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Software management, including more differences between the Red Hat method and the
Debian method, are discussed in a later section.
• Linux Mint
• Debian
• openSUSE
After the release of Linux in 1991, the two major branches, Debian and Red Hat, followed quickly
and generated hundreds of distros.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
• Name resolution: Hosts Domain Name System (DNS) name resolution services.
Most commands are consistent across distributions. A few commands, such as those
for software management, may be specific to one group of distributions or another. For
example, Red Hat Linux uses the rpm command to manage software, while Debian
Linux uses apt.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
• Scriptable: CLI commands can be written into a text file, which the system then
reads and executes in a consistent, efficient, repeatable, and scheduled manner.
CLI disadvantages:
• Learning curve: Remembering many different commands and their related
options is difficult.
• Inconsistent: Many commands differ from each other in small but distinctive
ways, making it difficult to recall exactly how to use them.
Common CLIs
Command-line interfaces are available in Linux, Windows, and macOS. Users type
commands using a specific syntax, and the system processes the commands. At
first, such input may seem intimidating or difficult, but CLI environments get easier
with use. These environments are usually faster and offer automation options that
are not available in GUIs.
Several sample commands and their output, including whoami, pwd, and date.
Shells provide the CLI. Each shell has its own syntax, or way of structuring
commands.
Common Linux shells:
• Bash: Default Linux shell
• zsh: Z shell
The Bash shell is covered in more detail later in this Lesson. It is the only shell covered
by the CompTIA Linux+ exam objectives.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Common GUIs
Just as there are many different Linux distributions, there are also many different
Linux graphical environments. Windows and macOS users have one GUI available
to them—whatever graphical environment Microsoft and Apple choose to provide.
Linux users have the freedom to install zero, one, or many GUI environments and
switch between them.
These GUIs are usually distinguished by two characteristics: user-friendly interface
and performance. Some users like the look and feel of a particular GUI over others.
In addition, some GUIs consume more processor time and memory than others do.
Luckily, many options are available in the Linux world.
Common GUI environments include GNOME, KDE Plasma, Cinnamon, and MATE.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
3
Linux Characteristics
Answer the following questions:
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 1B
Understand Bash Interaction
with Linux
5
Command Shells
The CLI is provided by software called a shell. The shell accepts user input,
processes the input for syntax, and provides output back to the user. The default
shell for most Linux distributions is Bash, and this is the shell that sysadmins
should be prepared to work with.
Other common Linux shells include ksh, or KornShell, which is common among
Unix servers; Zsh, or Z Shell, with quite powerful scripting capabilities; and Fish, or
friendly interactive shell, an interface that provides a user-friendly experience and
web-based configurations.
By way of comparison, Windows Server also uses shells: the traditional, DOS-like
cmd.exe shell and Microsoft PowerShell. The current (at the time of this writing)
default shell for macOS is the Zsh.
Bash is the Linux default and the only shell to concern yourself with for CompTIA Linux+.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
• Option: A command modifier that slightly changes the way a command is processed.
• Argument: The object on which the command acts. For example, in a command
to delete a file, the argument is the name of the file to be deleted.
There are two basic forms, normal command and command-subcommand, to this
syntax.
As an example, here are several ways to use the list (ls) command with options
and arguments.
Most Bash error messages are descriptive, so be careful to read the error message to
understand what went wrong.
Command-Subcommand Syntax
Many Linux commands support subcommands to specify particular information
that the sysadmin needs. These commands rely on a different syntax from the basic
format in normal command syntax. The sysadmin enters the primary command,
then follows it with a space and a subcommand, and then a space and argument.
The ip command uses this format.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Example with
Command Purpose Options Result
ls List the contents of the ls /tmp List the contents of
current directory the /tmp directory
touch Create a new empty file touch Create a new file
or update the timestamp newfile.txt named newfile.txt
on an existing file
cd Change from one cd /etc Changes the
directory to another current directory
to /etc
cat Display the contents of a cat data.txt Display the
text file on the screen contents of the
data.txt file
less Display the contents of a less Display the
file in windows that fit on data.txt contents of the
the screen data.txt file screen
at a time when
the file would not
normally fit on one
screen
tree Display the directory tree /etc Display the
structure in a tree subdirectories and
format files in the /etc
directory in a tree
structure
shutdown Shut down the system shutdown Restart the system
-r now immediately
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Two common commands do not use options to generate an output. Use whoami
to display the current user, and use pwd to display the present working directory.
Command line interface showing the output of ls, pwd, whoami, and touch.
The number of Bash commands can be overwhelming. Start by using a few commands
at a time, and make them a habit. The longer you work with Linux, the more
comfortable you’ll become with the commands.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Typing the history command displays the contents of the history file. Each entry in
the file is numbered. Type ! and the command number executes that command.
Some shells cache command history in memory. When the system is rebooted, the
commands are no longer available. Bash writes the command history to a file stored on
the hard disk. The commands are available even after multiple reboots.
• Use command history instead of rewriting long commands: When you make
a typographical error in a command or file name, do not manually retype the
entire line. Repeat the line with the mistake by hitting the Up Arrow key one
time, and then use the Left and Right Arrow keys to move to the mistake so that
you can correct it.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
• Clear the screen: Enter the clear command to clear the CLI of all text. This
is useful when you’re starting a new task and want to eliminate any distracting
information from past command entries.
Vim
Vim is very powerful and complex. It uses three different modes, where each
mode maps keyboard keys to different functions. For example, in Insert mode
the keyboard acts as normal, inserting text into the file. If you’re in Insert mode
and type “abc,” those three characters appear in the file’s content. In Command
mode, pressing a key on the keyboard issues commands to Vim instead of entering
text in the file. Selecting the i key tells Vim to switch from Command mode to
Insert mode. The third mode is Execute. This mode is entered by selecting the
colon character, : , and it provides a command prompt to Vim where additional
commands can be issued. For example, :wq places Vim in Execute mode, writes
the files to the disk (save), and then quits Vim (q).
The many modes and commands can make Vim a little confusing. Strive to
understand four basic functions: create/open, edit, save, close.
For efficiency, type :wq to combine the save and close options.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The Vim editor. Note the INSERT flag in the lower left corner.
Nano
Nano is a popular and common alternative to Vim. It’s simpler but less powerful.
However, in many cases sysadmins don't need the power offered by Vim, which
makes Nano a useful choice for basic editing functions.
Nano does not have modes. Pressing keys on the keyboard inserts text into the
file, just as expected with most editors. To save and close the file, use keyboard
shortcuts using the Ctrl meta key. For example, Ctrl+O saves the file, and
Ctrl+X exits the file. You may have used similar keyboard shortcuts in other
applications.
As with Vim, it’s critical that you are capable of using Nano to create or open, edit,
save, and close files.
• Type nano filename to create a new empty file or open an existing file with
Nano.
• To edit the file, simply begin typing. Use the arrow keys to move the cursor.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Some Linux distributions install both Vim and Nano by default, while others will
include only one or the other. It is essential for you to be able to use both editors at
a very basic level (open, edit, save, close) so that you are capable of editing files with
whichever tool is available.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Elevate privileges from standard user to root, and confirm the change with
the whoami command.
The problem with the su - root command is that it grants all administrative
privileges to the escalating user, assuming the user knows the root password.
In other words, the user is either a non-privileged account with almost no
administrative authority or the full root user account with all possible administrative
authoring—and nothing in between. Sometimes, administrators want to delegate
specific, defined activities that require root authority, but only those particular
activities.
Sysadmins can edit a file named /etc/sudoers to delegate specific tasks to
individual users and groups. The specified identity may exercise that task as if
they are root, but nothing else. This is a much safer alternative than giving full
root privileges to individuals who may not be fully qualified to run the system. This
delegation concept is critical to good security.
To accomplish a delegated task, simply precede the command with sudo. You will
usually be prompted for your password and given a warning to be careful on the
system. The command then executes.
As a security measure, some distributions disable the root user account and force
the use of sudo on specific user accounts.
Privilege escalation using su and sudo are covered in more detail in a later Lesson.
A summary is provided here in case it’s needed for hands-on activities.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
• /home/username: Each standard user has a specific and private directory used
to store personal files, profile settings, and other data. These user directories are
subdirectories of /home.
• /etc: Most system configuration files are stored in the /etc directory.
• /var/log: Log files for the system and applications are stored in the /var/log directory.
There are many other standard directories, and they are covered in a later Lesson.
If the system boots to the GUI, a login prompt is displayed that may show available user
accounts. A password is entered, and then the user is authenticated. Profile settings
related to the GUI—such as desktop backgrounds and menu items—are then loaded.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Interact with Linux
6
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 1C
Use Help in Linux
4
Linux Documentation
There are several ways of getting help in Linux. The most common are the manual
pages, referred to as “man pages” for short. There is built-in documentation for the
system and some applications, too. Many online resources also exist, and they are
often the most up to date.
Because there are so many commands, and because each command has so many
options, it’s very common to use the man pages as a quick reference for displaying
the available options.
Manual Pages
It’s common for new Linux users to ask for help and then be asked, “Did you check
the man pages?” That’s because man pages are the primary reference for standard
Linux commands. The man pages provide syntax information and usage examples.
Perhaps most important, the available options are displayed. Because of the
number of options for each command, and the fact that many options differ from
command to command, the man pages provide an essential quick reference.
The syntax for using man pages is man {command}.
For example, to display help for the ls command, type man ls.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Note that the numbers in this list are man page section numbers, not merely
part of the list. In other words, “System calls” is in Section 2 of the man pages
documentation, not just the second item in this grouping.
Section eight is probably the most commonly used section for administrators.
Built-In Documentation
Most commands include help references. Add the -h option, or help after the
command to display this reference material.
The whatis command provides a brief description of the specified command.
The syntax for whatis is whatis {command}.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Online Documentation
There is a great deal of information available online that covers Linux
administration, applications, security configurations, and network services. This
documentation may be provided by vendors, community groups, online forums,
article repositories, and other sites.
• Linux distribution vendors: Vendors such as Red Hat and Ubuntu have large
repositories of reference information.
• Linux application vendors: Vendors for products such as Apache web server,
Vim, and Firefox provide many references for their applications.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Help in Linux
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 1D
Identify the Linux Troubleshooting
Methodology
3
Troubleshooting Methodology
A formalized and consistent troubleshooting methodology can make identifying
issues and discovering fixes more efficient. While the steps can vary depending
on the actual issue and components involved, there are several universal
troubleshooting steps.
The following list represents the basic steps in a troubleshooting methodology:
• Identify the problem.
Throughout the process you will find it helpful to document findings, actions, and
outcomes of the various steps.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
In Linux, the log file service is named "rsyslog." Services are covered in Lesson 9.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
down to replace hardware, or if data has been lost due to a HDD failure, the end
users must be notified. The plan of action defines the steps to be taken. These steps
should be defined ahead of time rather than created during the implementation of
the solution. It is useful to provide the impacted users with an expected duration of
the outage.
Some service desk management software requires the use of tickets. Such software may
require that troubleshooting documentation be entered before the ticket can be closed.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Troubleshoot in Linux
4
1. A user contacts you to find out why they cannot access a directory. Using
the troubleshooting methodology, how would you narrow the scope of
the problem?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 1
Summary
4
Guidelines
These best practices and guidelines are provided for your use as revision tools or as
quick references in your job role.
• FOSS: Recognize and describe free and open-source software, including
advantages and disadvantages.
• GPL: Understand how the GPL influences the development and availability of the
Linux OS.
• Use Vim and Nano to open, edit, save, and close files.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
Modern operating systems require users to prove their identity. This identification
process, referred to as authentication, provides access to major functions. First, the
user’s identity can be used to control access to resources via permissions and other
rules. Second, the user’s environment can be customized to fit that individual’s work
style and habits.
The first task is to understand user account management, including its related
configuration files and commands. However, managing individual users can be
inefficient, so users are often placed into groups for simplicity. Group management
involves a different set of configuration files and commands. Next, administrators
should log on to the server with non-privileged accounts and then elevate privileges
only when necessary. The administration of privilege elevation and its related
commands is covered in the third Topic. Finally, this lesson will cover applying
configuration files and commands in troubleshooting and security auditing.
Lesson Objectives
In this lesson, you will:
• Manage user accounts.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 2A
Manage User Accounts
2
Sysadmins are responsible for, among other things, managing user accounts. These
accounts customize the user environment and provide access to resources. It’s
difficult to administer user accounts effectively without a solid understanding of the
files and tools used to manage accounts. This Topic covers user configuration files
and management commands.
Field Content
User Name The name the user logs into the system with
Password User password represented as an x; the actual password is
stored elsewhere
User ID Unique number representing the user to the system
Group ID Unique number representing the user’s primary group
Comment Typically displays the user’s full name
Home directory Absolute path to the user’s home directory
Login shell Absolute path to the user’s default shell (usually /bin/bash)
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The /etc/shadow file. Note the long string representing the hashed password.
Field Content
User name The name the user logs into the system
with
Password Hash value of the user’s password
Days since last password change Number of days since the last password
change; counted from January 1, 1970
Days before password may be Minimum changeable period, typically
changed set at 1 day
Days before password must be Maximum number of days since the last
changed password change before the password
must be changed again; a value of
99999 means the password never
needs to be changed, but often set at
90 days
Days until the user is warned to Days before the date the password
change password must be changed that the warning is
issued, often set to 7 days
Days after password expires that Number of days after the password
the account is disabled expires until the account is disabled;
should be immediate
Days until account expires Number of days until the account
expires and cannot be used
Unused field Reserved for potential future use
It may seem odd that account information is distributed across two files and that
specifically password information is stored in a different file than user accounts.
Passwords were originally stored in the second field of the /etc/passwd file.
This file, however, is “world-readable,” meaning that all users have read permissions
to the file. The password itself, or the encrypted version of it, could be viewed by all
users. To increase security, the password was moved to the /etc/shadow file,
which only the root user (administrator) can access.
The default shell setting, defined in the last field of the /etc/passwd file,
specifies which shell will launch when the user logs in. There are many different
shells, and some users may prefer one over another. Bash is the default shell and
therefore the most common.
For example, User1 has experience with several Unix flavors and is already familiar
with the Korn shell (ksh). The sysadmin may install ksh and set it as the default shell
for this user. The last field of the User1 line in /etc/passwd will read /bin/
ksh. User2, however, might be more comfortable with the Bash shell. In that case,
the sysadmin leaves the default shell value as /bin/bash.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The tilde character (~) represents the current user's home directory. For example, the
~ character means the same as /home/user1 (assuming user1 is the currently
logged-in user).
The system-wide files process first, and then the user-specific files are executed.
The user-specific configuration files take precedence over system files, allowing
users to customize their environments to suit their needs.
Finally, a sysadmin can store files in the /etc/skel directory and have those files
copy automatically to the home directory of any new user. This feature is useful for
pre-populating configuration files such as .bashrc with suggested settings for users
or for distributing policy documents all users should have access to.
The user management lifecycle, including adding, modifying, and deleting a user.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The default values found in the /etc/login.defs file can be overridden with
various options, providing administrators with flexibility. Common options include
the comment field or default shell settings.
Some common options for the useradd command include:
Observe that the comment value is enclosed in double quotes. The quotes cause Bash to
recognize the enclosed information as a single object. If the quotes did not exist, the first
name would be seen as a separate item from the last name, resulting in an error.
Set a Password
The useradd command creates the user but does not set a password. Most
Linux systems will not allow a user to log in with a blank password, so while the
account exists, it is not yet usable. The passwd command sets passwords for user
accounts.
The syntax for using passwd is passwd [username]
Helpdesk Ticket #01982
Submitted by: Department: Assigned to: Date Opened:
Kai Garcia Engineering you 2024-03-08
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
You are prompted to enter a new password twice. Use the passwd command to
configure a password for a new account as well as to reset a forgotten password for
an existing user.
The adduser command walks the admin through each field of the user account information.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Modify these existing user accounts by using the usermod command. In these
two cases, the commands will look like this:
# usermod -e 2025-12-31 alee
# usermod -c "Joseph Deng" jdeng
Helpdesk Ticket #01984
Submitted by: Department: Assigned to: Date Opened:
Kai Garcia Engineering you 2024-04-01
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The userdel command removes existing users from the system. By default, the
command does not remove the user’s home directory. This is important, as the user
data may need to be assigned to other users. However, the -r option can be added
to the command to remove the account and its associated home directory.
The syntax for using userdel is userdel {user-name}
For example, to delete the Alex Lee account, type userdel alee
Neither the usermod nor userdel commands will modify users if the accounts
have running processes.
The deluser command removes user accounts from the system on some
distributions.
Deleted user accounts cannot be recovered. They can be recreated, but they will be a
different identity (unless created with the same UID value). It is often better to disable a
user account rather than delete it.
Verification
When you use the useradd, usermod, or userdel commands to manage
users, the result of the command is recorded, even if nothing is displayed on
the screen. For example, when you create a user, there is no message displayed.
When something goes wrong, an error is displayed explaining the issue. While the
messages are self-explanatory, such as “Username already in use” informing you
that the username you tried to set exists already, the results are actually labeled
using an exit code number. Display the results of the most recent command by
typing the following:
# echo $?
0
A zero indicates success; any other value indicates an error of some sort.
Some examples of those exit codes are provided here.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The error values differ slightly for the usermod and userdel commands.
All Executables have exit codes. Use the echo $? command to display the exit status
of the most recent command.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
User Account Management
3
1. Why are user passwords stored in the /etc/shadow file and not the
/etc/passwd file?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 2B
Manage Group Accounts
4
Like the management of user accounts in the previous section, managing groups
requires an understanding of the configuration files and commands used to govern
groups. Groups simplify the process of granting access to resources to multiple
users.
Output of the tail /etc/group command, showing the most recently added groups.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
As the help desk tech, you run the following two commands to complete the service
request:
# groupmod -n publicity marketing
# groupadd sales
The -n option changes the group name.
Deleting a group does not delete the user accounts that are a member of that
group. A group is a separate object from the user.
Note that you cannot remove the primary group of an existing user. You must
remove the user account first by using the userdel command.
Some distributions rely on addgroup and delgroup to manage groups.
These commands are more interactive than groupadd and groupdel. If the
commands are not installed on the system, they can be added.
Be sure to search for files or other resources that may be associated with the group
before deleting it. Configure another group with access to those resources before
deleting the original group.
Verification
Group management commands are usually straightforward, but things can go
wrong. The messages printed on the screen should be plenty to guide you toward a
solution. However, you can also display the exit values by using echo $?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Group Account Management
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 2C
Configure Privilege Escalation
5
One should avoid logging on to a system as the root user. The root user’s broad
privileges are unnecessary for most day-to-day user tasks, such as managing data
or browsing the Internet. If the standard practice is to log on with a non-privileged
standard account, then what about situations where administrative privileges are
required? Instead of logging off and then logging back on as root, Linux provides
ways of switching identities or running commands as a different user.
This section introduces privilege escalation and then covers tools such as su,
sudo, and pkexec. Proper use of privilege escalation helps to maintain the
security of the system and satisfy security policy requirements.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Those distributions that do not disable the root user still suggest that sysadmins log
in with non-privileged accounts and then elevate privileges by using su.
Avoiding signing in as the root user is an example of the principle of least privilege. This
principle states that the minimum level of access should be granted to accomplish a
given task.
Note that in this discussion, the string "su - {user-name}" has a space on each side of the
dash. This is a rare instance in Linux where this is true; the majority of other commands
are spaced as "command -option," which has a space only on the left side of the dash.
Using su with a hyphen following it enables a user to change users and launch a
new shell under the context of that new user. This is a much better practice. Anyone
using the su - except the root user will be challenged for the password of the
user they are switching to. It is most common to switch to the root user, but any
user can switch to any other user as long as they know that user’s password.
Without a user name argument, the su - command will assume you mean to sign in
as root.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
You can check your sudo privileges by using the -l option. For example, type
sudo -l, and your privileges are displayed.
It may be difficult to get into the habit of using sudo before each command. Recall
that Bash keeps a history of recent commands and that !! repeats the most recent
command. If you forget to type sudo in front of a command, rerun the command by
typing sudo !!.
Understand visudo
While the /etc/sudoers file is a normal text file, it is essential not to directly
edit it with a standard text editor like Vim or nano. The /etc/sudoers file
controls access to all elevated privileges, and a mistake in this file can render it
impossible to gain root privileges on the server. Most distributions will set a default
editor (usually Vim or nano) for /etc/sudoers. When using the visudo
command, the system verifies the syntax of the /etc/sudoers file before
committing changes, enabling the administrator an opportunity to correct mistakes
before they become part of the running configuration.
The following are some options you can use with the visudo command:
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
PolicyKit Rules
The polkit (PolicyKit) toolkit provides a different way of delegating privileges than
sudo does. The polkitd daemon works with systemd to permit administrators to
delegate more granular control to users than sudo allows. Unlike sudo, polkit
does not grant full root access to a process but instead grants specific access to
defined actions.
One example of polkit’s benefits is software management. Using polkit rules,
sysadmins can permit a user to update existing software but prevent the
installation of new software. Other delegated tasks include system shutdown or
hibernation, configuring network devices, controlling device access, and mounting
or unmounting filesystems on removable media.
Some topics in this section, such as systemd and software management, are covered in
more detail elsewhere.
Use of pkexec to create a user account with confirmation that the account has been created.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
For example, to launch nano with pkexec and edit the /etc/named.conf
configuration file, type:
pkexec nano /etc/named.conf.
Recall that the su - root command actually changes the user identity to root,
with all related privileges. This could be dangerous. The sudo and polkit utilities
allow administrators to delegate specific tasks to specific users without granting
complete administrative privileges to the system.
Phone Call 1: su
A user calls and says that the su command is not responding as expected. You ask
the user to type whoami and the user reports the result is root. You also ask the
user to type pwd and the user reports the result is their own home directory. When
the user switches identities, they remain in their own home directory with their own
profile settings. The user wants to know what is preventing them from switching to
root and gaining the root user’s profile.
In this case, it’s likely that they are using the incorrect syntax. The user failed to
include the space on both sides of the dash between the su command and the
username, su - root.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Privilege Escalation
6
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 2D
Troubleshoot User and Group Issues
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Users may fail to authenticate to the system. These failures are often associated
with user account and password misconfigurations. Recall that account information
is stored in the /etc/passwd and /etc/shadow files.
2. The user enters a name and password combination. These are checked
against the /etc/passwd and /etc/shadow files. Settings such as
expired passwords and locked accounts are checked for at this point.
3. System and user profile files are processed, and the user is presented with an
authenticated and customized environment.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The last command displays the most recent logins and logouts.
It is a good security practice to delete unused user accounts, and these tools help
identify such accounts.
While the historical data displayed by last and lastlog can be helpful, it’s
also useful to know what users are currently on the system. Both the w and who
commands display this information. The w command is particularly useful because
it shows the user idle time, which indicates the user may be logged on but no longer
interacting with the session.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
User and Group Troubleshooting
6
1. List at least three scenarios where you might need records of who logged
in to a Linux system.
2. Another administrator asks you to explain the value of editing the /etc/
sudoer’s file with visudo rather than a traditional text editor. What is
your response?
5. A user places sudo before a command, but the command still fails to run.
What might be the cause?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 2
Summary
7
Observe how user authentication allows the system to uniquely identify the logged-
on user. The primary purpose of this identification is to enforce permissions on files
and directories. Permissions can be granted (or denied) to identities, allowing tasks
such as read-only file access, script execution, or application execution. Users are
placed into groups when more than one user must be restricted by permissions.
The use of user identities is further exemplified by considering privilege escalation.
What privilege escalation actually provides is the ability to move from one user
identity to another to exercise different levels of resource access.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
The identity of an authenticated user provides context for enforcing permissions.
Once the system knows which user is logged on, it can limit the actions that user
can take. Linux relies on a simple yet effective permissions structure that recognizes
three identities (users, groups, and all others) and provides three access levels
(read, write, and execute). More complex permissions options exist, including
special permissions and access control lists (ACLs).
Administrators manage group membership, file ownership, and group association
to control access to resources. As such, the permissions discussion in this Lesson is
a natural extension of the account management subject of the previous lesson.
Lesson Objectives
In this lesson, you will:
• Configure standard Linux permissions.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 3A
Configure Standard Linux Permissions
2
The authentication process provides users with an identity on the system. Based on
this identity, the system can enforce levels of access to system resources, such as
processes and files. This type of access control allows users to share systems and
resources with the appropriate levels of confidentiality and privacy.
Sysadmins rely on default Linux settings, such as umask, to define some levels of
access. Administrators also define explicit controls by associating specific access
levels with particular identities. Linux has several permissions structures, including
standard, special, and access control list mechanisms. Users are organized into
groups to make access control more efficient. Proper permissions settings and
owner/group associations are critical to Linux security and administration.
• Improper: They are granted the read, write, and execute permissions and could
potentially change the file.
Joseph Deng needs to create files associated with their own job but doesn’t need to
perform system administrative tasks.
• Proper: Joseph logs on with a standard user account.
Keep the principle of least privilege in mind in all access control configurations,
especially those involving file permissions.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Access Levels
Standard Linux permissions define three levels of access: read, write, and execute
(rwx). These permissions perform differently depending on whether they are
applied to files or directories.
Files Directories
Read (r) The ability to access and The ability to list the
view the contents of a file. contents of a directory.
Write (w) The ability to save changes The ability to create,
to a file. rename, and delete files
in a directory. Requires
the execute attribute to
also be set.
Execute (x) The ability to run a script, The ability to access a
program, or other software directory, execute a file
file. from that directory, or
perform a task on that
directory (e.g., a search).
The three permissions levels are abbreviated with r, w, and x. These abbreviations
are used in conjunction with permissions management commands, so be able to
recognize them.
Access Identities
Standard Linux permissions define three identities to which permissions can be
applied: user (owner), group, and others.
The user (u) identity is a single resource owner. Only one user identity is associated
with the resource with standard permissions, and specific permissions are applied
to this identity. By default, the user is the identity of the account that created the
resource, but that can be changed. This user identity is referred to as the resource
“owner.”
The chown command allows administrators to change the associated user (and group).
The chown command is covered later in this Topic.
The group (g) identity is a single group of users associated with the resource. In
standard Linux permissions, only one group is assigned to the resource and a
specific set of permissions is assigned. By default, the creator’s group is set on the
resource, but that can be changed.
A group allows multiple users to access the resource at a given level. For example,
a sales group consisting of several user accounts can be granted read access to a
sales file, allowing all members of the group to view the contents of the file.
The others (o) identity represents all accounts that are not the user (u) identity or
a member of the one associated group (g). The others identity means “everyone
else” who is not the user and not a member of the group. These other accounts
are granted a level of access. Frequently, that permissions level is either read or
no access.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Linux permissions are enhanced with special permissions and access control lists (ACLs),
which are both covered later in this Topic.
View Permissions
The ls command, introduced earlier, relies on the -l option to display
permissions. Think of the ls -l command as “list in long format,” where the
long format includes the display of permissions. Sysadmins use this command
frequently to confirm permissions settings.
The ls -l command displays details about permissions, owner, group, size, and more.
In the following example, note that the resource is a file (based on the leftmost
dash character), the owner (root) has rwx, the group (grp) has rwx, and all others
have r only.
-rwxrwxr-- root grp fileA
Interpreting Permissions Strings
The permissions string consists of 10 fields, with each field containing different
information.
The first field defines whether the resource is a file or a directory. A file is identified
by a dash character (-), while a directory is identified by a d character.
The first column of the permission string, listing one directory and three files.
The next three fields are related and identify the permissions assigned to the
resource for the user identity. If a permission is granted, it is identified with one of
three characters: r, w, or x. If the permission is not granted, the dash character is
used as a placeholder.
For example, if the user is granted read but not write or execute, the three fields
appear like this: r--. If the user is granted read and write, but not execute, the three
fields appear as rw-. Note that the permissions are always displayed in the rwx
order, and the - is a placeholder for any unassigned permission.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The second three columns list the permissions assigned to the user identity. Here the user
has rwx access to the directory and the first file, rw access to the second file, and read
only access to the third file.
The same structure applies to permissions assigned to the group, in the fifth, sixth,
and seventh fields.
The group permissions are outlined here. The group has r-x access to the directory, rw access to
the first and second files, and no access at all to the third file.
And the final three fields use the same structure for others.
The final three columns show permissions for others not in the user or group identity.
Permissions are more stringent here, with others having r-x access to the directory
and read only access to the first file, with no access at all to the last two files.
Additional fields, such as owner, group, and file size, have been removed from these
examples to provide clarity.
A file named file A, with the user having read, the group having read, and others
having no access would appear as:
-r--r----- fileA
A directory named dir1, with the user having read, write, and execute; the group
having read and execute; and others having read and execute would appear as:
drwxr-xr-x dir1
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
A directory named dir1, with the user having read and execute, the group having
read and execute, and others having no access would appear as:
dr-xr-x--- dir1
Recall that the execute (x) permission is required for the user to use cd to move into
the directory. If a user does not have execute to a directory, they cannot change into
that directory.
Default Permissions
The ls -l command displays the existing permissions, but what if permissions
need to be changed? Administrators can set file and directory permissions for all
resources, and resource owners (the account identified by the user (u) permissions)
can also configure permissions.
A value named umask defines default permissions on a per-user basis. The “change
mode” or chmod command changes permissions settings from the default values.
• 2 means that the group permissions should be masked by 2 (i.e., subtract 2 from
the default [6] and you get 4). Group members now only have read access.
• 2 does the same thing as the previous number, but it does so for other users.
You can use the umask command directly in the CLI to set the default permissions
for that session, or you can set the default permissions for each user in their
.bashrc or .profile file.
The syntax of the umask command is umask {number}.
Because it subtracts from the default (666), the umask command cannot force newly
created files to set the execute bit.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The chmod command has two different syntaxes for setting permissions: absolute
mode and symbolic mode. Both approaches provide the same results. Some
administrators find one approach more logical than the other, and it does not
really matter which is used. Sysadmins should understand and be able to use both
modes.
Absolute Mode
Absolute mode uses octal (base-8) numbers to specify permissions. Each
permission (r/w/x) has an associated number.
Absolute mode octal values:
• Read = 4
• Write = 2
• Execute = 1
By adding the octal numbers for the permissions you want to grant, you get
the overall permission number to assign to a directory or file. For example, full
permissions (read, write, and execute) are equivalent to 4 + 2 + 1, or 7. Read and
write permissions are equivalent to 4 + 2, or 6. Complete permissions are expressed
as a three-digit number, where each digit corresponds to the owner, the group, and
others, respectively.
In absolute mode, the syntax of the chmod command is chmod {number}
{file/directory name}
Three-digit and Four-digit Modes
When written in octal, numeric format, file permissions typically have three digits,
with each digit corresponding to the user, group, and others permissions. However,
file permissions may also be written with four digits, with the new, leading digit
signifying any advanced permissions to be defined (or 0, for none). For example,
the permissions for a non-executable file in Linux might be rw-rw-r--, or 664. This is
equivalent to the octal format of 0664.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Symbolic Mode
Symbolic mode enables you to set permissions using three components, namely:
• Permission contexts: u/g/o/a (a applies the permissions to all three contexts)
While sysadmins tend to prefer one mode or the other, it is worthwhile to understand
both modes. Documentation, online resources, and other administrators may provide
permissions settings using either mode, so you must be able to interpret whichever
mode is presented.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Configure Ownership
Although you’ve restricted access to your data by assigning permissions, you may
need to allow users to modify those permissions for certain files and directories.
This is where the concept of ownership comes into play.
As you’ve seen, the first permission context is the owner or user. In Linux,
ownership refers to the property by which a user can apply and modify the
permissions of a file or directory. By default, the owner of a file or directory is the
user who created that file or directory. Other than the superuser, no other user
can change the permissions of an object that is owned by someone else. While the
most common application of ownership is the changing of read, write, and execute
permission attributes, owners can also alter advanced and special permissions of
the objects they own.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The chown command is used to change the owner, the group, or both for a
file or directory. At times, you may wish for someone else to manage an object’s
permissions other than the user who created that object.
Changing the owner with chown. The file named “project1.txt” was owned by root, but is now
owned by student5 in this example.
Configure Attributes
Files can have one or more attributes set on them that define how the system
interacts with those files. These attributes go beyond typical permissions and
enable you to more granularly customize what the system is and is not allowed to
do with a file.
There are many such attributes. Some examples include:
• Only allow the file to be open for writing in append mode (i.e., don’t allow the file
to be overwritten).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The lsattr command displays current attribute settings, such as this immutable flag.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Thanks,
Ali
Date last updated 2024-04-25
Attribute Issues
Attribute problems are typically related to whether or not the attribute is set. Often
the solution is to either set or unset the value.
If the file can be deleted and should not be, set the immutable attribute with
chattr +i {filename}
If the file cannot be deleted and should be, unset the immutable attribute with
chattr -i {filename}
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Standard Linux Permissions
3
1. How does the principle of least privilege help mitigate threats and
mistakes?
3. Write the command by using symbolic mode that removes the read
permission from others for fileA without impacting other permissions.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 3B
Configure Special Linux Permissions
5
The standard read, write, and execute permissions are good enough in most
circumstances. However, there are additional permissions and attributes that you
can use to restrict access in a more specialized way. These permissions permit
users to run software as someone else or allow directory contents to inherit group
associations, providing default access control settings.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
• Confirm the SGID permission is set correctly for directories to permit files
created in the directory to inherit the group association.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Special Linux Permissions
6
1. How would SGID benefit users when set on the /projects directory where
multiple users are members of the associated group and need access to
each other’s files in the directory?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 3C
Configure Access Control Lists
3
One weakness of standard Linux permissions is that only a single user, a single
group, and all others who are not that user or a member of that group can be
granted access. With standard permissions, a sysadmin cannot provide UserA with
rw- and UserB with r--. Nor can GroupA be given rwx to a directory while GroupB is
given r-x.
Access control lists, a feature of the filesystem, do permit the system to recognize
multiple identities and enforce different levels of access on those identities. In other
words, with ACLs the scenarios above are possible.
ACLs do not replace standard permissions, but rather they enhance them.
Everything you know about standard permissions still applies and is then
supplemented with additional ACL features.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The getfacl command output shows the file owner, group, and standard permissions.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The setfacl command uses the -m option to modify the access control list already in place.
ACL settings do not replace standard permissions. Standard permissions are still
enforced as described earlier in this Lesson, but they are further enhanced by ACL
capability.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
ACL Configuration
4
2. What commands are used to set ACL entries for USERA with rwx and
USERB with r-- for fileA?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 3
Summary
4
The identity of a user or a user’s membership in a particular group governs access to files and
directories. This access control, provided mainly by permissions, allows the possible viewing,
editing, or running of files. Additional controls, such as attributes, default permissions, and
access control lists, permit administrators to exercise more granular control over resources.
Guidelines
These best practices and guidelines are provided for your use as revision tools or as quick
references in your job role.
• Understand the principle of least privilege, which enforces the idea that users should be
given as little access to resources as necessary for them to do their jobs, with no additional
unneeded access.
• Absolute mode and symbolic mode provide the same information in different ways.
Absolute mode displays in octal numerals, while symbolic mode displays information using
operators.
• The immutable flag is an attribute of a file or directory that prevents it from being modified,
even by the root user.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
This Lesson covers the Filesystem Hierarchy Standard (FHS) that defines consistent
locations for data across the various Linux distributions and makes it easier for
users to navigate among directories to find and manage files and directories. Users
rely on an understanding of the FHS to perform file management tasks such as
creating and deleting resources. This Lesson covers the necessary commands to
perform these file operations. In addition, commands such as find and locate are
used to search for resources using many different parameters.
Lesson Objectives
In this lesson, you will:
• Understand the Linux file system.
• Locate files.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 4A
Understand the Linux File System
2
Standard Subdirectories
/bin - Stores essential command-line utilities and binaries. For example, the
/bin/ls is the binary for the ls command.
/boot - Stores the files necessary to boot the Linux operating system.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
/dev - Stores hardware and software device drivers. This directory maintains file
system entries that represent the devices connected to the system (for example,
the /dev/sda1 partition).
/etc - Stores basic configuration files. For example, the /etc/ samba/smb.
conf file stores Samba configuration data.
/home - Stores users’ home directories, including personal files.
/lib - Stores shared program libraries required by the kernel, command-line
utilities, and binaries.
/media - Stores mount points for removable media such as CD-ROMs and floppy
disks.
/mnt - This is the mount point for temporarily mounting file systems.
/opt - Stores optional files of large software packages. These packages normally
create a subdirectory bearing their name under the /opt directory and then place
their files in the subdirectory. For example, the /opt/nessus subdirectory
contains files for the Nessus vulnerability scanning program.
/proc - This is a virtual file system (VFS) that represents continually updated kernel
information to the user in a typical file format (for example, the /proc/mounts file).
/root - The home directory of the root user.
/sbin - Stores binaries that are used for completing the booting process and also
the ones that are used by the root user. For example, the /sbin/ifconfig file is
the binary for the ifconfig command that is used to manage network interfaces
on the system.
/sys - This is another VFS, and it primarily stores information about devices.
For example, /sys/block includes links to devices that are stored in various
subdirectories under the /sys/ devices/ location, which presents a hierarchy
of devices in the kernel.
/tmp - Stores temporary files that may be lost on system shutdown.
/usr - A read-only directory that stores small programs and files accessible to all
users.
The /usr directory contains some important subdirectories.
• /usr/bin - Includes executable programs that can be executed by all
users.
• /usr/local - Includes custom build applications that are stored here
by default.
• /usr/lib - Includes object libraries and internal binaries that are
needed by the executable programs.
• /usr/lib64 - Serves the same purpose as /usr/lib, except it is
meant only for 64-bit systems.
• /usr/share - Includes read-only architecture independent files. These
files can be shared among different architectures of an operating system.
/var - Stores variable files, or files that are expected to constantly change as
the system runs. Examples include log files, printer spools, and some networking
services’ configuration files.
The FHS is displayed by running the following command: ls / (recall that the
forward slash represents the root of the filesystem).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Key Directories
The critical directories to know from the FHS are /etc, /home, /root, and
/var/log.
/etc
The /etc directory contains files and subdirectories that hold configuration
information for the system and its services. It’s reasonable to assume that if you
need to adjust firewall rules, manage Secure Shell (SSH) access, or configure
software-management settings, you will need to work with files stored in /etc.
/home
The home directory contains a user’s personal files or files that are otherwise
specific to that user. The home directory is where you are placed when you log
in to the system. In Linux, by default, every user except the root user is assigned
a subdirectory in /home that corresponds to their user name. A user can create
subdirectories and files within this directory.
The home directory path is set to a variable named $HOME. When the string
$HOME is used, it references the path to the current user’s home directory, such as
/home/student-user. This text will often reference the home directory using
the $HOME variable. In many shells, including KornShell, C shell, and Bash, the tilde
character (~) represents your home directory.
/root
The home directory of the root user is /root. This is not to be confused with the
root directory (/), which is the top-most part of the file system hierarchy.
/var/log
Linux and installed services typically write to log files stored in the /var/log
directory. As a sysadmin investigating a system issue or auditing system access, you
will likely find the information required in log files stored at /var/log.
Familiarity with all of the directories is important, but the directories listed above
are more commonly used and accessed.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Absolute Path
The absolute path defines the directories to traverse, starting from the root of
the filesystem. Recall that the filesystem root is depicted using a forward slash
character (/). The absolute path is the complete path from the top of the directory
structure.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Suppose a user named student-user wants to find the widgets.txt file, which
is stored in the inventory subdirectory of the resources directory of their home
folder. The absolute path is:
/home/student-user/resources/inventory/widgets.txt
Relative Path
A relative path is dependent upon the user’s current location in the filesystem.
Using the above scenario, if the user is already in their home directory, then the
entire path is unneeded, and all that needs to be specified is the remainder of the
path from the current location. Assuming the user is in their home directory, the
relative path is:
resources/inventory/widgets.txt
In other words, relative to your current location, what’s the rest of the path?
Understand Inodes
An index node (inode) is an object that stores metadata about a file or directory
on a file system. This metadata can include time-based values such as when a file
was created and last modified, permission and ownership information, the block
locations of a file’s data on a storage device, and other miscellaneous information.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Use the ls -i command to list the inode numbers for files and directories.
Link Types
Using the ln command, you can create two types of links: hard and symbolic
(soft). Hard and symbolic links are a feature of the file system and are common in
most file systems supported by Linux. The ext2, ext3, ext4, and XFS file systems all
support hard and symbolic links.
The syntax of the ln command is ln [options] {target name}
{link name}
The ln command has various options. Some of these options include:
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
The Linux File System
3
3. A user submits a ticket regarding a file access issue. The first file,
projectA.txt, had a second hard link named my-project.txt. The same
data was available via either link. The user deleted the my-project.txt
file, and the data was still available via projectA.txt. The second file,
projectB.txt, had a sym link that pointed to the projectB.txt link. When
the projectB.txt link was deleted, the data was no longer available via
the sym link. The user wants to know why the first file is still available
after a link deletion but the second is not.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 4B
Use File Management Commands
4
Once the FHS is familiar, navigation among directories is much easier. Commands
such as pwd and cd allow users to understand where in the filesystem they are
and how to move to another location. Over the years, shortcuts have been added
to reduce the amount of typing at the command prompt. Users must manage
file operations—tasks such as moving, copying, creating, and deleting files and
directories—to manage their data correctly. Users must also be able to redirect
information into or out of files.
Navigate Directories
Directories store system configuration files, user data, log files, and other
resources. Linux users move from directory to directory by using various navigation
commands. Shortcuts make the navigation process quicker and simpler.
Knowing how to navigate through the directories allows Linux users to understand
specific directory navigation information such as:
• Where in the file system you are.
Navigation Shortcuts
Absolute and relative paths clearly delineate how to travel from one directory to
another, but over the decades, shortcuts have been established to make common
tasks easier.
The single dot character (represented by “.“) means “here“ or this directory. If your
present working directory is /home/USERNAME/resources, then that path
can be abbreviated as a dot: .
The term parent directory refers to whatever directory is above the current directory.
If your current location is /home/USERNAME/resources/inventory, then
the parent directory of inventory is resources. The parent directory of resources is
USERNAME. The parent directory is often referenced in commands (particularly with
cd), and it has been abbreviated as two dots (represented by “..“). In the above
scenario, the result of typing cd .. is to move to the resources directory. This is far
less typing than the absolute path of /Home/USERNAME/resources.
One of the most useful shortcuts is the tilde symbol (~). This abbreviation means
the home directory of the currently logged-in user. This is incredibly handy. A user
could type cd ~ instead of cd /home/USERNAME to jump to their home
directory. The ~ can be combined with many other commands covered below,
including copy and paste functions.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Using the cd command to return to your home directory is so common that even the ~
is strictly necessary. If you type cd with no argument (path), Bash assumes you wish to
return to your home directory.
Change Directories
The cd command moves your present working directory to another directory. For
example, if you type pwd and discover you are currently in your home directory,
then you could type cd /etc to move to the /etc directory, where many
configuration files are stored.
The cd command is the primary filesystem navigation command in Bash.
The syntax for the cd command is cd {path}
Note that either an absolute or relative path can be specified, depending on your
current location in the filesystem and the desired destination. To traverse the
filesystem to the inventory subdirectory in the resources directory of your home
directory, type the following:
cd /home/USERNAME/resources/inventory
Know Your Location
The critical piece of knowledge for navigation is to know your current location. In
Linux, this is referred to as the “present working directory,“ and the pwd command
displays that. The output is an absolute path from the root of the filesystem to the
directory the shell is currently focused on. The output from pwd may be used to
confirm your location before a backup job, a file transfer, or the deletion of files.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Output of the pwd command, showing that the user is in the /home/student directory.
Some Linux distributions are configured to display the name of the current directory
as part of the command prompt. Note that this is not the absolute path but merely the
name of the current directory. The prompt configuration can be changed.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Files where the first character is a dot (".") are hidden by Bash. This isn't a security
feature, but rather a way of keeping some files out of the user's way. Profile files are
often hidden. Use ls -a to display all files, including hidden files.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Commands used to create a project directory with three subdirectories, and use of the ls
command to display the directories.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
While copying a file creates a new file (a duplicate of the original), moving a file
typically places the file elsewhere in the filesystem. While the file itself may not
move from its location on the hard drive, pointers to the file will be updated with a
new location.
The mv command moves one or more files from one location to another. Like cp,
the mv syntax is to specify the source location first and the destination location
second.
The syntax for the mv command when moving a file is mv {source-
location} {destination-location}
For example, to move a fileA from your home directory to the Projects directory in
your home folder type:
$ mv fileA Projects
However, the mv command has a second function. It also serves as the rename
command in Bash. The syntax is the same, but the terms shift to original-filename
and new-filename. The syntax for the mv command when renaming a file is mv
{original-name} {new-name}
For example, to rename an existing file named “sales-project.txt“ to “marketing-
project.txt“, type:
$ mv sales-project.txt marketing-project.txt
In the project management scenario, the cp and mv commands are very useful for
organizing files.
First, you’ll copy the timeline.txt file to the resources directory:
$ cp timeline.txt resources/
Next, you move the newprojects.txt file to the drafts subdirectory:
$ mv newprojects.txt drafts/
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Using the cat command to confirm the newly created text exists in the newprojects text file.
There are many ways to display file contents besides using cat. A text or
configuration file may be opened with a text editor such as Vim or Nano, or
database resources may be accessed via database programs such as MariaDB.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Observe that to delete an empty directory, the command is rmdir, but to remove a
non-empty directory, the rm command is combined with the -R (recursive) option.
If the user is in their home directory, the entire project directory structure can be
deleted by using the rm command and the -R option. Again, be very certain about
what’s being deleted before running this command:
$ rm -fR project
Use the ls command to confirm the project directory and its contents are gone.
Files are not recovered from the CLI. There is no concept of a trash can from which to
recover deleted files. Be careful before using the rm and rmdir commands!
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Not all file contents fit on the display. When using cat to display a long file, only
the contents at the bottom of the file may fit on the monitor. The remainder scrolls
upward, off the screen. The less command breaks the output into pages that fit
on the screen and can be cycled through.
There are two ways of using less. The first is directly, as a primary command to
display file contents. An example is less long-file.txt. The second way to
use less is to better organize the output of other commands. For example, the
/etc directory has many subdirectories and files—too many to display on the screen
simultaneously. The output of a ls command can be redirected into less, which
allows pagination through the output of ls.
The syntax for this example is ls /etc | less
The pipe character | is discussed later in this Topic in the redirectors section.
The more command is similar to less. The primary difference between the two
commands is that with less, you can paginate up and down, while with more you
can only paginate downward.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The tail command also has some very practical options. Like head, the tail
command accepts the -n option to modify the number of displayed lines. In
addition, the -f (or follow) option updates the output whenever the bottom of the
file changes. This is useful for following log files, as the display will update whenever
the log file changes.
The basic syntax for the tail command is tail {filename}
To display the last 15 lines of the file, type tail -n 15 {filename}. However,
to follow a log file and see updated output whenever the log file changes, type
tail -f {filename}.
Commands such as less and tail display the specified file contents, regardless
of whether it contains the data administrators or users need. These commands
don’t search for particular information within the file, they simply display its existing
content.
The grep command is a pattern matcher, which is a complex way of saying it
searches for strings of characters within a data stream. For text files, grep is a find
utility that displays the specified string or search term in the output.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The syntax for these combinations can take on several different forms.
To list all files in the /etc directory that contain the string “net“ in either uppercase
or lowercase:
To list all files in the /home/student directory that contain the string “.txt“:
The pipe (|) character is covered in more detail in the next section of this lesson. The
ps command is also covered later in the course.
The egrep command is a modified version of grep and functions similarly from
the user perspective, but this utility is deprecated in favor of grep -E.
Redirectors
All of this management and manipulation of files is useful for more than just
looking at the results in a terminal. When you use the terminal, or log out entirely,
you’ll want to ensure that crucial information is stored in a file for later retrieval
and analysis. In addition, you’ll benefit from combining multiple commands in
conjunction, making your administrative duties more efficient and powerful.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Redirection
Operator Action Example Results
> Redirect the standard ls > file1.txt The output of the
output to a file. ls command is
redirected to a file
named file1.txt
>> Append the standard ls >> file1.txt The output of the
output to the end of ls command is
the destination file. appended to a file
named file1.txt
2> Redirect the standard ls file3.txt 2> The output will not
error message to a errorfile.txt be displayed on
file. the screen but is
redirected to a file
named errorfile.txt
2>> Append the standard ls file3.txt 2>> The output will not
error message to errorfile.txt be displayed on
the end of the the screen but is
destination file. appended to a file
named errorfile.txt
&> Redirect both the ls file1.txt file3.txt The output will not
standard output and &> errorfile.txt be displayed on
the standard error the screen but is
message to a file. redirected to a file
named errorfile.txt
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Redirection
Operator Action Example Results
< Read the input from mail user@ The myletter.txt
a file rather than address < file is taken as the
from the keyboard or myletter.txt input and attached
mouse. to the email
message.
<<{string} Provide input data cat <<EOF The cat command
from the current This is a here will use the rest
source, stopping document. of the lines in this
when a line EOF file as input. It will
containing the stop accepting
provided string that input when it
occurs. When placed reaches the string
in a script, this is EOF. This string
called a here can be named
document. anything you want.
The output of the
cat command
would therefore
be: This is a here
document.
Redirection operators, their syntax, and results.
Command Modifiers
Several command modifiers exist that allow users to run combinations of
commands. These commands differ from redirectors in that they manipulate the
command, not the output. Learning to use these effectively makes command-line
administration more efficient.
Background a Command
The single ampersand & causes the command to execute in the background.
Normally, when a command is executed, it consumes the shell until it completes.
Some commands, such as backup scripts, may take a very long time to finish, and
until the script is done, the user cannot type in additional commands or accomplish
additional tasks in that shell instance. If the command runs in the background,
however, it executes while the user continues to work within the shell. Such
commands are referred to as jobs.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Standard interaction with the Bash shell involves typing a command, executing the
command, and then typing another command for execution. Commands can be
written sequentially at a single command prompt to be processed in order. There
are multiple ways of doing this.
Piping is the process of combining the standard I/O streams of commands. It uses
the standard output of one command as the standard input for another command.
The output format of the first command should be compatible with the format that
the second command works with. The pipe operator (|) can be used with most
commands in Linux.
$ ls -l | grep audit
This command, which searches for files named “audit,“ is an example of using a
pipe. The standard output of the ls -l command is fed as standard input into the
grep audit command so that grep searches for the term within the directory
listing.
Chain Operator
Character Common Name Results
; semicolon If the semi-colon character is
placed between commands,
they are run one after another,
regardless of whether the
previous command completed
successfully.
&& logical AND If the logical AND is placed
between commands, the
following command is only run
after the previous command
completed successfully. Useful
for commands that rely on
each other’s success.
|| logical OR If the logical OR is placed
between commands, the
following command is only run
if the previous command fails.
! bang If the bang is placed in a
command expression, it
negates the expression. Used
as a way of stating “except
this.“
Many of these command chains and redirectors are used in scripts. Scripts are covered
in a later section.
These command modifiers do not use a typical or regular syntax. Instead, they are
used between commands to modify certain portions of the command expressions.
To run a series of commands one after another:
$ backupscript.sh;rmdir /projects;mkdir holidays.txt
To run a series of commands that rely on the success of the previous command:
$ backupscript.sh && rmdir /projects
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
File Management Commands
5
1. You have been assigned a helpdesk ticket to answer a user question. The
user is attempting to rename files but cannot find the rename command.
What command do you teach the user?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 4C
Find File Locations
4
Users and sysadmins may struggle to find older files managed by the system and
applications. The find command permits users to search for files based on specific
parameters such as name, ownership, permissions, and more. Users can use
commands such as which to discover where files were executed. Finally, many
file manipulation commands, such as sed, awk, wc, echo, and others, help
sysadmins find data available within files.
Search Commands
Even though the Linux filesystem is fairly well organized by the Filesystem Hierarchy
Standard, and users have file management options with mkdir, mv, and grep
commands, sometimes files are lost or their location is unknown. The primary
command for searching for files using parameters is the find command. The
locate command is an alternative that may make searching easier in a very large
filesystem. Finally, the which command displays where a command executable file
is stored.
Response Hi Joseph, you can search by the file name or by the file
owner using the find command.
Date last updated 2024-05-10
The find command searches the filesystem for files that match the given parame-
ters. These parameters might be file size, modification date, owner, or even permissions.
The find command is a powerful tool for managing files.
The syntax for find is more complicated than some other commands. The general
syntax is:
# find {where to search} {search criteria}
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
For example, to search for a file named “business-plan.txt“ in the projects directory
within your home directory, type:
# find -name business-plan.txt /home/USERNAME/
projects
The -name option specifies to search by name.
A search by permissions of the /home/student directory returns only those files with the
664 access level.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The updatedb command is used to both build and update a database of files
based on the /etc/updatedb.conf file. The database itself is located at
/var/lib/mlocate/mlocate.db. The configuration file can be set to
exclude particular directories that should not be indexed by the utility.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The tr Command
The tr command is used to translate a string of characters. It is predominantly
used to change the case of letters in a file. This command acts only on a stream of
characters and does not accept file names as arguments. You must use redirection
to actually change a file.
The syntax of the tr command is tr {character 1} {character 2}
where {character 1} is the character to be replaced.
The wc Command
The word count (wc) command is used to count the number of lines, words, and
characters in a text file. If multiple files are specified, then the command displays
the counts for each file and the total count for all files.
The syntax of the wc command is wc [options] {file-names}
The wc command provides various options that enable you to specify the nature of
the output.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
• Tokyo,Japan
• London,United Kingdom
• Lima,Peru
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
File Location
5
1. You are conducting a security audit and need to document user access
to log files—specifically whether any files are world-readable or whether
any allow rwx access to all users. How can the find command be used in
such a project, and what specific command might you use?
3. A senior sysadmin suggests that commands such as sed, awk, and sort
are just as useful in automation as at the command-line. How might
commands such as these be used in automation?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 4
Summary
4
Guidelines
These best practices and guidelines are provided for your use as revision tools or as
quick references in your job role.
• Recognize file management commands
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
Linux users edit text files in day-to-day activities and when making system
configuration changes. Because a graphical user interface (GUI) is not always
available, visual menus are not always possible; text editing in Linux is very different
from text editing in other platforms. Text editors rely on various modes and
metakeys to enable functions such as save and copy/paste. It’s also essential to
ensure that files are backed up, protected, and that their integrity is guaranteed.
This Lesson focuses on Linux text editors such as Vim and archiving tools such
as tar.
Lesson Objectives
In this lesson, you will:
• Edit text files.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 5A
Edit Text Files
2
Text file editing is a basic but essential skill for Linux users. In Linux the graphical
user interface is optional, making text editing unique in Linux compared to other
operating systems. If the Linux system does not have a GUI, editors that rely on
mouse-driven menu options cannot be used. Sysadmins must use the keyboard
only to access all text editor program functions in this case. This Topic covers the
common Linux text editors that all users should be familiar with. It is critical to be
able to open, edit, save, and close files with any Linux editor.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Vim
The “Vi Improved,” or Vim editor, is installed on most distributions. It is extremely
powerful and a little complex, but the general functionality is straightforward. Vim
has three modes. When switching modes, the keyboard will react differently. For
example, pressing the w key in one mode inserts the “w” character in the text of the
file. In a different mode, however, the w key writes or saves changes to the file.
The older version of Vim is named vi (pronounced “vee-eye”), and it is not often used
on modern Linux systems. Frequently, when a user types vi to invoke the editor, the
Vim editor is automatically invoked instead. The vi editor is more limited, but its basic
functionality is the same as that of Vim.
To make working with Vim easier, begin by memorizing what the three primary
modes do and how to switch among them.
Both Command Mode and Execute Mode manipulate the file by doing an action
such as creating or saving a file, while Insert Mode actually manages the text in a
file (writing or deleting words). The default mode you see upon opening Vim is the
Command mode.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
There is a fourth Vim mode named Visual, which allows the user to select or highlight
text for copying, deleting, and other tasks. Visual mode is not covered in this course.
There are many additional commands in Command mode, but for the purpose of
learning the editor, only some commands have been documented here.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
:q Quit Vim.
Observe that ZZ in Command mode and :wq in Execute mode do the same thing.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Users may find it useful to compare two files or may need to transfer content
between the files. In this case, it’s useful to have the files open side-by-side (vertical
split). The user can glance back and forth between the two file versions, making
whatever edits are desired.
Split Vim into two or more vertical windows by typing Ctrl+w and then v.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
To cycle from one window to the next, type Ctrl+w and then w. You can also use
Ctrl+w with the four normal directional keys mapped in Vim.
nano
Nano is a simpler (but less powerful) text editor than Vim. As such, many users
and administrators prefer nano for basic editing functions. Nano does not use the
concept of modes. Instead, pressing the Ctrl key on the keyboard along with
various character keys issues commands to the program.
The nano command invokes the editor. If an existing file is specified, the editor
opens it. If no file is specified, nano creates a new file for editing.
Note that the name of the text editor is “nano," with no capitalization.
Shortcuts in nano
When nano opens a new or existing file, no further action is needed to begin editing.
Simply pressing keys on the keyboard begins the process of entering text. You can
move the cursor through the file using the arrow keys. Most commands are issued
to nano by using the Ctrl key; however, other keys, such as Alt and Tab, may
be used for some functions.
Nano is quite powerful and contains many keystroke shortcuts in addition to those
mentioned here. Use the arrow keys, Page Up, Page Down, and Home keys to
navigate within a document.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Copying parts of text on a line requires you to “mark” the text you want to copy with
the Ctrl+^ shortcut. You then navigate your cursor to highlight the text you want
to copy. Pressing Alt+^ copies the marked/highlighted text, and Ctrl+U pastes
it. You can cut the current line by using Ctrl+K.
Gedit
The gedit text editor is the default text editor used in GNOME desktop
environments and is a member of the GNU Project. Unlike Vim and nano, gedit
has a GUI with a typical menu-based design that makes it easy to work with. It also
has features such as syntax highlighting and spell checking and can be customized
through plugins. While not as powerful as Vim, gedit may still be useful in systems
that have a desktop environment installed.
Although you can launch gedit from the desktop, you can also use the CLI with the
gedit command. The syntax is similar to vim and nano—typing the editor name
with no argument opens a new file, whereas providing a file name as an argument
either opens an existing file or creates a new one with that name.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Text Files
3
1. A user contacts you and wants an easier text editor to use than Vim.
There is no GUI installed on the system in question. What text editor do
you suggest and why?
3. Why are text editors more important on Linux systems than on other
systems?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 5B
Manage Text Files
4
Both user and system files must be protected. It is common to back up user files
in case of hard disk failure. It is also common to back up system configuration files
before making major changes. Doing so offers the ability to restore the original
configuration file if something goes wrong with new changes. The tar utility is
often used to back up or compress files. In addition, applications or other data
files available on the web are commonly bundled with tar for ease of access. After
downloading such files, verify their integrity to ensure the files are legitimate,
complete, and uncorrupted.
Thanks,
Ali S
Date last updated 2024-05-14
When using tar to work with a group of files, the primary phases are:
1. Create a tarball (bundle).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The syntax for the tar command is tar [options] {file1, file2,
file3...}
Some common options for tar are:
Thanks,
Ali S
Response Sure thing, Ali. Please take a look at the attached walkthrough
using the -c and -x options with tar
Using the example in the helpdesk ticket, the following list is a demonstration of the
tar utility. This series of commands will manage user Ali Selassi’s proposed archive
consisting of file1, file2, file3, and file4.
1. Create a new tarball:
tar -cvf filearchive.tar file1 file2 file3
2. Display the files in the archive:
tar -tf filearchive.tar
3. Add a file to the archive:
tar -rf filearchive.tar file4
4. Extract the files from the archive (this is equivalent to a restore process in a
backup/restore scenario).
tar -xf filearchive.tar
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The full CLI output of the different steps of the tar utility.
Keep in mind that as a user, you will frequently interact with tar archives as part
of a download process. Experience with tar makes both file management and
download processes easier.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Compress Files
Compression is a procedure in which data is encoded to reduce the amount of
bits that are used to represent that data. The compression process can significantly
reduce the size of a file or collection of files in order to make the storage and
transfer of data more efficient. Although the file takes up less space, it still contains
the requisite information so that only redundant data is removed (lossless
compression) or so that only noncritical data is lost (lossy compression).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Compressing with xz
The xz command is a data compression utility, similar to gzip, that reduces the
size of selected files and manages files in the .xz file format. The xz command has
several options.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
For compression speed, tests tend to show that gzip is slightly faster than bzip2,
and both are significantly faster than xz when the applied compression level
increases. For decompression speed, gzip tends to be the fastest again, with xz and
bzip2 as second and third fastest, respectively. When it comes to compression ratio,
xz tends to perform the best, followed by bzip2, with gzip having the worst ratio.
Ultimately, consider using:
• gzip—if you just care about compressing and decompressing files as fast as
possible and are less concerned with storage space.
Thanks,
Ali S
Response Yes, you can combine the tar utility with a compression tool
like gzip or bzip2. I’ve sent over a tutorial on how to use it.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
You'll use the md5sum command to check file integrity in Lesson 12.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Text File Management
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 5
Summary
3
Linux users must be able to open, edit, save, and close text files using various text
editors, especially Vim and Nano. Not only is user data held in text files, but system
settings are also stored in these files and must be edited to make configuration
changes. Furthermore, user data should be backed up or may need to be available
for transfer to other systems. Archiving tools like tar play an important role in file
management. The text editing skills covered in this Lesson are critical to all facets of
Linux system use.
Guidelines
These best practices and guidelines are provided for your use as revision tools or as
quick references in your job role.
• Make a copy of configuration files before making changes.
• Be aware that various distributions may offer one or the other (or both)
editors.
• Recognize that tar is used with backup/restore processes and file downloads.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
Maintaining software on Linux systems is usually accomplished with package
managers. Package managers deploy, update, remove, and report on applications.
However, due to the open-source nature of the Linux environment, software
applications are often compiled from source code—something that is not common
with other operating systems.
Because there are many different Linux distributions available, there are many
package managers. As a general rule, most distributions either originated with Red
Hat Linux (and therefore use the Red Hat package managers) or Debian Linux (and
therefore use the Debian package managers).
This Lesson covers several common package managers, the process of acquiring
and compiling software, and running software in a sandbox for security.
Lesson Objectives
In this lesson, you will:
• Understand software management.
• Acquire software.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 6A
Understand Software Management
2
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
• You can learn how the software is constructed, discover bugs, and contribute
improvements.
To effectively use Linux systems, users must be capable of both managing software
packages and compiling software from source code.
Software Packages
Linux software is often distributed in packages that contain everything needed
to run the software—executables, configuration files, supporting resources, and
documentation. Therefore, the process of installing, maintaining, and removing
software is referred to as package management, and the tools required to maintain
software are package managers.
One critical component of package managers is the ability to report software
information. Package managers track software installation information in a
database that can be queried. Such queries might include a list of all installed
software, a list of software versions, or specific information on a single software
package. The ability to query the package manager’s installation database provides
sysadmins with essential information on the system and its applications.
Querying a package manager. In step 1, a user at a terminal uses the # apt show nmap
command to find out more information about nmap. The package manager calls out to the nmap
package (step 2), which provides information back (step 3). Finally, the package manager displays
the nmap details at the terminal (step 4). (Images © 123RF.com.)
A second critical part of package management is the source from which package
managers pull the software. A storage location for software packages is referred
to as a repository. Sysadmins control what repositories are available to package
managers.
Lesson 6: Managing Software | Topic 6A
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
In an earlier lesson, the Filesystem Hierarchy Standard (FHS) was noted as being a
consistent way of organizing Linux directories. Such organization allows package
managers to exist. Package managers place configuration files in /etc, log files in
/var/log, documentation in /usr/share, and so on because those locations
are standardized across distributions.
Each package manager has its own related commands, and those commands cover
the three major parts of the software lifecycle (installation, maintenance,
and removal). Some basic examples are:
• $ rpm -i {software-package}
• $ rpm -U {software-package}
• $ rpm -e {software-package}
• $ apt install {software-package}
• $ apt upgrade {software-package}
• $ apt remove {software-package}
When discussing package managers, note that the name of the package manager is
usually shown in uppercase letters as an acronym. The associated commands are
displayed in lowercase letters because they would be typed at the command prompt.
So the RPM package manager includes the rpm command (to install .rpm files).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The commands for these specific package managers are covered in detail later in
this Lesson.
Software Dependencies
Package managers make software maintenance much more straightforward. One
challenging part of handling Linux software, however, is dependencies. Some
software packages rely on other packages to function. If the software an application
depends on is not installed, it will either fail entirely or not work as intended.
Early package managers required administrators to manually provide the
dependent applications before installing the primary package. Modern package
managers such as YUM, DNF, and APT install supporting applications automatically,
ensuring that a single installation command provides the user with everything
needed to run the program.
Periodically, package dependency issues still arise, so recognize the problem
(failed dependency) and the solution (install the packages required for the primary
application to run).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Software Management
3
3. Why is compiling software more common with Linux systems than with
other operating systems?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 6B
Manage RPM Software Packages and
Repositories
4
Many common Linux distributions are derived from Red Hat Linux. Common
components of most of these distributions are package management and software
package format. Packages for Red Hat–derived distributions use the .rpm file
extension. There are three common package managers: RPM, YUM, and DNF.
Common examples of Red Hat–derived distributions include Red Hat Enterprise
Linux and Fedora.
RPM Commands
The use of Red Hat package managers is primarily focused on installing, updating,
upgrading, and uninstalling software packages. These packages have a .rpm
file extension. RPM files are pre-compiled and usually include all supporting
documentation and configuration files. The idea is that a single package contains
the entire application.
Observe that in this Lesson, “Red Hat” usually refers to that Linux distribution in the
context of a parent distro from which many other Linux distros are derived. RPM-
oriented package managers are not necessarily developed or maintained by Red Hat
itself.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Here is an example of using RPM to manage a software package that installs the Z
shell (assume the zsh.rpm package has been downloaded to the system, and the
present working directory is the download location).
This command installs the software in verbose mode and provides a progress bar
to track the installation process:
$ rpm -ivh zsh.rpm
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
This command does two things. It will update the package on a system that already
has the package installed. It will also install the package on a system that does not
currently have it. To accomplish either of these, type:
$ rpm -Uvh zsh.rpm
This command will update an existing package, if installed, but it will not install the
package if it is not already present:
$ rpm -Fvh zsh.rpm
The importance of upgrade (-U) versus freshen (-F) may be difficult to visualize
when thinking of a single system. On a single computer, you’re likely to know
whether the specific software package is present. However, the real importance of
these two options is clear when the rpm command is used in scripts that maintain
software on many systems. A single script may be used to manage software on
20 systems, some of which are supposed to have the software and some of which
are not.
Removing the zsh.rpm package is just as simple. The progress bar and verbose
options may be used to track the removal process as well:
$ rpm -evh zsh.rpm
The actual zsh.rpm package name will, in reality, be much longer and include
information about the version and architecture for which the package is designed. The
package name used here has been shortened for these examples.
YUM Commands
The yum command works with .rpm packages and is the next evolution of the
RPM package manager. It features a more intuitive syntax and the ability to handle
software dependencies more elegantly.
The syntax for the yum command is yum [options] [subcommand]
{package-name}
There are many common subcommands for the yum command, but the key
examples are presented in the table below.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The command to check for updates for all installed packages is:
$ yum check-update
This may generate a lot of output. If there is a specific package that you want to
check for updates, add the package name as an argument:
$ yum check-update {package-name}
To remove software by using YUM, type:
$ yum remove {package-name}
The yum update command, with no arguments, updates all software packages on
the system.
DNF Commands
The DNF package manager is the most advanced of the three software-
management solutions and includes many practical features and updates. It is the
assumed package manager on modern Red Hat–derived distributions, though YUM
and RPM may also be available on those systems.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The DNF package manager recognizes package groups. Package groups are logical
collections of related packages. If an administrator wanted to install all software
for managing virtual machines, each individual package could be identified,
downloaded, and installed. However, virtualization software is collected into a single
package group to be installed as a unit:
$ dnf group install virtualization
It is also possible to identify the group by using the @ symbol in the following command:
dnf install @virtualization. Note that this example uses the
standard dnf install syntax.
Which to Use?
When working with Red Hat–derived distributions, assume the use of the dnf
command to manage packages. Sometimes the rpm command is useful for a single
quick installation when no dependencies are involved. While DNF is the standard,
YUM is still very common.
It’s a good idea to be able to administer basic package management by using all three
commands.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The output from the rpm -qa command is likely to be immense, so it may be a
good idea to redirect the results into a text file.
The syntax to display information about a specified package is:
$ rpm - qi {package-name}
Results of the rpm -qi command showing information about the nano package.
The YUM and DNF package managers provide the same functionality.
There may be instances when a user, administrator, security auditor, or other
individual needs to know exactly what software is installed on a specified Linux server.
Thanks,
KG
Date last updated 2024-04-11
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
It’s likely that the output of these commands will be redirected into a text file to be
provided to the requesting user.
Observe that the syntax for YUM and DNF is very similar.
Why Repositories?
Repositories, often called “repos,” are software storage locations that package
managers can check when installing or updating software. Many repositories exist,
and not all are trusted. In some cases, malware might be present, but there are
other reasons that repositories may not be trusted.
Possible reasons for sysadmins to control available repositories include:
• Software version control: Some repositories may release beta or unapproved
software that production servers should not use.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The yum command includes some additional subcommands for viewing and using
repositories:
• repolist —Used to see all available repositories.
• makecache —Used to locally cache information about available repositories.
• clean all —Used to clear out-of-date cache information.
Global settings, such as where to find repository configuration files, log file
locations, and cache information, are stored in the /etc/yum.conf file. The
difference between this file and the repository configuration files is that this file
defines how the YUM package manager works, while the repository files define
where the package manager searches for packages.
The DNF package manager uses a configuration file stored at /etc/dnf/dnf.
conf to define its global settings. These are the same types of global settings
as defined for YUM. DNF also looks to the /etc/yum.repos.d directory for
repository reference files.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Services are covered later, but recall that for configuration file changes to be
implemented, the sysadmin must restart services.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
RPM Software Packages and
Repositories
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 6C
Manage Debian-based Software
Packages and Repositories
4
While the previous section covered the Red Hat approach to package management
and this section covers the Debian package-management system, it’s worth noting
that package management concepts remain constant. Both approaches manage the
software through its entire lifecycle, from installation, to update, to removal.
Many Linux distributions trace their lineage back to Debian, one of the oldest
distros. The most widely used distros include Debian, Ubuntu, Linux Mint, and Kali
Linux, though there are many other examples. Debian’s common dpkg package-
management system has been replaced by the apt command.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Update Packages
As part of software life-cycle management, APT can update installed software.
Software updates are usually a two-step process with APT. The first step is for APT
to discover updated packages in the configured repositories. The second step is to
actually install the updates.
First, update APT with information about newer versions of available software
as compared to the packages already installed. This does not update the actual
software. The command is:
$ apt update
Once APT is aware of available software, it checks that software against the current
installations. By using the upgrade subcommand, administrators can upgrade
any or all packages to current versions. The apt command for upgrading is:
$ apt upgrade {package-name}
Lesson 6: Managing Software | Topic 6C
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
If no argument is specified with apt upgrade, then all packages are upgraded
to the latest version.
The dpkg package manager has mostly been replaced by APT in much the same way
that the RPM manager has been replaced by YUM and DNF.
Output of the sudo apt show command displaying details of the nmap package.
Sometimes a piece of software is unfamiliar to the user, and the ability to see
the vendor, the install date, and the description of the software makes it easier
to understand why the software is installed (and potentially whether it can be
removed).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Debian Software Packages and
Repositories
5
1. What are the two steps for upgrading software with apt?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 6D
Compile from Source Code
3
Package managers are efficient and convenient forms of acquiring and installing
software. However, there may be times when you want to build software from
source code—after all, most Linux software is open source.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The Bash shell only checks for executable files such as programs and scripts in specific
locations. Usually, a user’s home directory is not one of these locations (nor should it
be, for security reasons). However, it’s as if the software the user is compiling has been
downloaded to the home directory. The ./ instruction tells Bash to “check here” at the
present location for the specified executable file.
The second step is the actual compile process. In most cases, once the makefile is
created, simply issuing the make command without arguments will compile the
application. The make command automatically looks for the makefile in the current
directory. You can, however, issue make with various options.
A makefile is a file that contains instructions used by a compiler to build a
program from source code. These instructions typically define the resources that
the program depends on in order to function properly, as well as any additional
directives as defined by the developer.
Once the compile process completes, it’s time to install the software. This is the final
step in the process. The make install command installs the program, placing
the appropriate files in the appropriate locations (configuration files, log files, and
so on). The software is now available and ready to run.
Compile Software
When an administrator downloads software, there is a common process to build
the executable file called software compilation.
1. Unpack the download, typically using tar and/or gzip commands.
2. Change into the directory that gets created as part of the unpacking process.
4. Use the make command to compile the application using the information
stored in the makefile. Note that this usually requires root privileges.
5. Use the make install command to install the resulting binaries (the
application).
Many developers will provide instructions and options that may modify this process
somewhat. Specifically, there may be options or modifications that can be made
to the makefile before the make command is run to optimize the software for
the system or the user’s needs. It is important to review any README or other
instruction files that are downloaded as part of the software.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Source Code
4
2. Why is it more common to compile software with Linux than with other
operating systems?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 6E
Acquire Software
3
Repositories are not the only way to download and install software. Several other
tools are used in this topic to enable you to acquire the files necessary to use
software. These tools provide alternate ways of downloading files from web servers
and managing compression.
You can also search open-source hosting sites, such as GitHub®, for software.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
While there are many options for the curl command, common examples include:
Recall that tar was covered in an earlier lesson. It is covered here only in the context
of downloading software or source code from the Internet.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Software Acquisition
4
1. How can wget or curl be used to download files from the Internet in a
way that a web browser can not be used?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 6F
Run Software in a Sandbox
3
Typically, software and the operating system share resources and can affect each
other. This design creates potential security threats where one piece of software
can impact the entire system. Isolating software with sandboxing helps mitigate this
potential vulnerability.
Why Sandbox?
One of today’s greatest cybersecurity threats is ransomware. Malware may enter
a network environment via poorly tested or poorly written software, which then
gains access to user data. One way of mitigating this threat is for end-users to run
software in a sandbox environment.
A sandbox is a virtual machine or container that isolates the application from the
rest of the system and mediates communication between hardware resources and
the program. Such a design is often more secure than an operating system and
many applications sharing unmediated access to system resources. Developers
testing new software and cybersecurity professionals examining malware code are
among those who benefit from sandbox solutions.
Sandboxing differs from an older practice known as chroot. By using chroot,
administrators told the application that a given directory was the “root” or highest
point in the filesystem. Since the application was unaware of any directories above
this root, it couldn’t access the rest of the system. In some cases, this practice is still
appropriate today.
Sandboxing relies on applications to enforce boundaries, while chroot uses the
filesystem.
Sandbox Software
The following three package managers distribute and run software in a sandboxed
environment: Snaps, Flatpak, and AppImage.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Snaps
Canonical, the group responsible for Ubuntu Linux, uses the Snap package
manager to deploy and maintain software. The software is distributed as “Snaps”
and managed by the snapd daemon and the snap command. Each Snap is self-
contained with everything necessary to run included in the package. The packages
run in an isolated sandbox environment.
Once Snap is installed, packages can be downloaded from the Snap Store. After
that, application management is similar to that of other package managers:
$ snap install {software-package}
$ snap info {software-package}
$ snap list
$ snap remove {software-package}
Flatpak
Another package manager that runs applications in a sandbox is Flatpak. Using
the flatpak command, users can manage software on a system-wide or per-user
basis. Repositories—called “remotes”—store software distributed as flatpaks.
To install {software-package} from a remote named org.demo.sample,
type:
$ flatpak install {software-package} org.demo.
sample
AppImage
AppImage offers self-contained applications that run consistently on Linux systems
in a sandboxed environment. AppImage applications are distributed and managed
as a single file containing everything needed to run the application. Application
developers decide what distributions to support and then ensure that all needed
dependencies and libraries are included with the AppImage file.
AppImage applications are standalone components, and while they can be installed
in the traditional manner, they do not have to be. They can be accessed and run as
mounted drives.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Software in Sandbox
4
2. True or False? The original practice, known as chroot, that predates the
current method of sandboxing, is deprecated and no longer used.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 6
Summary
3
Red Hat and Debian package managers handle software maintenance for most
Linux distributions. There are also package managers that run applications in
isolated sandbox environments for ease of maintenance and security. Some
software is acquired in the form of source code, which allows users to customize
the application for specific features or hardware before compiling it. This process is
uncommon on platforms that use proprietary software but is more prevalent with
open-source code.
Guidelines
These best practices and guidelines are provided for your use as revision tools or as
quick references in your job role.
• Recognize which package managers are used by which distributions:
• rpm, yum, and dnf commands are usually used by Red Hat–derived
distributions.
• Be able to install, update, and remove software by using the rpm, yum, dnf,
and apt commands.
• Be able to query packages by using the rpm, yum, dnf, and apt commands.
• Be able to configure software repositories for the RPM, YUM, DNF, and APT
package managers.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
Storage management involves planning, understanding hardware, and using many
tools to accomplish storage goals. Sysadmins must know what types of hardware
are available and what type will work with the Linux system in question. They must
also know the performance requirements for data stored on any drives. Direct-
attached storage disks are managed as single entities with traditional partitions or
can be combined into logical volumes for more flexible storage space. Network-
based storage, such as NAS, SAN, and cloud technologies, may also be used. Finally,
sysadmins must understand the available Linux tools for troubleshooting and
performance monitoring.
Lesson Objectives
In this lesson, you will:
• Understand storage.
• Deploy storage.
• Troubleshoot storage.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 7A
Understand Storage
2
Storage Concepts
Storage capacity for user data, databases, logs, configuration files, operating
system and application executables, and other resources are of major concern to
sysadmins. Capacity is only one part of the issue, however. Related is the ability
to maintain cost-effective, reliable, and secure storage media that is accessible to
users and services.
The storage concepts in this section compare various storage technologies and
configuration options that inform the choices that Linux administrators make for
storage.
Cloud-based storage is a growing online service and has become a critical part of much
storage management. General cloud concepts are covered in a later Lesson.
• Solid-state disk (SSD): Flash memory storage, usually expensive, fast, small, and
shorter -lived
• Universal Serial Bus (USB): Connection protocol for various external devices,
including storage drives
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
File storage is the common approach to storing data on local drives, with data
organized into discrete files stored in directories. These directories are organized
in a hierarchical structure. Data is easy to retrieve and change, but file storage does
not scale well: it must be scaled out rather than scaled up.
Block storage is a good choice for large quantities of unstructured data
stored across multiple platforms and storage types. Commonly used with SAN
technologies, it is quick, reliable, and efficient.
Object storage is cost-effective and very scalable but best for static data because
it’s difficult to modify data once written. This makes it particularly unsuited for
databases.
A typical Linux server will rely on file storage by using one or more internal drives
that use a standard filesystem to organize and retrieve data.
Storage Interfaces
Internal storage devices use different protocols and interfaces to communicate
with the rest of the system. These designs vary by speed, communication type, and
scalability. Various solid-state drives, hard disk drives, and flash storage use these
interfaces.
Serial Advanced Technology Attachment (SATA) is a common inexpensive
storage media that uses a serial connection to communicate with the motherboard.
This is the slowest of the three options discussed here but the least expensive. It is
a good all-around solution for most systems.
Small Computer Systems Interface (SCSI) tends to be expensive with less capacity
than most SATA drives but makes up for this by being very fast. For servers, RPMs
of 10,000 and 15,000 are common, while desktop and laptop drives might spin
at 7,200 or 5,400 RPMs. Multiple SCSI drives can be attached to the same chain,
making their scalability far more flexible than SATA.
Serial Attached SCSI (SAS) is an upgraded SCSI design with larger capacities, faster
transfer speeds, and greater flexibility. However, these benefits come with a higher
cost. The cost may be well worth it for mission-critical servers.
Linux administrators must balance speed, capacity, and cost when deciding which
of the standards is appropriate for a new Linux workstation or server.
Types of Partitions
Storage drives are divided into partitions for more efficient and organized use.
On a Linux server, these partitions may store different types of operating systems,
applications, or data files. There are two ways of tracking these divisions of the
drive: a Master Boot Record (MBR) or a GUID Partition Table (GPT). These two
entries identify where on the physical drive the partition divisions are located.
The MBR is the traditional choice, but it is limited. Many server administrators use
the GPT because it recognizes more partitions (divisions) of the drive, which is
important for larger-capacity storage devices.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The master boot record (MBR) is the first physical sector on a storage drive and a
type of partition structure. The MBR boot sector contains the boot loader that loads
the operating system into memory. It also contains the partition table of the storage
drive. MBR determines what sectors are available to each partition, as well as which
partitions are bootable and which are not.
For many years, MBR was the dominant partition structure used in Linux and other
operating systems. However, it has three major disadvantages:
• The maximum storage space of an MBR-partitioned drive is two terabytes.
• The boot data is stored all in one sector, which increases the risk of corruption.
The GUID Partition Table (GPT) is a successor to MBR that makes up for the latter’s
shortcomings. Like MBR, it is a partition structure, but it employs a more modern
design and is part of the UEFI standard. Every partition on a drive is assigned a
globally unique identifier—a GUID—to distinguish it from every other partition on
(theoretically) every drive.
The storage space and partition number maximums are so large that they are not
currently achievable, and any limitations are going to be imposed by the file system
type or operating system kernel, rather than GPT itself. GPT also has the advantage
of storing its boot data in multiple locations on a drive to enhance redundancy.
If the primary location is corrupted, GPT can leverage one of the other copies to
restore the boot data.
Whenever possible, partitioning a drive with GPT is preferable to MBR.
The use of FUSE is not inherent in Linux administration. The key factor here is that Linux
is capable of this feature, which provides a great deal of flexibility.
RAID Arrays
A standalone storage disk is a single point of failure. When the disk fails, the data on
it is likely to become inaccessible. In addition, individual disks have limited transfer
speeds and storage capacity.
Storage disks may be organized into RAID arrays to mitigate the limitations of
standalone drives. A Redundant Array of Inexpensive Disks (RAID) combines
storage disks together. Depending on the configuration, the result may be greater
capacity, greater fault tolerance, and increased speed.
Two different designs manage RAID arrays: hardware and software. Hardware RAID
uses a dedicated controller attached to the motherboard. This is usually faster,
more flexible, and more expensive. Software RAID relies on the operating system
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
to manage the storage, which is usually slower, less flexible, and less expensive
(because no special hardware is required).
In a server, hardware RAID is almost always preferred.
Various RAID standards exist and are primarily identified by number, but three
of the most common are RAID 0, RAID 1, and RAID 5. Each has advantages and
disadvantages to consider.
• The total number of blocks (in kilobytes) that are being used by the user/group
on a file system.
• The total number of inodes that have been used on a file system by the
user/group.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
3
Storage Concepts
Answer the following questions:
1. Explain the key differences between MBR and GPT partition tables.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 7B
Deploy Storage
4
To confirm the proper disk type is installed and compatibility with the storage
controllers, type:
# hwinfo --short --storage
Add the --short option to focus on general information about the specified device.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The hwinfo tool is also used to gather CPU, memory, Bluetooth, and network device
data. It is covered in more detail in the next Lesson.
Output from the lsblk /dev/sda command displaying capacity and partition
information.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The sd string (which used to stand for “SCSI disk” but now means “storage disk”) is
followed by a letter defining the drive’s location. Any numbers that follow reference
a partition, if any have been created.
So, the first storage disk in the system is displayed as /dev/sda. In this example,
a second disk is added to the system, so it is labeled as /dev/sdb.
Partition Design
It is common to dedicate specific partitions to certain FHS directories. For example,
it may be useful to place the /boot directory on its own partition. In addition, the
/home and /var directories may also be mounted to dedicated partitions. The
reason these two directories are often attached to dedicated partitions is that they
are particularly at risk for filling up. Users may create or download a great many
files to their home directories, or log files stored at /var/log may suddenly
increase in size due to failing applications or services. If the partition where the root
of the filesystem (/) resides fills, the system will crash. To prevent this, directories
such as /home and /var, which are at risk for filling, are placed on separate
partitions from /.
Linux also commonly dedicates a partition to virtual memory. Using a process called
“swapping,” Linux moves data between memory and the hard drive if the memory is
in danger of being fully consumed. A dedicated swap partition is often set aside that
is 1.5 times the quantity of the total RAM.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
To create partitions on the newly installed storage disk by using fdisk, use the
following steps:
1. Type fdisk /dev/sdb to edit the partition table for the second (new)
disk.
7. Type p to display the new partition information (note that no changes have
been made at this point).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
8. Type w to write (save) the changes to the partition table and exit fdisk.
rm Delete a partition.
To create partitions on the newly installed storage disk by using parted (and only
if you haven’t done so via fdisk), follow this process:
1. Type parted /dev/sdb to edit the partition table for the second (new)
disk.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
5. Type quit to write changes to the partition table and exit parted.
GNU Parted is a critical tool for any sysadmin. The utility recognizes and can resize
New Technology Filing System (NTFS) partitions, which are commonly found on
Windows Servers.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The output of the blkid command displaying the UUID for the /dev/sda1 partition.
The ext toolset enables a variety of administrative tasks to manage the filesystem. These
tasks are covered in a later section.
To format the new partitions, use the mkfs command. The command expects to
know the desired filesystem and a target partition.
To place the ext4 filesystem on the second partition on the new disk, type:
# mkfs.ext4 /dev/sdb2
The mkfs also recognizes a slightly different syntax. The following command
achieves the same result as the example command above:
mkfs -t ext4 /dev/sdb2
The mkfs command overwrites existing data on the partition, making that data
difficult or impossible to recover. Use it carefully!
To format the second partition on the new disk with the XFS filesystem, use the
mkfs command but with a different option:
# mkfs.xfs /dev/sdb2
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
XFS Tools are available to help manage the filesystem. Management tasks include
resizing the filesystem and gathering information. The tools are covered in a later
section.
Observe that umount is a slightly confusing way of unmounting. The command and
the concept are not spelled the same.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Note that the syntax is similar to the mv or cp commands—from here to there. The
command could be interpreted as “attach the partition found at /dev/sdb2 to the
directory found at /projects.”
To test that the storage area is attached and usable, use the du and df commands.
External storage devices such as USB drives are mounted similarly. The path to the
device is specified along with the desired mount point. For removable drives, this
mount point is often a subdirectory of the /mount directory.
Assuming the USB drive is identified as sdc, use the following command to mount
the USB storage device:
$ mount /dev/sdc /media/usb
Sometimes there is confusion with the use of the word “filesystem.” One use involves
the format of a partition used to store data, such as ext4 or XFS. Another useinvolves
the organization of directories in a logical tree, such as the Linux Filesystem Hierarchy
Standard.
Output from the du -h /boot command displaying the size of each file in the directory.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The result shows files and directories consuming space in the /projects
directory. Add the -h option to display the capacity in a human-friendly format;
otherwise, the output will display in bytes, which may be difficult to translate.
Next, check the storage space in use by using the df command. The syntax is the
same as for du, with the command being: df -h /projects
Output from the df -h /dev/sda1 command displaying the size of the partition.
To see a summary of space in use on all disks, type df without any arguments.
Both utilities are important to troubleshooting, testing, and capacity planning.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
2. Confirm that Linux sees the storage device by using tools such as hwinfo,
lsblk, and lsscsi.
3. Partition the drive with fdisk or parted.
5. Manually test mount the storage capacity to a mount point by using the
mount command.
6. Ensure the storage space is usable by copying actual data to the location
using cp.
Manage Filesystems
Filesystems such as ext4 and XFS may require periodic maintenance. You may
wish to relabel the filesystem to something more descriptive or configure tunable
performance parameters. The filesystem may need to be expanded or shrunk
when using tools like parted to resize partitions. Here are several ext4 filesystem
management tools.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
XFS Tools
There are many tools that enable you to work with the XFS file system.
xfs_growfs Expand the XFS file system to fill the drive size.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The three levels of the Logical Volume Manager. Physical volumes combine to form the volume
group, which is then divided out in logical volumes to meet storage needs. (Images © 123RF.com.)
LVM provides a great deal of flexibility. Additional storage capacity can be added
to the VG and granted to the LV to provide storage space without interrupting or
reconfiguring user resources.
LVM maps whole physical devices and partitions (e.g., /dev/sda1, /dev/sdb2,
and so on) into one or more virtual structures called volume groups. Within these
volume groups are one or more logical volumes. Ultimately, the logical volumes
become the storage devices that the system, user, and applications work with.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The /dev/mapper/ directory contains all of the logical volumes on the system
that are managed by LVM. Devices in this directory are typically formatted as:
/dev/mapper/<volume group name>-<logical volume
name>
In some cases, this directory may just include links to the actual logical volume
location.
Many distributions support LVM, and several actually place the root file system on
logical volumes during installation.
Compared to traditional physical partition management, LVM provides the following
benefits:
• Dynamically create, delete, and resize volumes without having to reboot the
system.
• A logical volume can exceed the size of any one physical device (as long as it
doesn’t exceed the total size of devices in the volume group).
• Create virtual snapshots of each logical volume so you can quickly and easily
revert a volume to a specific state.
One potential downside to LVM is that the initial setup can be somewhat complex.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Storage Deployment
5
2. What role does the partprobe command play in the process of adding
storage?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 7C
Manage Other Storage Options
6
In some cases, direct-attached storage, such as internal drives, will not be sufficient
for the reliability, performance, or scalability requirements of a project. In such
cases, larger storage solutions, such as RAID, NAS, and SAN storage, may be
required. For security reasons, disk contents may need encryption.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Before encrypting a device, it’s a good idea to overwrite its contents with random data
or all zeros. This ensures that no sensitive data from past use remains on the device.
The shred command can be used to securely wipe a storage device in this manner.
The syntax is shred [options] {file-name}
RAID Standards
Three common RAID standards are RAID 0 (disk striping), RAID 1 (disk mirroring),
and RAID 5 (disk striping with parity).
Disk striping (RAID 0) relies on at least two disks. The disk partitions are divided
into sections called stripes and data is written sequentially through the stripes.
Because RAID 0 provides no fault tolerance, it is mainly used for performance
benefits with application data that does not need to be preserved (such as caching).
Disk mirroring (RAID 1) duplicates data on two storage disks. This provides
complete redundancy (100% of the data resides on each disk) but is a relatively
inefficient use of storage capacity. RAID 1 usually results in faster reads than a
single standalone disk.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Software RAID
Most servers contain hardware RAID controller cards. These cards provide a
performance benefit and allow flexible configurations. However, operating systems
such as Linux can configure and manage storage devices like RAID arrays. In Linux,
the mdadm command manages RAID. Think of the mdadm command as “multiple
device administration.”
To display information on a RAID array, use the mdadm command with a series of
flags. The flags set mdadm into different modes, such as Assemble, Monitor, and
Build.
The mdadm utility also provides a dynamic file that displays messages and status
information related to RAID arrays. To display the contents of this file, type:
cat /proc/mdstat
The output of the cat /proc/mdstat command displays the RAID level the
kernel currently supports and any current RAID configurations. The RAID levels are
referred to as “Personalities” and will exhibit values such as [raid1] or [raid5].
Any configured RAID arrays are identified on an md_d0 line, which consists of the
current RAID configuration and a list of disks that are members of the array. For
example, the output might look like the following:
Personalities : [raid0] [raid1] [raid5]
md_d0 : active raid1 sde1 sdf1
Network-Attached Storage
A network-attached storage (NAS) device is a dedicated network node that
provides inexpensive, scalable, and easy-to-configure storage. The device is
essentially an enclosure of storage drives managed by a minimal open-source
operating system.
Lesson 7: Administering Storage | Topic 7C
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The SMB protocol provides users with shared access to files and other resources
across a local area network (LAN). SMB clients make requests for resources
to SMB servers, which respond and provide the appropriate level of access. This
protocol is primarily used with Windows computers. However, SMB-compatible
software called Samba helps interface Linux and Windows hosts running network
shares.
Common Internet File System (CIFS) is a specific implementation of SMB.
Microsoft designed it as a successor to SMB version 1, but SMB versions 2 and 3
superseded it. However, Linux still uses the CIFS name in some of its tools, though
these tools support newer versions of SMB.
Network File System offers similar functionality to SMB, but the protocols are not
compatible. NFS is preferred in situations where Linux clients access Linux servers.
In environments that are a mix of Windows and Linux, the SMB protocol is the
better choice.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Storage-Area Network
A storage-area network (SAN) is a significantly more expensive and complex
option. However, it is usually faster and more scalable. Dedicated storage devices
are managed as a single unit and are controlled by one or more Linux servers.
Network protocols communicate between the management nodes and the storage
devices. Two common protocols are Fibre Channel (FC) and Internet Small
Computers Systems Interface (iSCSI).
In some cases, Fibre Channel devices may be attached to the server. The fcstat
command displays information about existing Fibre Channel adapters. These
adapters are typically found in conjunction with SAN solutions.
The syntax for the fcstat command is fcstat [options] {driver-
name}
For example, to display driver-collected information for the Fibre Channel
connection, type:
fcstat fcs0
The fcstat command also contains subcommands that provide additional detail,
such as link statistics. The syntax for displaying link statistics is:
fcstat link_stats {link-number}
A network segment featuring a SAN using Fibre Channel protocols. (Images © 123RF.com.)
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Identify multipathd
One common attribute of SAN implementation is multipathing. This concept refers
to providing multiple connections between a server and its SAN storage devices.
The benefit is fault tolerance (in the event one path becomes unavailable) and
performance (load balancing across paths). In Linux, multipathd is responsible
for checking and displaying information about paths.
The multipathd daemon manages the paths and reconfigures the network map as
needed to react to changes in paths (such as failures).
The multipathd command displays information about the state of paths.
For example, to display the current configuration, type multipathd show
config.
Network File Systems for SAN
Like standard file servers and NAS devices, SAN storage solutions may be
configured with NFS or SMB network filesystems. Users can connect to these shared
resources to access files and directories.
Note that the NFS and SMB protocols provide communication between network
clients and the filesystem. These operate on a higher level than iSCSI and Fibre
Channel, which govern the communication between the hosting server and
connected SAN storage.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Storage Options
7
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 7D
Troubleshoot Storage
4
Disk Performance
Storage devices read and write data, an action referred to as input/output (IO). Even
with solid-state storage, drive actions may be one of the slowest tasks the server
performs. Factor in many users reading and writing simultaneously, and it’s easy to
see why disk performance is a concern for sysadmins.
NVMe storage disk detection may fail during the initial installation of the drive or
during later boot sequences. Ensure the BIOS settings are correct for the storage
disk type and that the GRUB2 configuration file does not contain typos when
referencing the NVMe drive.
NVMe disks are also prone to failure from heat, so proper cooling is essential, and
frequent backups are recommended.
High Latency
Latency refers to the time it takes for data to travel across the communications
media. In the case of direct-attached storage (such as local storage disks), the media
is the motherboard, disk controllers, and connecting cables. Latency is any delay
as the data travels the path. Some latency is inevitable; the goal is to ensure the
latency is acceptable within the server’s performance requirements. The goal is for
this number to be as low as possible.
The organization’s individual needs define storage performance. Often these
needs will vary by service. For example, web services have different performance
requirements than database services. Hardware specifications, software, and
specific configurations impact disk IO performance and wait times. These variables
make it difficult to identify ways to decrease latency and improve throughput.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Low Throughput
Throughput is a measure of the storage device’s effective bandwidth, or ability
to move data to or from the drive. The goal is for this number to be as high as
possible.
Managing disk performance begins with purchasing a server with the appropriate
storage specifications. These specifications impact the drive’s throughput. Often,
this means SCSI or SAS storage, as SATA may not perform well enough for servers
with many storage devices. The drives themselves are important, too, not just the
control interface. For physical disks, the RPM value should be as high as possible—
often 15,000 RPMs.
Organizing storage into RAID arrays may also provide a performance benefit in
addition to fault tolerance. Hardware RAID controllers are typically preferred.
Measuring IOPS
You can check performance by keeping track of the Input/Output Operations
per Second (IOPS). Identifying throughput to ensure that disk performance is
acceptable on a Linux server involves the iostat and ioping commands.
The iostat utility generates reports on CPU and device usage. For storage, it
provides input and output statistics for block devices and partitions. Using the -d
option to specify device information only, the iostat command lists the following
statistics for each storage device:
• Transfers (I/O requests) per second (tps).
You can use this report to monitor how a storage drive is being used and to identify
any potential bottlenecks. For example, a faulty drive might have lower reads and/
or writes per second than expected. You can also use the report to help you decide
how to best distribute the I/O load between the available devices.
The syntax of the iostat command is iostat [options] [device
names]
The ioping command generates a report of device I/O latency in real time. It will
continuously “ping” the specified device with requests and print information about
each request at the command line. By default, this information tracks how long it
took an I/O request to finish. Aside from specifying a device to test, you can also
specify a path name to test whatever device is associated with that path.
Consider using ioping to troubleshoot latency issues with storage devices,
especially if you believe your read and/or write speeds are slower than they
should be.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Both iostat and ioping are useful for troubleshooting I/O errors that may
occur due to failing drives, performance issues, or storage disk driver problems.
Deadline
The Deadline scheduler performs sorting of I/O operations using three queues: a
standard pending request queue, a read first in first out (FIFO) queue, and a write
FIFO queue; the latter two are sorted by submission time and have expiration values.
When a request is submitted, it is sorted into the standard queue and placed at the end
of its appropriate FIFO queue. When the top request of the FIFO queue becomes older
than the queue’s expiration, the scheduler stops working with the standard queue and
starts servicing requests from the top of the FIFO queue—in other words, it switches to
the oldest requests. This ensures that the scheduler doesn’t “starve” a request for too
long. This makes it ideal for certain workloads like multi-threaded workloads.
CFQ
This refers to the Complete Fair Queuing (CFQ) scheduler. It is the default scheduler
for modern versions of the Linux kernel. In this scheduler, each process is given
its own queue, and each queue has an interval by which it is accessed (its time
slice). The scheduler uses a round-robin system to access each queue and services
requests from these queues until either their time slices or requests are exhausted.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
When the queue is empty, the CFQ waits 10 milliseconds for any new requests in
the queue, and if it doesn’t see any, it moves on to another queue. Like the deadline
scheduler, this helps to minimize request starvation. Its advantage is that it services
processes fairly and provides good performance in most workload situations.
Noop
Noop is the simplest scheduler and does not sort I/O requests, but merely
merges them. This can be ideal in situations where the device or its storage
controller performs its sorting operations. It can also benefit devices that don’t
have mechanical components requiring seek time, like SSDs and USB flash drives,
because this scheduler doesn’t expend much effort in reducing seek time. However,
the previous two schedulers are preferred in most other situations.
Set the scheduler on a particular device by modifying the scheduler file located at
/sys/block/<device name>/queue/scheduler.
Setting the scheduler is as simple as echoing the desired option to this file, as in:
echo noop > /sys/block/sda/queue/scheduler
Note that this sets the scheduler for runtime only; the setting will revert upon
reboot. To ensure your changes persist, you must modify the system’s boot loader
configuration.
Capacity Issues
One of the great challenges for sysadmins is managing storage capacity. Storage
space is relatively inexpensive, and there are many storage options, from direct-
attached storage to network storage to cloud storage. Users often see no need to
delete data, and many files are kept just in case they’re needed.
Display Storage
To manage storage, begin by understanding what storage devices exist. Tools such
as blkid and lsblk display information about recognized storage devices. Another
resource is the /proc/partitions file, which delineates the partitions that
Linux is aware of. Display this information with the cat /proc/partitions
command. Finally, both fdisk and parted display drive and partition
information.
If the storage devices are organized using LVM, commands such as pvdisplay,
vgdisplay, and lvdisplay provide information about the configured
volumes.
The mount command displays all attached storage and may be useful for
understanding exactly where particular storage devices reside (they won’t always
be local).
Find Issues
The du and df commands are commonly used to gather specific storage utilization
information. Both tools are flexible and have many options.
Use df to get general information on the mounted storage capacity. Use df with
a specific device path to gather more information about a given partition. For
example:
# df
# df /dev/sda2
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Inode Exhaustion
Each file created on a Linux partition is given an identifier by the filesystem. This
identifier—called an inode—uniquely identifies the file. Filesystems such as ext4
have a limited number of inodes available to allocate. While the available number is
very high, filesystems that store many small files may eventually run out of inodes
to assign. This is referred to as inode exhaustion.
If you receive an error message such as “No space left on drive” or “Cannot create
directory” but there is still storage capacity available on the drive, you’ve likely
encountered an inode exhaustion issue.
You can use the df and du commands again in this case to troubleshoot this issue.
The df -i command displays the percentage of inodes consumed and available
in the IUse% column of the output. If you have available storage space but are
receiving an error message when creating files, check this value.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Filesystem Issues
Filesystem corruption often occurs when Linux servers are not shut down
gracefully. This is more prevalent with non-journaled filesystems (most modern
filesystems, such as XFS and ext4, are journaled).
The fsck utility can be run on disks to detect and attempt to correct issues. Note
that the volume must be unmounted for fsck to be run against it. The fsck
command was discussed in Topic 7B.
Filesystem mismatch errors may be reported, especially after changes to the
filesystem or partition size. This issue may occur when an application (or the
system) attempts to write to the storage disk location where the filesystem
superblock resides. It may also happen if the storage disk itself is damaged or if
there is a misconfiguration of the filesystem or partition table.
You may be able to recover and access data by unmounting the filesystem (in
rescue mode) and using a repair utility such as fsck.
Device Issues
There are common troubleshooting steps for storage devices. Begin by ensuring
Linux is aware of the device. Commands such as blkid and lsblk display
storage device information. The hwinfo command can be filtered to show storage
disks, too. If the disk is not detected by Linux, confirm its physical connectivity
by checking the interface and power cable for a tight connection. If the drive is
installed in a motherboard slot, confirm the connection is good.
Once physical connectivity is established, Linux should be able to detect the drive.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
If issues with the filesystem are suspected, use the various ext4 or XFS tools to
confirm the status of the filesystem.
Verify the drive can be mounted by using the mount command. First, create
a directory that acts as a mount point, and then attach the storage capacity to
the directory. If the partition is not automatically mounted at boot, check for
typographical errors in /etc/fstab or the systemd.mount file.
Network file servers share directories by using NFS or SMB to make storage capacity
available from across the network. These remote filesystems may also be mounted.
When troubleshooting mount issues with remote filesystems, first ensure network
connectivity is established by using tools such as ping and ip addr. Next, verify
the network file server has made the directories available on the network and that
the user has permission to mount and read/write to the directories.
Network tools such as ping and ip addr are covered in a later Lesson.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Storage Troubleshooting
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 7
Summary
5
Proper administration of storage directly impacts the server’s performance and the
ability of users to access critical data. System specifications, such as SATA, SCSI, and
SAS play an important role, as do design decisions such as traditional partitioning
versus LVM-based storage. In fact, it may be more efficient to store data on NAS,
SAN, or cloud-based devices rather than on internal storage disks. Monitoring
performance and troubleshooting storage disk issues are common sysadmin tasks.
Guidelines
These best practices and guidelines are provided for your use as revision tools or as
quick references in your job role.
• Understand the process of configuring storage with traditional partitions.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
Linux sysadmins must identify and configure hardware resources. First, administrators
must be able to find hardware information using a series of commands to identify CPU,
memory, bus, and other hardware devices. Next, sysadmins manipulate processes
consuming hardware resources to optimize and troubleshoot the system. Often the
focus of this optimization is the CPU and memory. Finally, the Linux kernel—the core
of the operating system—may be managed to maintain performance, enable modern
features, and provide compatibility with current hardware.
Lesson Objectives
In this lesson, you will:
• Gather hardware information.
• Manage processes.
• Manage memory.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 8A
Gather Hardware Information
2
• USB controllers
• Graphics cards
• Print devices
One common option used with hwinfo is --short, which returns abbreviated
information on the resources. Using either hwinfo or hwinfo --short
displays information on all detected hardware. However, it’s more likely you’ll want
details for specific devices.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The output from dmidecode may be very long. Use the pipe redirector to display
the information in a pagination utility such as less or more.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Recall that in the previous section, you displayed storage device information from the
/dev/sda file.
It’s possible to test the udev device manager by using the monitor subcommand.
Run udevadm monitor and then attach a new USB device to the system. You
should see the device is detected and the output shows device details.
Information can be displayed for specific attached devices by using the udevadm
command. For example, type udevadm info /dev/sda to see storage
device information.
The term “storage device” represents traditional magnetic hard disk drives, modern
solid-state drives, USB flash drives, and any other media used to store data.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Three other device files are listed: null, zero, and urandom. These are known
as the special device files.
The /dev/null special file is a writeable location that is used as a target for
generated data that should be discarded. This data may be error messages that are
redirected to /dev/null by using the 2> redirector.
The /dev/zero file is a way of filling storage capacity. For example, using the
dd command, a sysadmin can create a file of a specified size as part of testing. For
example, to create a one MiB file named foo.txt, run the following command:
# dd if=/dev/zero of=foo.txt count=1024 bs=1024
This command uses /dev/zero as the source of data that fills the file to its
specified size.
The /dev/urandom file can create is a source of random characters for
tasks such as creating completely randomized passwords. Take care of how this
command runs on low-performing systems at the risk of consuming all available
resources.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
This section covers installed memory, not how that memory is being utilized. Memory
utilization is covered in a future section.
Memory Tools
Use the lsmem command to display memory blocks, including their size and state
(online, offline).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
File contents might be useful when troubleshooting memory. For example, if you
believe the system has 64 GB of RAM installed, but only 32 GB are reported, you
can use this file to see what memory Linux recognizes. Doing so may help identify
which sticks of RAM are not recognized (and therefore, may not be seated in the
motherboard correctly).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Hardware Information
3
4. What file has the make, model, number of cores, and other details
about the CPU?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 8B
Manage Processes
5
Processes are instances of running code. These may be parts of the OS, services,
applications, or scripts. Some processes are executed as part of the system, while
others are initiated and managed by users. Each process is assigned a unique
process identification number (called a PID), and this number is used to manage
the process throughout its life cycle. This section covers process management,
troubleshooting, and optimization.
Processes Concepts
Process management is an essential part of performance monitoring and
troubleshooting on Linux systems. Sysadmins manage processes with tools that
indicate their resource consumption, status, and priority levels.
What Is a Process?
A process is an instance of running code. Applications reside dormant on the
storage disk until executed by a command or initiated by the system. When
executed, the processor loads an instance of the application into memory and
manages it . At that point, it is a running program.
As with other system functions, processes are managed by number rather than
name. These numbers are called process identifiers (PID), and a PID is almost
always used to manipulate the process. Most processes start and stop without
issue, but periodically administrators may need to see what processes are running
or discover which processes are consuming large amounts of system resources.
Manipulate Processes
Sysadmins view and manipulate processes as part of system management. Many
basic commands display specific process information. The most important basic
information to acquire is the PID.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
One or more process IDs are displayed. The -l option is useful with pgrep
because it displays the actual process name along with the PID.
Much like pgrep, the pidof command also displays process ID information. The
primary difference between the two commands is that pidof requires accurate
knowledge of the process name, whereas pgrep searches for a string that may
be contained within the name. For example, when searching for SSH processes,
pgrep ssh will display any process containing the “ssh” string, while pidof
ssh will likely return nothing because no process name exactly matches the “ssh”
string.
Output of the pidof ssh-agent command. Note the use of the full process name.
Process Signals
Sysadmins directly impact processes by using the PID, as displayed by pgrep or
pidof. So what activities do administrators undertake? Often, the process needs
to be ended. This usually occurs when the application is closed, such as when
quitting Vim. However, sometimes a process does not end gracefully, and the
administrator must directly manage it using signals.
Three ways of ending processes are SIGTERM (signal -15), SIGKILL (signal -9), and
SIGHUP.
Before covering these signals it’s important to understand how applications shut
down, or exit. A graceful exit uses SIGTERM. It is performed to avoid data loss
or corruption and ensures the program shuts down according to its design. This
means the program completes its regular shutdown procedure and no longer
resides in memory or has a process ID associated with it. For example, when using
Vim, the :q command initiates a graceful exit.
Sometimes, however, the graceful exit fails or is unavailable. In that circumstance, a
non-graceful exit is required. This is referred to as “killing” the program. The SIGKILL
signal is usually a last resort.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The SIGHUP signal requests that a process exit when the terminal running the
process closes. It’s assumed that if the terminal closes, the user is no longer
interested in the results of the command.
The kill command is used to pass these signals to processes. For example, to
initiate a graceful exit, type:
$ sudo kill -15 {PID}
Likewise, kill -9 {PID} sends a SIGKILL message to the process.
SIGTERM is the normal kill signal sent to applications. SIGKILL is used when an
application refuses to exit via SIGTERM. SIGHUP tells the application to exit when
the shell closes.
An alternative command to kill is the pkill command, which also references
the process by PID. Additionally, pkill can also terminate processes based on
name, users, and other criteria.
For example, pkill can kill all processes associated with the Firefox application
(which may have many spawned processes):
$ sudo pkill -15 firefox
The upper portion of top’s output displays useful information including system
uptime, memory consumption (both physical and virtual memory), and process
statistics. Sysadmins rely heavily on top because it is one of the most useful
monitoring programs.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Value Purpose
%us Displays CPU time spent running user processes.
%s Displays CPU time spent running the Linux
kernel.
%id Displays CPU idle time. (If this is high, the CPU is
working hard.)
%wa Displays I/O wait time. (If this is high, the CPU is
ready to work but waiting for I/O access.)
%st Displays Steal. (If this is high, a virtual CPU is
waiting for access to the physical CPU.)
Processor utilization metrics.
Note that with %st, you are working with a virtual CPU (vCPU) in a virtualized
environment. For example, if a physical Linux server hosts two Linux virtual
machines, then the vCPUs of the VMs may be awaiting access to the physical CPU
in the host server. If this value is high, the VMs may put too much strain on the
physical processor resources of the host server.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The ps Command
The standard command to display process status is ps. This command has many
options to filter and display the exact process information you need.
The ps command is a perfect example of why man pages are so helpful. The
command has many possible combinations, and it may be difficult to remember
them all.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Perhaps you need to see files opened by a specific user. In that case, the -u
{username} option filters the output for the specified user. Another option is to
display files opened by a specific process, such as a database or webserver. The -c
{process} option displays this information.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The results of uptime are also displayed at the beginning of the output of the
top command.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
One way of displaying parent and child processes is by using the pstree
command.
The sleeping state indicates a process awaiting access to resources. The state is
a normal consequence of resource sharing. The sleep state has two substates:
interruptible and uninterruptible.
• Interruptible: The process waits for a specific time slot or event before
attempting to enter the running state.
Exiting processes can get stuck in the zombie state if their parent process exits
before releasing the child process. These processes must be manually killed by the
sysadmin.
Runaway Processes
Bugs or misconfigurations may lead some applications to steadily consume more
resources, eventually congesting the system and impacting its performance. These
processes may not always terminate correctly.
It’s best to attempt to terminate the process gracefully by using a command such as
sudo kill -15 {PID}. Because the process is already misbehaving, a more
forceful attempt such as sudo kill -9 {PID} or pkill may be necessary.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
High Utilization
Linux systems that display high CPU utilization and load averages may be
suffering from a number of issues. High utilization may be due to software bugs,
misconfigurations, untuned default settings, or properly functioning but high-
demand applications (such as rendering, databases, or dev programs).
Since Linux itself is relatively well-tuned, the problem is likely with a user
application. Use commands such as ps or top to identify processes consuming
resources and why those processes were launched.
Utilization at or near 100% indicates the processor’s demand is too high. The lower
this percentage is, the more CPU capacity is available to additional workloads.
The difference between nice and renice is that nice is used when starting
a new application, and renice is used when changing the priority of a running
process.
Job Control
Process management is usually considered from a system-wide perspective and
handled by the root user (system administrator). Processes represent all running
code on the system. Individual users, however, can manage scripts or applications
that they have started.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Manage Jobs
Jobs are a subset of processes and refer specifically to any process the current
user has started. Users can display processes they are running by using the jobs
command. The resulting output shows a numbered list of all existing jobs. These
job numbers are used to identify and manipulate the processes.
Normally, when a command is executed, it processes in the foreground, consuming
the shell until the command completes. Upon completion, the command exits and
the shell prompt is available to the user to run another command.
For example, imagine a backup script that takes 10 minutes to complete. Until the
script completes, the command prompt is unavailable to the user. In this case, the
script is running in the foreground as a job associated with the user. The system
sees the script as a process.
However, scripts and other commands can be executed in the background. The
process or script runs, but the shell is returned to the user rather than consumed
until termination. To background a job, such as the backup.sh script, append the
ampersand & to the command:
$ backup.sh &
You can display the status of the jobs by using the jobs command. When a job
is executing in the background, you cannot see its status. The jobs command
displays current jobs and identifies each with a number enclosed by square
brackets.
What if you need to see the actual process running (for example, to check the status of
a progress bar or to ensure the program hasn’t unexpectedly halted)? You can move a
backgrounded job to the foreground by using the fg command, % symbol, and the job
number. For example, to foreground the script with a job number of 1, type:
$ fg %1
The job is now running in the foreground for you to observe.
Pause the job with Ctrl+Z, and then background it with bg %[1]. This
command returns the job to the backgrounded status to remove it from the shell.
$ bg %1
Check the status again by using the jobs command.
Jobs can also be managed by using the Ctrl meta key. The following key
combinations are useful for managing jobs:
• Ctrl+Z - Pauses a job temporarily, often so it can be moved to the
background.
• Ctrl+D - Exits the program and logs the user out of the current session.
• Ctrl+C - Stops a running process.
The nohup (“no hangup”) command prevents a process from ending when
the user logs off. For example, if an administrator launches a backup script and
then logs off the system, the script would stop running. By placing the nohup
command in front of the normal command, the script would continue even after
the administrator logged off.
The syntax of the nohup command is nohup {command/script}
Lesson 8: Managing Devices, Processes, Memory, and the Kernel | Topic 8B
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Processes
6
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 8C
Manage Memory
5
Random Access Memory (RAM) provides a temporary, volatile, and fast storage
area for the processor. Without sufficient RAM, users cannot open applications,
and the system would be unable to provide services. Memory is a finite resource
on computer systems and sometimes there is not enough storage capacity in RAM
to support the system’s services. In this case, additional storage capacity can be
borrowed from storage drives, such as solid-state drives or hard disk drives. This
borrowing is referred to as virtual memory. While these devices provide additional
capacity, they often result in a slower system than RAM.
This section identifies system memory issues and covers the use of virtual memory.
Virtual Memory
Both Random Access Memory (RAM) and storage devices are storage locations.
While disks are nonvolatile storage locations that maintain data even when power
is removed, RAM is a temporary storage location. However, both locations are used
to store data. RAM is a much more finite and limited system resource than storage
disks. In addition, there is usually far less storage capacity in memory than on a
drive.
Each process that runs is assigned a quantity of RAM, and because this memory is
finite, a system’s entire memory can be consumed. On old systems, this resulted
in an “out of memory” error that required users to close some applications before
launching others. Modern operating systems, however, swap or trade information
between RAM and the storage disk. Additional storage space is borrowed from the
storage disk and used as RAM. This concept is referred to as “virtual memory,” and
the data is “swapped” between the two storage locations.
However, storage devices are substantially slower than RAM, so swapping places a
significant performance hit on the system.
Swap Space
Swap space is a partition on the storage device that is used when the system runs
out of physical memory. Linux pushes some of the unused files from RAM to the
swap space to free up memory. Usually, the swap space equals 1.5 x the quantity
of RAM.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
An example of swap space operations. Here a user attempts to open the httpd program (1) that
exceeds the available space in the RAM. The system moves the mariadb file into the swap partition
(2) to make space for httpd in the RAM. (Images © 123RF.com.)
• File system swap: configured primarily upon installing Linux and used by the OS
as an emergency resource when the available swap space runs out.
Swap files are created for storing data that is to be transferred from a system’s
memory to a storage device. They are dynamic and change in size when data is
moved in and out of memory.
A swap partition is an area of virtual memory on a storage device to complement
the physical RAM in the computer. Linux systems use swap partitions because they
perform better than swap file systems.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Memory Exhaustion
It is critical, particularly on Linux servers, to ensure the system has plenty of free
memory. Too little RAM greatly reduces system performance. On Linux systems
hosting major business applications such as databases or webservers, such
performance issues can impact the entire organization.
The server’s specifications should include more memory than the system is
anticipated to need.
Output of the free -h command. Observe the used and free columns.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The vmstat command displays the use of virtual memory. Recall that virtual
memory involves swapping data between two storage locations: physical
memory and storage disk(s). Such swapping is time-consuming and reduces the
performance of the system. Significant use of virtual memory indicates that the
system needs more memory or a reduced workload.
Because the use of virtual memory indicates the system is overwhelmed, you want
the utilization number from vmstat to be low.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Memory
6
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 8D
Manage the Linux Kernel
4
One of the defining features of Linux is that it is modular, enabling you to adjust
low-level system configurations at boot and during operation. This provides you
with a great deal of flexibility in adjusting how your system runs and what types of
devices it can leverage. In this section, you’ll explore more about the Linux kernel
and some of its features, and then you’ll customize the kernel to meet your unique
business needs.
You’ll begin by identifying some of the key concepts and components that make
up the Linux kernel. This will give you a better sense of what services the kernel
provides and how you might go about customizing those services.
Device Drivers
A device driver is a software program that enables a computer’s operating system
to identify the characteristics and functions of a hardware device, communicate
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
with it, and control its operations. It acts as an interface between the operating
system and hardware devices such as storage drives, printers, scanners, monitors,
and keyboards. Device drivers can be included in the operating system or installed
on-demand.
When the system boots, drivers are loaded with the kernel, enabling Linux to work
with various devices. While the kernel and drivers are separate pieces, they work
together to allow Linux to use the device’s features. For example, printer drives let
Linux know what features the printer has (color, duplexing, and collation) and how
to expose those features to the user. The drivers are not part of the kernel and can
therefore be updated without making changes to the kernel.
The latest Linux kernel and stable releases can be found at www.kernel.org.
By default, uname prints the name of the kernel—Linux. You can view the kernel
version number of your current system by using the uname -r command. You
can also enter uname -i to view the hardware platform. To print all information,
enter the uname -a command.
• They extend the functionality of the system and avoids rebuilding and rebooting.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
A kernel module file consists of a .ko extension. Modules built for a specific kernel
version may not be compatible with another version of the kernel.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Module Directories
The /usr/lib/ directory contains shared libraries and binaries for general
programs and software packages. The files in this directory are not meant to be
executed by the user or custom shell scripts. More specifically, the /usr/lib/
modules/ directory contains the modules of different kernel versions installed.
It holds a directory named after the kernel’s version number. Inside this directory,
modules are stored across various subdirectories based on their categories. For
example, a Bluetooth driver may be stored in:
/usr/lib/modules/<kernel version>/kernel/drivers/
bluetooth/
Inside /usr/lib/modules/<kernel version>/kernel/ are several
subdirectories, some of which are described in the following table.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Kernel Panic
A kernel panic is a mechanism by which the system detects a fatal system error
and responds to it. A fatal error typically results in the system becoming unstable or
totally unusable. Software that handles kernel panics will display an error message
to the user and dump the current state of kernel memory to a storage device for
later debugging. Depending on how the system is configured, the panic handler will
either reboot the system automatically or wait for the user to do so.
In Linux, kernel panic can happen for many reasons and at any point during
operation, but it is usually experienced during the boot process. Common causes
include the following:
• The kernel itself is corrupted or otherwise improperly configured.
• The systemd program is not executed during boot, leaving the system
unusable.
• The kernel cannot find or otherwise cannot mount the main root file system.
The equivalent of a kernel panic in Microsoft Windows is the well-known Blue Screen of
Death (BSoD).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
• Did you configure any nonstandard settings during or after the installation?
The systemd management system includes a very robust journaling and logging
component that can be useful for understanding system and application crashes.
Note that systemd journal is a different and independent service from rsyslog, the
traditional Linux log file service. The journal is maintained by the journald daemon
and draws information from more sources than rsyslog. It also displays the log files
more easily by using the journalctl command and a series of options.
For example, to display journal entries for SSH, type:
$ sudo journalctl -u ssh
The journal can be helpful when troubleshooting system and application crashes
that occur frequently due to the level of detail provided and the robust filtering
options.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
The Linux Kernel
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 8
Summary
4
Linux provides many commands to display and manage system hardware. These
commands allow sysadmins to understand the system’s current configuration,
including drivers, OS kernel (and its related modules), and recognized hardware.
In addition, the processes consuming hardware resources must be optimized
and managed. Finally, for both stability and security, the OS kernel must be kept
up-to-date.
Guidelines
These best practices and guidelines are provided for your use as revision tools or as
quick references in your job role.
• Consider whether what’s reported in the /proc and /dev directories is
hardware Linux recognizes, not necessarily the hardware installed. Hardware
that is not properly connected may not be displayed.
• Processes are displayed by using commands such as ps, top, and htop.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
Linux servers (and Linux workstations, too) enable users and applications to
complete tasks that drive business. This function begins with the initialization of the
Linux kernel by systemd and SysVinit. These utilities start any configured services,
such as SSH for remote administration or make websites available via Apache.
Finally, sysadmins must configure the system for the comfort and practicality of the
users and their preferred locale settings.
Lesson Objectives
In this lesson, you will:
• Manage system services.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 9A
Manage System Services
2
Most Linux systems initialize using either the newer systemd or older SysVinit
processes. Both initialization programs start and manage services and daemons
that make the server useful. Each program also has a separate group of
management commands. Systemd is very robust and includes the ability to manage
boot options, service startups, and even scheduled tasks by using unit files and
directives. This Topic covers the use of both management systems.
• NFS service: Allows remote access to exported directories and relies on several
daemons, including nfsd and mountd.
• NTP service: Synchronizes time among network servers and relies on ntpd.
System Initialization
System initialization is the process that begins when the kernel first loads. It
involves the loading of the operating system and its various components, including
the boot process. System initialization is carried out by an init daemon in Linux—the
“parent of all processes.” The init daemon refers to a configuration file and initiates
the processes listed in it. This prepares the system to run the required software.
The init daemon runs continuously until the system is powered off, and programs
on the system will not run without it.
On Linux, there are two main methods that initialize a system: systemd and
SysVinit. Which method is active on your Linux system will affect how you manage
services on that system.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
systemd
The systemd software suite provides an init method for initializing a system. It
also provides tools for managing services on the system that derive from the init
daemon. The systemd suite is now the dominant init method in modern Linux
distributions, and was designed as a replacement for other methods like SysVinit.
The systemd suite offers several improvements over older methods. For example,
it supports parallelization (starting programs at the same time for quicker boot)
and reduces shell overhead. In systemd, Control Groups (cgroups) are used to
track processes instead of process IDs (PIDs), which provides better isolation and
categorization for processes.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Note that enabling a service and starting a service are two different things. Enabling a
service configures the service to start the next time the server starts. This merely sets
the default status in the configuration file, and it does not start the service in the cur-
rent runtime. Starting a service turns on the service in the current runtime but does
not set its default startup status in the configuration file. Usually, when a new service
is installed, the sysadmin will both start the new service and enable it.
The term "persistent" describes a setting that remains in place even after a reboot.
Enabling a service means it will start each time the system boots, whereas starting a
service means it will run for the current system's runtime but will revert back to its
default status upon reboot.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
There are many systemd unit file types, with .service, .timer, .mount, and .target as
the primary examples.
Unit files include [sections] followed by directive=value statements. Two
common sections are [Unit] and [Install]. The [Unit] section typically manages
the unit’s relationship to other units, including Wants= and Requires= directives.
The [Install] section specifies the results of enable and disable actions by the
administrator. This includes WantedBy= and RequiredBy= directives.
Note the [Unit] section and four directives in the example image below.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/sbin/simple-firewall-start
ExecStop=/usr/local/sbin/simple-firewall-stop
[Install]
WantedBy=multi-user.target
Another example is an event that runs at 9:00 p.m. on the first Friday of the month:
• OnCalendar=Fri *-*-*1..7 21:00:00
Systemd .timer files can be used to replace schedulers such as cron. Schedulers
permit administrators and users to specify when an event should occur. The classic
example of a timer is to schedule a system backup for the middle of the night.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Mount points managed via systemd reference paths use a slightly different naming
convention than ones managed via normal Linux paths. Where Linux paths contain
forward slashes as delimiters, systemd .mount unit files use the dash character
instead. A path that might normally read /mnt/projects/servers becomes
mnt-projects-servers. There are also a few replacements for special
characters and punctuation.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
[Unit]
Description=Emergency Mode with Networking
Requires=emergency.target systemd-networkd.service
After=emergency.target systemd-networkd.service
AllowIsolate=yes
This example contains a [Unit] section. Other .target files may also contain an
[Install] section. This file includes a user-friendly description, a requirements
statement (for other targets or services that are required), an After field for when
the target should load, and a field indicating whether the target can be switched
manually.
Configure Targets
The default.target unit file points to the selected target—either CLI
(multi-user.target) or GUI (graphical.target). When the default
startup option is changed, this file is modified.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
SysVinit was popularized in the UNIX System V (pronounced "System Five") family of
operating systems.
Runlevel Purpose
0 Halt or shut down the system.
1 Start single-user mode.
2 Start multi-user mode at CLI without
networking.
3 Start multi-user mode at CLI with
networking.
4 Unused
5 Start multi-user mode with GUI and
networking.
6 Restart the system.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
System Services
3
1. When using the systemctl command, how does enabling a service differ
from starting a service?
3. What are the target names for the GUI and CLI startup options?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 9B
Configure Common System Services
4
One of the sysadmin’s primary roles is to ensure the services users and systems
rely on are available and configured. There are many possible services. Some
servers are configured with multiple services, while others are dedicated to a single
function. This Topic reviews several common services that sysadmins are regularly
responsible for, including task scheduling, remote administration, and sharing
resources from a centralized file server.
Basics of Configuration
System and service configuration files store the settings necessary to manage
the system. Linux reads these configuration files as part of the startup process
and loads the services accordingly. If you make a change to a configuration, the
system must reread the file to implement the updates. This can be accomplished by
rebooting, reloading, or restarting the service.
For example, to restart a service after editing a configuration file, type:
# systemctl restart {service-name}
Reloading a service is a similar command:
# systemctl reload {service-name}
There are several common services that Linux administrators configure. This
section covers SSH, rsyslog, NTP, scheduling, web services, NFS, and CUPS.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Configure rsyslog
Log files are a critical component of system administration. Log files display
information on failed services, system restarts, configuration changes, user
authentication, and more. By default, log files are stored locally on each Linux
system. However, the rsyslog logging utility is capable of forwarding log files to
remote systems.
Many services and daemons log messages. These services are referred to as
“facilities.” Here are a few sample facilities:
• cron
• kernel
• ftp
• ntp
There are many possible facilities, depending on what services and applications are
installed on the system.
The rsyslog configuration file is found at /etc/rsyslog.conf. Additional
configurations may be found in /etc/rsyslog.d/50-default.conf.
Each line represents a different log configuration for the identified facility, such as:
cron.error -/var/log/cron
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
This entry logs all cron messages from error upwards to /var/log/cron.
Log files are simple text documents, so commands such as tail, cat, and grep
are very useful for displaying entries. The tail command is particularly useful
because rsyslog places the most recent log file entries at the bottom of the file.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Forwarding log files from multiple servers to a single server makes archiving and
parsing the files much simpler.
The first configuration occurs on the computer where logs will be centralized. You
must configure it to listen for inbound rsyslog connections.
1. Uncomment the following lines in the /etc/rsyslog.conf file. You will
find these lines in the Modules section of the file:
• $ModLoad imudp.so
• $UDPServerRun 514
4. Finally, test the configuration. On the source computer, type logger TEST.
On the destination log storage computer, search /var/log for a directory
with the source computer’s name and an entry that reads “TEST”.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Configure ntpd
The Network Time Protocol daemon (ntpd) synchronizes system time against one
or more specified time servers over port 123/tcp. You can define the time servers
by editing the /etc/ntp.conf file.
server timeserver-IP-address
Don’t forget to restart the service, since you made a configuration change:
# systemctl restart ntp
Often the /etc/ntp.conf file is configured for you by the Linux distribution
vendor.
Configure chrony
In some cases, the ntpd may not be responsive enough for certain systems. Linux
deployments that do not have constant or consistent network connections may
not accurately or immediately synchronize time settings via the ntpd. The chrony
service provides a more flexible and consistent time synchronization service in
these cases. Like ntpd, chrony uses port 123/tcp.
Two components make up the chronyd service: the chronyd daemon and the
chronyc command.
The chrony configuration file is /etc/chrony.conf . The file contains a
list of the time servers chrony will synchronize with. Here is a sample of the
configuration:
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburst
To see detailed configuration, status, and synchronization information, use the
following commands:
# chronyc -n tracking
# chronyc activity
Sysadmins must select one or the other time service; either ntpd or chronyd. Do not use
both time services simultaneously.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Configure Scheduling
The primary Linux task scheduler is cron. This tool references a crontab file to
determine whether any tasks have been assigned to a specific minute. A system-
wide crontab file is located at /etc/crontab, and a per-user crontab is at
/var/spool/cron/crontabs.
Helpdesk Ticket #01998
Thanks,
KG
Date last 2024-06-05
updated
Cron jobs can be used to specify tasks each minute, hour, day, month, and any day
of the week. This makes them extremely flexible.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Configure cron
The cron configuration relies on a crontab file. To schedule an event, edit the
crontab file using the crontab -e command.
The syntax of the crontab command is crontab [options]
Do not use a regular editor for managing the cron daemon. The crontab -e
command includes other features for managing the cron daemon. For example, after
editing the file, it automatically restarts cron.
Thanks,
KG
Response Hey Kai, absolutely. Call the script “backup.sh” and, at the
prompt, type in:
0 22 * * * /home/kgarcia/backup.sh
Date last 2024-06-06
updated
Here are a few other examples you could show the user who requested help.
To run the curl command to download a file daily at 10 p.m., type:
0 22 * * * curl -s http://sample.com/updated-
file.txt
To execute the command at 8 p.m. Monday through Friday, type:
* 20 * * 1-5 /path/to/command
To execute the command at 2:15 a.m. daily, type:
15 2 * * * /path/to/command
To execute the command at 4:30 a.m. on the first day of each month, type:
30 4 1 * * /path/to/command
To see scheduled cron jobs for the current user, use the cron -l command.
Configure at
The at command runs a task once at a specified time. It is not designed for
repetitive or regularly scheduled tasks. The at command is very flexible. Users can
specify a particular date and time, or they can cause the scheduled command to run
after a given period of time.
The command is typically used in an interactive manner, where the at command
and time interval are specified, and then a task is defined in an interactive prompt.
This enables the user to enter a path to a script or a command to be run. Pressing
Ctrl+D exits the interactive mode.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
In addition to cron, systemd .timer files can be used to schedule events. Recall that
.timer files were discussed in an earlier section.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Configure a Webserver
Apache webserver requires very little configuration for a basic deployment. The
basic process consists of installing the service, editing a single configuration file,
configuring the firewall, and creating content.
To edit the configuration file, use a text editor such as Vim or Nano to open /etc/
httpd/conf/httpd.conf. This file contains a great many comments and
optional directives. For a basic deployment, only two directives need to be modified.
Browse or search for the Listen and DocumentRoot directives, and then make the
following changes:
Listen 127.0.0.1:80
DocumentRoot "/var/www/html"
In this case, the webserver listens for connections to itself (hence the 127.0.0.1
loopback address) on port 80. The files that make up the website are found
at /var/www/html.
Next, configure the firewall to permit inbound HTTP (port 80/tcp) connections.
# firewall-cmd --permanent --zone-public --add-
service=http
# firewall-cmd --reload
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Finally, use a text editor to create a simple test web page with the following content:
Hello World
Welcome to my website!
Name the file index.html, and store it at /var/www/html (the location specified
by the DocumentRoot directive in httpd.conf).
The Apache service must own this file, so use the chown command to set
ownership:
# chown apache.apache /var/www/html/index.html
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Use a web browser on the local system to display the web page. Launch the
browser, and in the address bar, type http://localhost to see the page.
Configure NFS
One of the most common uses for a server is file storage. File servers centralize
business content, making security and backups easier. The Network File System
protocol permits remote client computers to connect to file servers from across the
network to access shared directories.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Don't forget to configure any firewalls for NFS connectivity. NFS relies on port 111/tcp
(and /udp) plus port 2049/tcp (and /udp).
Configure Printing
Printing is a critical function on a network. The term printers refers to the software that
manages the print process, while print devices are the actual hardware that applies
toner (or ink) to paper. The older Linux printers were managed by a series of lp (line
printer) commands, including the lpr and lpq commands discussed below. Modern
implementations often rely on CUPS to manage the print infrastructure.
Configure CUPS
CUPS is a print management system for Linux that enables a computer to function
as a print server. A system running CUPS is a host that can initiate print jobs from
client systems. These jobs are then processed and sent to the appropriate printer.
The main advantage of CUPS is that it can process different data formats on the
same print server.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Don't forget to open the firewall port. CUPS uses port 631/tcp.
Locally attached and network print devices are added to the CUPS configuration,
enabling administrators to manage print queues, security, and availability.
While the lpr command submits print jobs, the lpq command displays existing
print jobs that the printer is managing.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
System Service Configuration
5
4. When would a script run if it were configured in cron with the following
settings? 30 1 * * *
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 9C
Configure Localization Settings
5
Before users can get comfortable working in the Linux environment, they may need
to have the system localized to their specific region, culture, or preferences. In this
topic, you’ll configure localization options for users who need them.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
You can also format the time using a number of different formatting options. You
initialize the formatting options with a plus sign (+), and each option is prefaced
with a percent sign (%). For example, to retrieve the week number (out of 52 weeks
a year), you’d enter:
date +%V
You can also use the date command to change the system’s date by including the -s
option with a provided argument.
The syntax of the date command is date [options] +[format]
%S Display seconds.
Configure Localization
After you review the system settings with the date command, you can make
adjustments where necessary.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
For example, to configure the current time zone for Denver, Colorado, in the United
States, type:
# timedatectl set-timezone "America/Denver"
The output from the timedatectl list-timezones command is immense. Consider filtering
the results with | grep or paginating the results with | less.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Localization Settings
6
2. True or false? The localectl command configures the system locale and
keyboard settings as one collective setting that is aligned with the
locale’s specific cultural elements.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 9
Summary
3
The configuration services and locale settings enable users and other systems to
complete business tasks and serve customers. When the system starts, it runs
an initialization program to manage the necessary configurations. Most modern
Linux systems rely on systemd for initialization and service management, though
some older systems use SysVinit instead. These programs start web, print, file, and
remote administrations services that support users.
Guidelines
These best practices and guidelines are provided for your use as revision tools or as
quick references in your job role.
• Differentiate services versus daemons.
• Recognize that service configurations are held in files and services must be
restarted if a configuration file is changed.
• Recognize common service configuration files for SSH, rsyslog, NTP, cron, and
NFS.
• Recognize the port numbers for the services covered in this Lesson.
• NFS default port is 111/tcp and 111/udp plus 2049/tcp and 2049/udp
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
Basic networking skills are critical to Linux server administrators. The TCP/IP suite is
fundamental to modern networks and is built on a series of network devices. Each
node in a TCP/IP network has a unique identity, so displaying and configuring these
identities is a common task for Linux admins. Many network tools exist to provide
remote connectivity, whether that access is for administrative purposes or mere file
transfers. And many network tools exist to help troubleshoot these network access
issues.
Lesson Objectives
In this lesson, you will:
• Understand network fundamentals.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 10A
Understand Network Fundamentals
2
Modern networks, including the Internet, function based on the TCP/IP protocol
suite. Basic knowledge of this suite is fundamental to Linux system administration,
as is general knowledge of network devices. Furthermore, sysadmins need
to understand IP address assignment, classes, and relationship to network
segmentation. Finally, the concept of port numbers relates particular services—
such as web access or email—to numeric identifiers.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Network Nodes
The term node refers to devices with an identity on the network. That identity
may be represented by a physical address or one of two logical addresses, or any
combination of the three.
Each network interface card (NIC) has a unique identity coded into it that
identifies that NIC on the network segment. That code is referred to as a media
access control (MAC) address. It is the most fundamental network identity and is
considered a physical address.
Each NIC may be assigned a logical address called an Internet Protocol (IP)
address. The IP address uniquely identifies the NIC in the network environment.
IP addresses are shown in dotted decimal (base 10), which is a range of 0–9. The
computer works with the IP address in binary (base 2), which is a range of 0–1.
Nodes may be given a human-readable name, called a hostname, that helps
people better understand what device they are working with. This identity is often
configured during the installation of the operating system and is sometimes called
the “computer name.” Hostnames are limited to 255 characters.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Different devices on the network reference the different addresses. Often switches will
govern traffic based on MAC addresses, while routers will manage traffic based on IP
addresses.
Network Devices
There are several essential network devices and components to understand. These
may be part of the troubleshooting process or network installation. Linux systems need
to be configured properly to interact with these network devices and components.
A switch acts as a concentrator, centralizing all network connections for a segment
to a single device. Switches can be used to manage traffic for performance and
security concerns. As a general rule, switches work with MAC addresses at Layer 2
of the OSI model. There are switches that work at higher layers, too.
Routers act as control points for communications between network segments.
Administrators can configure the router to permit or deny certain kinds of traffic,
as well as pass traffic from one network segment to another. Routers work with IP
addresses at Layer 3 of the OSI model.
Typically, network media is twisted-pair Ethernet cable. Twisted-pair may come
shielded (STP) or unshielded (UTP). It is inexpensive and relatively easy to work
with. It is the most common type of network cable. Other cable types include
coaxial (coax) and fiber optic. Wireless networks forego cables and can transmit
data using radio waves.
Administrators use TCP/IP to organize networks for security and performance. Some
networks are divided into multiple segments to isolate certain types of traffic. For
example, traffic may be separated between production and development networks.
IP Addresses
IP addresses provide an addressing system for managing network identities.
Internet Protocol version 4 was defined in 1981. The addresses are 32 bits in
length, providing approximately 4.3 billion addresses. Humans usually work with IP
addresses in the decimal form, such as 192.168.2.200, while network devices work
with the address in binary.
IPv4 addresses are divided into at least two portions—a network identifier and a
host identifier. The network identifier defines to which network segment the host
belongs, and the host identifier uniquely identifies that host within the segment.
Because the network ID may use different bits within the address, a second
numeric value is used to show which portion of the IP address is the network ID
and which part is the host ID. This value is known as the subnet mask. It is essential
to understand the role of the subnet mask. It indicates where in the IP address the
division is between the network ID and the host ID.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The 4.3 billion IPv4 addresses are divided into the following five classes:
Number
Starting Ending of Hosts per Default
Class Address Address Networks Network Subnet Mask
Class A 0.0.0.0 127.0.0.0 126 16,777,214 255.0.0.0 or /8
Class B 128.0.0.0 191.255.0.0 16,384 65,534 255.255.0.0 or /16
Class C 192.0.0.0 223.255.255.0 2,097,152 254 255.255.255.0 or /24
Class D 224.0.0.0 239.255.255.255 n/a n/a n/a
Class E 240.0.0.0 255.255.255.255 n/a n/a n/a
Reserved Ranges
In addition to knowing the five IP address classes, there are several other IP
addresses or address ranges that are important. Due to the depletion of IPv4
addresses, there are three IP address ranges that are reserved for internal use only.
You will almost always find these in use on internal business and home networks.
• Class A Reserved: 10.0.0.0–10.255.255.255
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Address Configuration
There are two network services that are commonly involved with TCP/IP network
configuration. You will need to understand the role of both of these services in
order to properly configure your Linux system.
Humans have a difficult time working with long strings of numbers such as IP
addresses. The Domain Name System (DNS) service provides name resolution,
a way of relating an easy-to-remember hostname with a difficult-to-remember IP
address. DNS is implemented as a database hosted on one or more servers. The
database may only contain the names and IPs of nodes in your own network, or it
may be part of the larger Internet DNS infrastructure.
All nodes on the network must be configured with a unique IP address and
other corresponding information. There are two ways of accomplishing this
configuration— statically or dynamically. Static configuration is usually appropriate
for servers and network devices, while dynamic configuration is typically used with
end-user workstations. The Dynamic Host Configuration Protocol (DHCP) service
provides dynamic configuration.
IPv6
The IPv4 addressing scheme has many limitations. A newer standard is being
implemented in the form of Internet Protocol version 6. IPv6 addresses many of the
weaknesses of IPv4 with a much larger address space, built-in encryption, and more
efficient routing.
IPv6 uses 128-bit addressing, while IPv4 relies on 32-bit addressing. The result is a
much larger address space. IPv6 includes more modern features and is common
on large networks, such as telecom, Internet service providers (ISPs), and cloud
environments.
Linux is fully compatible with IPv6, so Linux servers and workstations should not be
a limiting factor in the deployment of IPv6 in a network environment.
Network Ports
Network port numbers are numeric values assigned to the various application-
layer protocols. Network devices use these port numbers to understand what
application will handle the communication. Humans work with the application-layer
protocols by name, such as Hypertext Transfer Protocol (HTTP). Computers need to
work with these by port number.
A few of the more commonly used ports are provided in this table.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Network Fundamentals
3
2. Explain the difference between the Network ID and the Host ID portions
of an IP address.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 10B
Manage Network Settings
4
Network settings are often configured manually (or statically) on servers and
dynamically on client devices. Various tools display and manage these settings,
aiding administrators in system configuration and troubleshooting. As has already
been covered, Linux configurations are stored in text files, and network settings are
no different.
This Topic focuses on network management tools and the process of configuration
IP address settings and name resolution.
Use ip Commands
The ip command replaces ifconfig in many distributions. It provides similar
information to ifconfig, including IP address, subnet mask, and MAC address.
The ip command is one of the first tools used in network troubleshooting on a
Linux system. Some common ways to utilize the ip command include:
• ip addr show —Displays the IP address information on all interfaces.
• ip link —Displays the status of each interface.
• ip link set eth1 up —Enables the interface identified as eth1.
• ip link set eth1 down —Disables the interface identified as eth1.
The syntax of the ip command is ip [options] {object}
[subcommand]
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Available ip subcommands.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
mode {mode} Set the operating mode for the NIC that
corresponds to the network topology.
freq {number} Set the Wi-Fi frequency used by the NIC.
Use NetworkManager
Linux distributions often include a utility called NetworkManager to aid in the
proper configuration of the IP information. NetworkManager includes three
different interfaces that may be used, depending on whether or not a GUI is
available on the Linux system.
The nmcli tool displaying the status of all connected network interfaces.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Use ethtool
The ethtool is used to manage NIC driver and network configurations. Whether
or not it is installed by default will depend on the distribution in use. The ethtool
utility has a great many options for gathering information. The basic output displays
interface options such as modes, speed, duplex configuration, Wake-on-LAN
settings, etc. Not only does the ethtool command allow admins to see these
settings, but it also allows them to change these options.
Assign IP Addresses
IP address configurations can be set in two ways: statically or dynamically. Each
method has advantages and disadvantages. It is important to know when to use
each method. Administrators will statically (or manually) configure IP addresses on
some types of network nodes. Client devices, however, are usually configured with
dynamic IP address settings. IP address configurations are then leased from a DHCP
server. The result is that both methods are used in most networks, not just one
method or the other.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Static IP Addresses
Static IP address configuration means that the settings are implemented manually
by an administrator. This method increases the risk of mistakes but also ensures
the system always has the same identity. Static IP address configurations are
usually appropriate for network devices (such as routers and network switches) and
servers. They may also be used for network print devices.
Static configurations are characterized by:
• Non-changing IP address configuration.
Dynamic IP Addresses
Dynamic IP address configuration means that the settings are retrieved from a
server. This method decreases the risk of mistakes but also means the system may
not always have the same IP address. Dynamic IP address configurations are usually
appropriate for client machines. They may also be used for network print devices.
Consider these traits of dynamic configurations:
• IP address configuration may fluctuate over time.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Periodically, DHCP clients must renew their leased IP address configuration. If the
DHCP server detects that the client has out-of-date information, it will force the
client to lease a new configuration. If there have been no changes, the renewal
will succeed. The lease renewal process is steps three and four of the initial lease
generation process.
The process of a DHCP client leasing and renewing an IP address from a DHCP server.
(Images © 123RF.com.)
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Thanks,
KG
Date last updated 2024-06-14
The /etc/hosts file is still important, however, because it can be used in special
case situations where a particular system—perhaps a developer’s workstation—
needs to connect to an experimental server that is not registered on the network.
While the /etc/hosts file is not commonly used, it is essential in certain
scenarios.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
5
Network Settings
Answer the following questions:
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 10C
Configure Remote
Administrative Access
5
Configure SSH
The primary remote administration tool in Linux is Secure Shell (SSH). SSH provides
encrypted and authenticated remote access to Linux systems. However, it is also
very common to use SSH to connect to network devices such as routers and
switches. Linux, Unix, and macOS systems include SSH by default, and the protocol
can be added to Microsoft Windows.
SSH has become an even more critical tool with the rapid growth of cloud
computing. SSH enables cloud administrators to securely connect to remote cloud
resources and is an essential tool.
Be careful not to get confused by the similar names of the SSH configuration files
(ssh_config versus sshd_config).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
To block the root user from authenticating over SSH, set the following value to no:
PermitRootLogin no
To both prevent password-based authentication and permit key-based
authentication, set the following two values (be sure you have configured key-based
authentication first!):
PasswordAuthentication no
PublicKeyAuthentication yes
Don't forget to restart sshd if you make changes to the configuration file.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Cloud service providers strongly urge administrators to administer systems via SSH
key-based authentication. Many organizations rely on SSH authentication keys for
on-premises and cloud resources.
The use of public and private keys is covered in more detail in a later section.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
3. Finally, test the connection. To connect to 192.168.2.200 with the user01 key,
type:
# ssh [email protected]
Observe that you are not challenged for a password. The key exchange quickly
authenticates you.
Key-based authentication is managed by the ssh-agent tool, and it needs to be
aware of existing keys. These keys are automatically added to the agent when
generated, but the ssh-add command allows a user to manually add an existing key
to the agent if it’s not already aware of the key.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Thanks,
KG
Date last updated 2024-06-24
Wget and cURL are HTTP clients capable of downloading files from remote
webservers. Most HTTP connections occur using web browsers and download a
series of files that are assembled into a web page. Simple downloads, however,
don’t justify the use of a browser. Furthermore, it’s difficult to script or automate
browser-based downloads.
The following is an example of using the cURL tool to download a file from the
Nmap website:
# curl -o nmap-7.70.tar.bz2 https://nmap.org/dist/
nmap-7.70.tar.bz2
The following is an example of using wget to download a file from the Samba
website:
# wget http://download.samba.org/pub/samba/samba-
latest.tar.gz
While curl and wget perform the same basic function, there are some key
differences.wget is a command-line utility only, whereas curl is implemented
using the cross-platform libcurl library and is, therefore, more easily ported to
other systems.wget can download files recursively, whereas curl cannot.curl
supports many more network protocols than wget does (wget only supports
HTTP/S and FTP).wget is better suited for straightforward downloading of files
from a web server, while curl is better suited to building and managing more
complex requests and responses from web servers.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The following table provides some example use cases for the netcat command.
Other commands, such as nc, may also be used to transfer files across the network.
However, nc may be more difficult to set up than establishing a basic scp connection.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The rsync command can copy files over SSH, or it can use the rsyncd daemon if
you set it up on the remote system. In the latter case, rsync must be installed and
running on the source and destination systems.
The following is an example of synchronizing the files in a local directory to a
remote directory over SSH:
# rsync -a /home/mydir/ user@host:/home/mydir/
The rsync command is used for network file transfers, where bandwidth may
be at a premium. This is different from a local move action, such as using the mv
command to move a file from one directory to another on a local filesystem.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Remote Administrative Access
6
3. What advantage does the rsync utility have over SCP and SFTP? What
disadvantage does it have?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 10D
Troubleshoot the Network
4
Network troubleshooting involves many layers and components. It may also span
areas of IT influence, such as between the server team (managing Linux servers)
and the network team (managing routers and switches). Often, troubleshooting
scenarios involve a fairly discrete part of the network. There may be issues with
the server’s network configuration or with the remote system’s network settings.
There may be network bandwidth, latency, or performance issues. Many issues
revolve around name resolution challenges. This section breaks down the tools and
approaches necessary for Linux admins to troubleshoot network problems.
Thank you,
Rey Harper
Jr Sysadmin
Date last updated 2024-07-12
Use the following steps as a guide when troubleshooting failed network connectivity
between a client and an NFS, web, or SSH server located on a separate segment.
1. Display the current IP address configuration by using commands such as ip
addr or ifconfig. Verify the address and subnet mask values are accurate
with no typographical errors. Confirm the gateway value is the IP address of
the NIC in the router connected to this client’s subnet.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Recall that 127.0.0.1 is the loopback address, and it is not valid on the network. An
address of 169.254.x.x indicates the client attempted to lease an IP configuration
from a DHCP server but failed.
2. Use the route command to display the system’s routing table. This table lets
the system know which interface is connected to which subnet.
3. Initiate a ping test against the remote server and the gateway address.
Ping the remote server by name and by IP address. Use the traceroute or
tracepath command to display the network path between the client and
server.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The term "foo" is a common example file or URL name that means nothing or a
changeable value. The focus is not on the actual object, but rather on the command(s)
associated with it.
Compare the returned certificate and trust information to determine whether there
is a problem with the remote server’s certificate.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
iftop
The iftop command displays bandwidth usage information for the system,
helping to identify whether a particular NIC or protocol is consuming the most
bandwidth. The iftop command may not be installed on all Linux distributions.
This command can help you identify why a particular link may be slow by showing
the traffic on that connection. You can use it to check to see what is consuming the
most bandwidth on an interface. For example, iftop -i eth0
Network slowness is often a symptom of bandwidth saturation, in which a network
link’s capacity is exceeded, i.e., all bandwidth is being used up. This can lead
to degraded network performance or even service outages. With the iftop
command, you can investigate any NICs on a network link that you suspect may
be sending or receiving excessive sums of traffic across that link. For example, one
host might be making repeated requests to an internal web server, and both hosts
might be flooding the network with their requests and responses. Once you’ve
identified the source of the issue, you can then take steps to stop the offending
host from making these requests, such as terminating the service responsible for
the requests.
The syntax of the iftop command is iftop [options]
[-i {interface}]
iperf
The iperf command is used to test the maximum throughput an interface will
support. The utility must be installed on both endpoint systems. One system is
designated as a “server” and the other as a “client.” It is the iperf client that is
getting tested. You can use this command to ensure that throughput is meeting
your expectations.
A basic test uses these steps:
1. On the server, run iperf -s
2. On the client, run iperf -c {server address}
3. Examine the results that appear.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
While tools such as itop and iperf give information about the quality of the
connection, tracepath and traceroute display the network path followed
by the connection.
It’s also possible the NIC in the local machine is misconfigured or failing. Ensure it’s
using a current device driver and that no system errors are associated with the NIC.
Consider replacing the NIC with a known-good spare.
Thank you,
Rey Harper
Jr Sysadmin
Date last updated 2024-07-19
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Many different tools test and troubleshoot name resolution. These tools should
be used after you have confirmed that the system is configured with the proper IP
address of one or more DNS servers (use cat /etc/resolv.conf to verify)
and after using ping to test connectivity to the DNS server.
To quickly display the hostname for the system, type the hostname command.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The dig, nslookup, and host utilities are installed as part of the bind-utils
package.
Use WHOIS
WHOIS is a name resolution protocol that queries DNS servers to display the
hostname, fully qualified domain name (FQDN), IP address, and other information
about a given host.
The syntax of the whois command is whois [options] {domain
name}
For example, type whois comptia.org to display the related information.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Network Troubleshooting
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 10
Summary
3
Guidelines
These best practices and guidelines are provided for your use as revision tools or as
quick references in your job role.
• Understand that different distributions use different network configuration
tools.
• hostname
• IP address
• MAC address
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
It’s critical for administrators to understand what’s happening on the network and
how that impacts servers and clients. Administrators can use firewalls to control the
flow of traffic into and out of individual nodes, network segments, or even entire
networks. Firewalls contain rules that define what traffic is permitted and what
traffic is not.
Ensuring network traffic flows as it should also includes monitoring and
troubleshooting connectivity issues, as well as understanding exactly what data
is moving on the network. The network map helps make the task of securing and
monitoring the network easier.
Lesson Objectives
In this lesson, you will:
• Configure the firewall.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 11A
Configure the Firewall
2
Firewalls are one of several tools administrators use to mitigate threats. Most
operating systems provide firewalls for the location computer, and most networks
have perimeter firewalls to control the flow of traffic. This Topic covers firewall use
cases, types, and configurations.
To summarize, a firewall rule might specify these elements: permit inbound HTTP
traffic on eth0.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
How sysadmins write these rules varies depending on the type of firewall. For
example, permitting or denying traffic by port or protocol is referred to as opening or
closing the port in some configurations or instructions.
Firewall rules are processed in order, with the most specific rules applied first and
the most general rules applied last. Nearly every firewall uses a generic “deny all”
rule as the final rule. A simplified explanation might look like this:
• Rule 1: Permit inbound port 80 to webserver01.
Any inbound connection that matches a rule is processed against that rule. Observe
that all inbound connections would eventually match the final rule. In this scenario,
any connection that is not inbound HTTP to webserver01 or not inbound FTP to the
192.168.2.0/24 segment is blocked.
Firewall Zones
Firewalls recognize different zones or groups of interfaces. A firewall device
may have multiple interfaces connecting to various network segments, such as
the Internet (untrusted), a perimeter network (semi-trusted), and an internal
network (trusted). Zones define a set of rules for each connection, simplifying the
administrative process. In addition, many firewalls come with pre-defined zones,
offering administrators common configurations so they don’t have to create all
rules themselves. Which zones exist by default varies by firewall service.
Firewall Types
While Linux devices may perform as a network segment or perimeter firewalls,
those devices are usually dedicated hardware components. In the context of Linux
systems, host-based firewalls are the main focus.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Most Linux distributions ship with a firewall, and it is usually enabled by default.
After the operating system is installed, it often has limited network connectivity
or it may even be completely isolated. This is a good default because it allows
administrators to define exactly what connections should be permitted or blocked.
Linux firewall capabilities are managed by iptables or nftables. These services have
their own command sets or tools, such as firewalld, or UFW can be used to establish
rules.
Configure iptables
The iptables tool enables you to manage packet filtering as well as stateful firewall
functionality within Linux through various tables. Each table applies to a certain
context and consists of rule sets, called chains, that the table uses to implement
the firewall. A packet is compared to the first rule in the appropriate chain, and if it
does not match that rule, it is compared to the next rule in the chain, and so on. If
the packet matches a rule, it can either be evaluated by a new chain or have one of
three actions applied to it: ACCEPT, DROP, or RETURN (skip to next rule in previous
chain).
Each table has one or more built-in chains, but you can also define your own chains
as desired.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Table Purpose
filter The default table used for typical packet filtering functionality.
nat Used to implement Network Address Translation (NAT) rules.
mangle Used to alter packets’ TCP/IP headers.
raw Used to configure exceptions for packets involved in connection
tracking.
security Used to mark packets with SELinux security contexts.
By default, rules set with the iptables command are lost on reboot. In CentOS/
RHEL, you can install the iptables-services package and issue the service
iptables save command to ensure your changes persist. For Debian-based
distros, you can install the iptables-persistent package. After installation, you’ll be
asked to confirm that you want your current rules to persist. The iptables-persistent
service will then automatically run at boot and load your rules.
Configure nftables
The nftables firewall is a modern, scalable, high-performance replacement for
iptables. It uses similar logic but includes enhancements that make the lives of
sysadmins easier. For example, management of IPv4 and IPv6 rules is integrated
rather than separate as in the older iptables. Other improvements include
simplified syntax, modernized security, and increased performance.
For example, to add a rule to the input chain of the traffic-filter table that permits
inbound IPv4 or IPv6 HTTP traffic, type:
# nft add rule inet traffic-filter input tcp dport
80 accept
Netfilter, the developer of nftables, has included translation options for converting
complex iptables rules into the nftables syntax.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The command option uses the now-deprecated term “dmz” to describe the perimeter
network. Terminology within the field has evolved, but the command syntax is likely to
remain the same for some time.
Settings configured with the above sample commands affect the current runtime after
the --reload flag is used. If the system restarts, these settings will be lost. To
make the settings persistent (survive restarts), add the --permanent flag to the
commands.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The ufw command enables you to work with the command line interface. For
example, the following commands set up an allow rule for HTTP, turn on logging,
and enable the firewall:
# ufw allow http/tcp
# ufw logging on
# ufw enable
This automatically creates a default deny configuration for incoming traffic. In other
words, everything without an explicit allow rule is dropped.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
• Check whether the default deny-all rule for incoming connections is processed
before permit rules.
• Check whether you’ve blocked or allowed the incorrect transport layer protocols
(TCP, UDP, or both).
Remember that the misconfiguration may be that traffic is getting through that
should not.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Firewall Configuration
3
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 11B
Monitor Network Traffic
4
2. Packet capturing. These tools intercept and display the contents of network
traffic. If the traffic is not encrypted, the contents are readable by whoever
conducted the capture. Wireshark and tcpdump are examples of packet-
capturing tools. Another name for this category of tools is protocol analyzers.
Begin network troubleshooting and monitoring with basic tools, and move toward
the more complex utilities as circumstances dictate. This section begins with
checking connectivity before moving into intercepting network traffic.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
• Timeout: The request reached the destination computer, but a response did not
return to the source computer before the source computer timed out. This often
indicates the problem is with the destination computer.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Continuous ping is a surprisingly useful tool. For example, if you are rebooting a
remote computer via SSH, you could set up a continuous ping. While the remote
system is restarting, the pings will fail. However, once the startup process is
complete, the remote system is again available for you to reconnect to it.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The traceroute command output following the route between two network hosts.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Thanks,
KG
Date last updated 2024-08-09
Use netstat
The netstat (network statistics) command gathers information about TCP
connections to the system. Depending on the options used, the netstat tool informs
the user of existing connections, listening ports on the server, NIC information, and
more.
The syntax of the netstat command is netstat [options]
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Common options for the netstat command are listed in the table below.
Use ss
The ss (socket state) command is an information-gathering utility similar to netstat
but provides simpler output and syntax. The ss tool provides information about
established TCP connections or which ports the system may be listening on for
inbound connections. This can help you diagnose problems related to clients and
servers being unable to communicate with one another over the desired protocol; a
missing socket could mean that the service isn’t running, and a closed socket could
mean that either the client or the server is prematurely terminating the connection.
Another way to use the ss command is to gather information about a particular
client that may be connected.
The syntax of the ss command is ss [options]
Subcommand for the ss Command Purpose
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The ss command is useful when troubleshooting errors such as ports that are
already in use by one application when another application starts or when tracing
existing connections to or from the server for security purposes.
Use lsof
The lsof command displays files in use by active processes. However, by adding
the -i switch, it displays network sockets in use. The lsof command can be used
instead of (or in addition to) the netstat and ss commands.
Another useful troubleshooting utility is netcat. Recall that the netcat (or nc)
command can test connectivity and transfer files. This tool was covered in Topic 10C.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Use tcpdump
Linux admins often rely on the tcpdump utility for packet captures. Created in 1987,
tcpdump remains one of the most popular packet sniffers available. It is installed by
default on many Linux distributions. Users can determine traffic type and content
using this command. It provides similar information to Wireshark, and you can use
it in a similar troubleshooting process.
The syntax of the tcpdump command is tcpdump [options]
[-i {interface}] [host {IP address}]
The following table provides some common tcpdump options.
When writing the results to a file, tcpdump does not provide a human-friendly
format. The file can be read by using tcpdump -r or Wireshark. The file
extension is usually .pcap.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Use Wireshark
Wireshark is a very common packet sniffer and network analyzer. Network
analyzers intercept and potentially read network traffic. These tools may be
used for eavesdropping attacks but are also commonly used for network
troubleshooting. When network traffic is intercepted, information such as source/
destination MAC address, source/destination IP address, port numbers, and packet
payload (data) is exposed. One advantage of a tool like Wireshark is seeing exactly
which packets are moving through a network segment or NIC and which packets
are not. This is very useful for troubleshooting.
Wireshark capturing network traffic as it flows between two hosts. (Images © 123RF.com.)
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Wireshark is primarily used with a GUI, but it does include the tshark command
for CLI use or scripting.
The tshark utility functions much like tcpdump. It even outputs capture results
in the same PCAP format. The results are a little more user friendly when generated
by tshark as compared to tcpdump.
The basic process for using tshark is the same as any other capture: Define the
interface you want to capture on, begin the capture, and then end the capture.
To identify the available interfaces, type:
# tshark -D
To begin a capture on the eth0 interface, type:
# tshark -i eth0
Use Ctrl+C to end the capture.
You could also use the -c {number} option to limit the capture to a specified
number of packets.
Use Nmap
The Nmap utility is an incredibly powerful network-mapping tool. It scans individual
network nodes, subnets, or entire networks and can report extremely detailed
results. The most basic scan shows the status and listening ports on a target, while
more advanced scans display target vulnerabilities, the presence of web application
firewalls, rogue DHCP servers, and more.
Nmap is a CLI tool, but there is an available GUI named Zenmap, which is powerful
and convenient. Both utilities are examples of open-source software.
Recall that the advantage of CLI tools is the ability to automate or script their
functionality. For example, the Nmap-based network inventory objective in this example
could be scripted and scheduled to run every 90 days, providing a quarterly report to
administrators that shows changes to the network environment over time.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
-F Fast scan.
There are other port results, but these are the three most commonly seen in Nmap
results.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
uses the -sn options, which does not report listening ports but merely checks the
status of IP addresses to see whether a host responds to a query. The result is a
basic list of IP addresses in use.
# nmap -sn 192.168.1.0/24
Nmap can also detect the operating systems of scan targets. This type of basic scan
does more than simply identify Linux, Windows, or macOS; instead, it is usually
capable of accurately identifying specific versions, kernels, and roles (servers). While
many of the default scans include OS detection, to specifically identify operating
systems, add the -O option.
OS detection works against entire subnets, but here is an OS detection scan against
just the 192.168.2.200 host:
# nmap -O 192.168.1.1
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Generate a basic text file named net-scan.txt from an Nmap scan in the
~/scans directory:
# nmap -oN ~/scans/net-scan.txt 192.168.2.200
Conduct Detailed Nmap Scans
Be aware that Nmap scans of large groups of nodes can take a long time. Nmap
has a variety of features designed to avoid detection or gather immense amounts
of information. In addition, scanning a large segment, such as a heavily populated
Class C or a Class B subnet, targets a lot of machines.
Some advanced scans speed this process up. Other advanced scans focus on more
stealthy scans to avoid detection.
Here is an example of a fast scan designed to check for common port numbers,
including 22 (SSH), 80 (HTTP), 443 (HTTPS), and others:
# nmap -F 192.168.1.1
Another example is a TCP connect scan. This scan attempts TCP connects via the
three-way handshake, which may leave entries in the target’s log file. This scan is
slower than some other scans.
# nmap -sT 192.168.1.1
Some administrators use nontraditional port numbers to help camouflage network
services. For example, port 22 is a well-known port associated with the SSH
service. An administrator might set that service to port 2222 as a way of hiding the
service from basic scans. However, nontraditional ports could mean unexpected
configurations are in place that require further investigation.
The following example scans for nontraditional ports:
# nmap -sV 192.168.1.1
Nontraditional ports, however, may represent an entirely different security
concern. Nontraditional ports may represent rogue network services (services the
administrator is not aware of). Such services might be the result of malware or
other unauthorized and unwanted software running on the network. Such software
could offer backdoor access to the network or direct network traffic outside the
network to a threat actor.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The nmap.org website also contains a large library of Nmap scripts that automate very
specific and detailed scans. These can be very useful for network administrators.
Nmap is a powerful but simple tool to use for network inventories, security audits,
and troubleshooting. Once you’ve completed your Nmap scans, reporting such
details as operating systems, port status, and any nontraditional reports should be
straightforward. Reports may be generated directly from Nmap output, integrated
into spreadsheets, or added to text files.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Network Traffic
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 11
Summary
4
The tools that threat actors use to understand the network are the same tools that
help administrators mitigate threats. Protocol analyzers intercept and read network
traffic, so firewalls help to isolate and manage that traffic. Network mappers such
as Nmap display potential vulnerabilities, misconfigurations, or unexpected services
exposed to remote devices.
Because both administrators and threat actors use these tools, it is critical to have
authorization to use them on the network.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
System security mitigates threats and vulnerabilities by ensuring Linux devices
match required configurations. These configurations, implemented via a process
called hardening, are supplemented by encryption, strong authentication methods,
and mandatory access controls. This Lesson provides configuration steps and
commands to manage security tools.
Lesson Objectives
In this lesson, you will:
• Harden a Linux system.
• Manage certificates.
• Understand authentication.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 12A
Harden a Linux System
2
Hardening Servers
There are many steps administrators can take to mitigate threats to Linux systems.
The process of managing such mitigations is known as hardening. Two of the most
crucial aspects of hardening are removing anything from the system that it does not
need and then using the most current version of whatever software and services
remain. There are many more tasks involved in hardening, however.
The principle of least privilege guides many hardening techniques. The principle
states that users and services should be granted as little access as possible while
still allowing them to function. In other words, if a user only needs read access to a
file, do not grant them both read and write.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
UEFI will be covered in Topic 16A. Logging was covered in Topic 9B.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Security Goals
One useful way of considering security is to define goals. System security attempts
to satisfy three primary goals: confidentiality, integrity, and availability. These goals
are known as the CIA Triad.
Confidentiality ensures that only the authorized user has access to data.
Establishing confidentiality may include encryption of network traffic against
interception, permissions to manage access to files or databases, and
authentication to manage access to system resources and other sensitive assets.
Integrity ensures that data has not changed unexpectedly. Such changes may
occur because of data corruption during network transfer, malicious users altering
data, non-malicious users accidentally changing or deleting data, and other similar
activities.
Availability ensures that users and services have access to the resources they need
when they need them. Availability includes system uptime, appropriate network
performance, and access to resources. Solutions such as backups, load balancing,
and low latency network connections are all part of the availability goal.
Observe how many Linux topics deal with availability. A few examples include RAID for
storage disks, the df and du commands to measure storage disk capacity, iftop
for overcoming network bandwidth limitations, and tools such as top to maintain
processor/memory utilization.
DevSecOps Concepts
Development processes have changed in recent years, moving toward a more
frequent and short release cycle. This practice is referred to as DevOps, and it is a
common part of application development in modern IT teams.
The shorter development cycle and more frequent release schedule for applications
have changed the approach for security. Security teams must now be integrated
into the development process rather than viewed as a single step toward the end
of the life cycle. This integration is DevSecOps, and it associates a development
culture, automation practices, and design based on blending security and
development practices throughout the process. DevSecOps does not really refer
to the surrounding security environment (firewalls, network encryption, server
hardening), but Linux sysadmins are still part of the process and must understand
the concept.
Understand Encryption
Encryption is a cryptographic technique that converts data from plaintext form into
coded, or ciphertext, form. Decryption is the companion technique that converts
ciphertext back to plaintext. An algorithm called a cipher is responsible for the
conversion process.
When a message is encrypted, only authorized parties with the necessary
decryption information can decode and read the data. This information is called
a key, and it is used with the cipher to ensure the message is unreadable to those
not in possession of the key. Encryption is therefore one of the most fundamental
cybersecurity techniques for upholding the confidentiality of data.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The basic process of both encryption and decryption, using the key in both instances.
(Images © 123RF.com.)
Encryption can be applied to data in three different states: when the data is passing
through a network (in transit), when the data is accessed in memory (in use), and
when the data is stored on a device such as a storage disk (data at rest).
There are several subtypes of encryption for data at rest, with two of the most
prominent being full disk encryption (FDE), which encrypts an entire storage drive,
partition, or volume using either hardware or software utilities, and file encryption,
which encrypts individual files and folders on a file system using software utilities.
Encryption Goals
Encryption attempts to satisfy the three primary goals of confidentiality, integrity,
and non-repudiation.
While the encryption goals look similar to the security goals, there are differences.
One primary difference is the encryption goal of non-repudiation as compared to the
security goal of availability.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Encryption Types
Two of the most common ways of encrypting and decrypting information are
symmetric key encryption, which is the use of a single key to both encrypt and
decrypt data, and asymmetric key encryption. Asymmetric encryption uses a pair
of mathematically related keys, where one key encrypts and the other key decrypts
data. One key is referred to as the public key, and the other is referred to as the
private key.
The use of a single key (symmetric) for both encryption and decryption performs
well but introduces a problem: how to securely deliver the key to the endpoint.
The asymmetric key-pair approach solves the security problem, though at the
expense of speed. Asymmetric encryption is more secure because the public key is
available for transport across a network or other media and is viewable by anyone,
while the private key must remain on the local system and is available only to the
authorized user or service. Finally, the asymmetric key pair is governed by the rule
that if data is encrypted with one key, the data must be decrypted by the other key.
This lends increased security over symmetric encryption because one key remains
private at all times. However, the process of encrypting and decrypting content is
slower due to the use of two keys.
The use case for each type varies depending on the goal (confidentiality, integrity,
non-repudiation). The following sections summarize these use cases and the role
the keys play in managing data.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
This method proves authenticity and meets the goal of non-repudiation. In other
words, it proves that the content came from the specified source. This is known as a
digital signature.
Hashing
The hashing encryption method uses a single-key symmetric encryption, but the
goal is to provide integrity, not confidentiality. The information is encrypted using
a key, and the encryption process generates a resulting encrypted value. If another
party encrypts a copy of the same original data, they would expect to get the same
result. If a different result is generated, the data copy is different from the original.
For example, an administrator stores a file on a Linux server and uses a hash
algorithm to encrypt the file. The hash generates a unique string. The administrator
makes both the file and hash available to users to copy. A user who copies the
file to their workstation and runs the same hash algorithm should see the same
hash result as the administrator sees. If the result is the same, the data is identical
on the server and the user’s workstation. If the result is different, the copy on the
workstation is not the same as the copy on the server. Observe that hashing does
not indicate what changed, only that something changed. Files might change based
on events such as user updates, file corruption, or malicious alteration.
Outcome of hashing. Alice, the administrator, has made the file available (1) to Bob, who runs the
hash algorithm and is able to see the correct file (2 and 3). If Mallory is able to inject a malicious
download (4), Bob would run the hash algorithm, see that it’s different from the reference file (5),
and reject it. (Images © 123RF.com.)
Hashing proves file integrity, ensuring that two copies of the same data are indeed
identical.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
System Hardening
3
1. Explain the principle of least privilege, and provide at least two examples
of its use.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 12B
Manage Certificates
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Recognize SSL/TLS
Security professionals must protect web traffic, and public key encryption helps
with that process. Transport Layer Security (TLS) relies on digital certificates to
provide confidentiality, integrity, and authenticity for web connections.
Secure Sockets Layer (SSL) is an earlier implementation of TLS, and often the two
acronyms are used interchangeably. The actual SSL protocol is deprecated but
often referenced due to its name recognition.
Websites that rely on TLS security contain HTTPS in the URL. This indicates that in
the background, the certificate information is exchanged between the web client
and the webserver to negotiate a secure connection. Web connections that use
HTTP do not negotiate this same information, leaving the connections vulnerable to
eavesdropping, impersonation, on-path, and other forms of attacks.
Certificate Authentication
Certificates are also used to allow users, applications, services, devices, and other
identities to authenticate and access resources. Authentication based on certificates
is more secure than password authentication and is usually more flexible.
Certificates may be stored on smart cards or hardware devices.
Certificate Authorities
A certificate authority (CA) is a server that issues digital certificates for entities
and maintains the associated private/public key pair. CAs sign digital certificates so
that clients can validate the authenticity of certificates owned by entities. CAs may
be third-party or internal.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Third-party CAs issue certificates that guarantee identities in public settings, such
as the Internet. The CA acts as a trusted third party—trusted by the entity claiming
an identity and trusted by the entity confirming the identity. For example, an
e-commerce site will request a certificate from a third-party CA that confirms its
claimed identity. E-commerce customers trust that the certificate confirms the
website’s identity.
Third-party certificates issued by CAs are used when the two parties don’t trust each
other’s identities, such as when an anonymous customer makes a purchase on a
vendor’s website.
Self-Signed Certificates
Internal CAs issue self-signed certificates—certificates that are owned by the
same entity that signs them. In other words, the certificate does not recognize any
authority and is essentially certifying itself. Self-signed certificates require the client
to trust the entity directly.
Self-signed certificates issued by an internal CA are used when the two parties each
trust the organization, such as when an internal workstation connects to an internal
server.
Wildcard Certificates
Most certificates are associated with a single identity, such as a website at www.
[example].com. These types of certificates will not guarantee other identities related
to that domain, such as mail.[example].com. Hence, an organization would need to
purchase two certificates; one for the website and one for the mail subdomain.
Wildcard certificates support multiple subdomains of a single parent domain, such
as www.[example].com, mail.[example].com, and ftp.[example].com.
Common certificate use cases include HTTPS web connections, smart-card
authentication, and digitally signed files.
Integrity Checking
Integrity checking is the process of verifying that data has not been intentionally or
unintentionally modified in any way. In other words, an integrity check can validate
the security goal of integrity. It is good practice to perform integrity checking after
you finish compressing and archiving a backup file to confirm that the data has
not changed. This will help you avoid storing corrupted and inaccurate archives for
future recovery, only to find out too late that the data was not properly backed up.
Several methods enable you to check data integrity, each of which may vary based on
its security requirements or goals. One of the most common and secure methods of
checking data integrity is through the use of hashing. By calculating the hash of a file
like a backup archive, you can compare that hash to past values, and if both are the
same, you can be reasonably sure the data has not changed in the meantime.
Hash Functions
A hash function is an algorithm that performs a hashing operation. There are many
different hash functions, each of which may have its own security strengths and
weaknesses. The two most common hash functions for checking data integrity on
Linux systems are MD5 and SHA.
The Message Digest 5 (MD5) algorithm produces a 128-bit message digest. It
was created by Ronald Rivest and is now in the public domain. MD5 is no longer
considered a strong hash function and should be avoided for sensitive operations
like storing passwords; however, it is still used in integrity checking.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The Secure Hash Algorithm (SHA) is modeled after MD5 and is considered the
stronger of the two. Common versions of SHA include SHA-1, which produces a
160-bit hash value, while SHA-256, SHA-384, and SHA-512 produce 256-bit, 384-bit,
and 512-bit digests, respectively. SHA-1 is being deprecated due to some security
weaknesses.
The md5sum command is used to calculate the hash value of a file or standard input
using the MD5 hash function. You can also use the -c option to specify a file contai-
ning MD5 hashes and the file names they apply to; md5sum will calculate the hashes
of the files listed and then compare them to the hash values listed. The results will let
you know whether each file passed, failed, or could not be found.
MD5 hashes are 128-bits in length. Like many other hash values, they are typically
represented in hexadecimal format (32 characters for MD5). The following is the
hash value of the string “Linux”:
edc9f0a5a5d57797bf68e37364743831
The syntax of the md5sum command is md5sum [options] [file name]
To use the md5sum command, create a test file by using Vim (or another text editor).
Type a basic sentence or phrase in the file, and then save and close the file. Next, run
the md5sum command using the file name as the argument. You’ll see hash value
output on the screen. Now, make a change to the file contents, then save and close the
file. Run the same md5sum command using the file name as the argument. Compare
the new hash. Because the contents are different, the hashes are different.
Here’s an example:
md5sum {filename} >> hashresults.txt
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Note that using md5sum to confirm the file is unchanged does not prove its
authenticity or guarantee confidentiality. It also does not prove the file contents are
safe. Hashing shows that the file contents—whatever they may be—are unchanged.
SHA Commands
There are several different commands that you can use to calculate SHA hash
values. These commands are functionally identical to md5sum but use the SHA
function with the applicable bit size.
• sha1sum
• sha256sum
• sha384sum
• sha512sum
The syntax of the sha#sum commands is sha#sum [options] [file
name]
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
6
Certificates
Answer the following questions:
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 12C
Understand Authentication
4
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Authentication Methods
There are multiple ways of proving identities beyond the use of passwords. Tokens
and biometrics enhance password-based authentication methods. Linux servers are
configured via the System Security Services Daemon (sssd) to use these methods
for centralized authentication with services such as Lightweight Directory Access
Protocol (LDAP) servers.
Tokens
A token is any unique physical or digital object that you can use to verify your
identity. Tokens are typically used to generate one-time passwords (OTP),
which are passwords that either expire after first use or within a small time
period, or both. In either case, OTPs are not meant to be memorized like normal
passwords. Tokens can also leverage digital certificates as authentication
information.
A hardware token is a physical device that generates and stores the authentication
information, and that information is tied to that particular device. One common
example is a key fob that generates and displays a numeric token on the key fob’s
small screen. RSA SecurID® is the most popular security key fob.
Software tokens, on the other hand, are generated by a system that can
distribute the authentication information to authorized general-purpose devices,
including smartphones and desktop computers. RSA SecurID also has a mobile
app for this purpose, and apps like Google Authenticator can generate one-time
tokens.
Multifactor Authentication
Authentication methods can make use of several factors. These factors are
typically expressed as something you know, something you have, and something
you are.
Multifactor authentication (MFA) is the practice of requiring the user to
present at least two different factors before the system authenticates them.
This helps prevent unauthorized access when one factor is compromised (for
example, when an attacker guesses a user’s password). Tokens and OTPs
(something you have) are commonly used as the second factor after the user’s
standard password. On more advanced systems, biometrics (something you are)
is also used as a factor.
For a system to enforce MFA, it must incorporate more than one factor, not more
than one method. For example, using a hardware token and a software token
would not qualify because they are the same factor (something you have).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
A user employs both a password and a security token as part of the multifactor authentication
(MFA) process. When the LDAP server confirms both elements as correct, the user may access the
secure network. (Images © 123RF.com.)
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
PAM Configurations
PAM configuration files are located in the /etc/pam.d/ directory, where each
PAM-aware service or application has its own file. Each file includes directives,
formatted in the following way:
<module interface> <control flag> <module name> <module arguments>
Module interfaces define functions of the authentication/authorization process
contained within a module. Control flags indicate what should be done upon the
success or failure of the module. The module name defines the module to which
the directive applies. Module arguments are additional options you can pass into
the module.
The four module interfaces are account, auth, password, and session. Account
checks to see whether a user is allowed access to something, auth is used to verify
passwords and to set credentials (such as Kerberos tickets), password is used to
change passwords, and session is used when performing tasks in a user session
that are required for access (such as mounting home directories).
There are also four control flags. When the optional flag is set, the module result
is ignored. The required flag mandates that the module result must be successful
to continue the authentication, and the user is notified when all tests in the module
interfaces are finished. The requisite flag is the same as the required flag except
for the requisite flag’s directive to notify the user immediately upon failure. The
sufficient flag states that the module result is ignored upon failure.
In some distributions, you may be able to configure PAM directly through the /etc/
pam.conf file. The syntax of this file is similar to individual files in the /etc/
pam.d/ directory.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
5
Authentication
Answer the following questions:
2. What is the relationship between PAM modules and PAM control flags?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 12D
Configure SELinux or AppArmor
3
What is SELinux?
Security-Enhanced Linux (SELinux) is the default context-based permissions
scheme provided with CentOS and Red Hat Enterprise Linux and is available on
other distributions. It was developed by the U.S. National Security Agency (NSA).
It provides additional file system and network security so that unauthorized
processes cannot access or tamper with data, bypass security mechanisms, violate
security policies, or execute untrustworthy programs.
SELinux enforces mandatory access control (MAC) on processes and resources
and enables information to be classified and protected based on its confidentiality
and integrity requirements. This helps mitigate the damage caused to information
by malicious applications and users.
SELinux Contexts
SELinux contexts (labels) define resource access. Access issues may be related
to incorrect labels, and relabeling the resources can help resolve such problems.
The autorelabel feature of SELinux allows sysadmins to cause contexts to be reset
throughout the filesystem.
SELinux defines three main contexts for each file and process. When you list an
object’s contexts, each one is delineated by a colon.
• User: This context defines how users can access the object. Note that this
does not refer to Linux system users but rather distinct SELinux users. Each
Linux system user is mapped to one of these SELinux user values. Different
distributions provide different users, but common ones include:
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
• Role: This context defines what roles can access the object. SELinux users are
authorized to be in roles. Roles are typically used to permit or deny users access
to domains, which apply to processes. The object_r role applies to files and
directories.
• Type: This context is the “label” portion of MAC and is perhaps the most
important context for fine-grained access control. It is a way of grouping objects
together that have similar security requirements or characteristics. The word
type usually applies to files and directories, whereas a domain is just a type that
applies to processes. For example, ssh_t is the domain for the SSH process.
List running processes along with each process’s security context. You can check the
context of specific processes by issuing:
#ps -Z {PID}
Change Security Contexts
Once you understand the resource’s current SELinux context, you can decide
whether it’s appropriate to change that context. The chcon command temporarily
changes the security context of a file.
The basic syntax of the chcon command is:
chcon {-u|-r|-t} {context value} {file or directory
name}
where {-u|-r|-t} refers to user, role, or type, respectively.
If the filesystem is relabeled or the restorecon command is used, the file’s
context is reset, restoring the default security context.
The syntax of the restorecon command is:
restorecon {file-name or directory-name}
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Thank you,
Rey Harper
Jr Sysadmin
Date last updated 2024-08-21
Three modes define how SELinux applies to the system. Think of these modes as
either turning on or turning off SELinux security. You can switch between the modes
on the fly, making configuration and troubleshooting easier.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Once the problem is resolved, be sure to switch back to Enforcing mode with this
command:
# setenforce 1
The purpose of Permissive mode is for testing and troubleshooting. If you are
attempting to resolve resource access issues that you believe may be related to
SELinux, you can temporarily set the mode to Permissive and attempt the access
again. Your results show you specific information:If you could not access a resource
when SELinux was set to Enforcing, but you could when it was set to Permissive,
then SELinux is blocking the access.If you could access the resource in Permissive
mode but not in Enforcing mode, SELinux logs the policy that blocked your access.
Examining the log file allows you to identify which policy needs to be updated to
resolve the access control issue.If you could not access the resource in Permissive
mode, then it is likely that some other security layer, such as standard permissions
or access control lists, is denying access.
Setting the mode to Permissive is an important troubleshooting suggestion.
Disabling SELinux is not recommended.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Command Purpose
semanage Configure SELinux policies.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
What is AppArmor?
AppArmor is an alternative context-based permissions scheme and MAC
implementation for Linux. Whereas SELinux is more commonly associated with
RHEL, AppArmor is packaged with Debian-based and SUSE Linux distros.
AppArmor provides the same fundamental service as SELinux provides, but its
approach is different in many significant ways. Perhaps the most overarching
difference is that SELinux is very complex and often difficult to configure, whereas
AppArmor was designed to be much simpler.
Functionally, the main difference is that AppArmor works with filesystem objects
based on paths, whereas SELinux references inodes directly. These paths are
referenced in flat configuration files, or profiles, that AppArmor uses to determine
how to control access. This also means that there are no types or domains in
AppArmor, only these profiles.
AppArmor Profiles
Each executable can have an associated AppArmor profile. Profiles are located in
the /etc/apparmor.d/ directory. Within this directory are several text files
that are named in a path.binary format. For example, the /bin/dig command
binary’s AppArmor configuration file would be located at /etc/apparmor.d/
bin.dig.
Within a profile, you can configure two main types of rules: capabilities and path
entries. Capabilities provide the executable in question access to some sort of
system functionality. For example, the net_bind_service capability enables the
executable to bind to a well-known TCP/IP port (port numbers below 1024).
Path entries enable the executable to access a specific file on the file system. As the
name suggests, you reference the files by their paths. After the path, you specify
what permissions you want to grant to this executable for the files. There are
several possible permissions, including r for read, w for write, ux for unconfined
execute (file being accessed doesn’t have a profile), l for link, and so on.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Each profile operates in one of two modes: complain and enforce. In complain
mode, profile violations are logged but not prevented. In enforce mode, profile
violations are both logged and prevented.
AppArmor Tunables
Tunables enable you to configure AppArmor functionality without directly modifying
profiles. For example, profiles may reference a common object or path using a
variable name, such as @{HOME} to refer to the user’s home directory. If the user’s
home directory is not in the default location, you can adjust the appropriate tunable
file to account for this. Tunable files are located in the /etc/apparmor.d/
tunables/ directory.
AppArmor Commands
The following table describes some of the major commands that you can use to
configure an AppArmor environment.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
SELinux and AppArmor
4
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 12
Summary
4
Solid hardening practices are critical to Linux system security. Begin with a security-
oriented mindset by integrating DevSecOps practices into all aspects of system and
application development security. Use encryption as appropriate to secure data in
transit, in use, and in storage. Carefully control authentication processes to ensure
only authorized users access your systems. Finally, rely on technologies such as
SELinux and AppArmor to provide more granular control to access your resources.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
The ability to automate and schedule complex tasks on a Linux system relies on
Bash scripting. Scripts can be as simple or complex as necessary to accomplish the
goal. One of the benefits of a script is that it executes the same way every time,
rather than relying on an administrator to recall the proper order of operations or
avoid typographical errors.
Scripts are also capable of running a set number of times, for example, while
a value is true. They can also compare values and use if/then logic to process
information differently depending on the contents.
This Lesson begins with simple scripting basics and then addresses various scripting
techniques that increase flexibility.
Lesson Objectives
In this lesson, you will:
• Understand Bash scripting basics.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 13A
Understand Bash Scripting Basics
2
Scripts provide scheduled, repeatable sets of commands that run the same way
each time they execute. Such consistency and flexibility make them a powerful
tool for administrators. You must understand how to write scripts that call the
appropriate shell and are well-documented. In addition, scripts need the execute
permission to run and must either be placed in specific locations or you must issue
special instructions to Bash to run them.
• Speed: Scripts execute commands more quickly than humans can type them.
• Accuracy: Scripts are less likely to produce errors than humans would likely
produce them when typing commands.
• Scheduling: Using tools such as cron and systemd timers, you can schedule
scripts to begin at certain times.
Script Comments
In the world of programming, comments are a method of annotating source code
so that it is easier for the author and other programmers to understand. In most
languages, comments are ignored by the system that compiles, interprets, or
otherwise executes the program. Therefore they exist as a way to document various
elements of the code within the code itself.
In Bash, the number or pound sign (#) indicates that every character after it on
that line is part of a comment and is not to be executed. Although you are free to
comment your code how you want, it’s usually good practice to include one or more
comment lines at the top of the script that explain what that script does and to
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
comment each line or code block that may require explanation. You should refrain
from commenting on a line of code with an obvious purpose. Too many comments
can clutter the source code and make it harder to understand.
This is an example of a short script with comments:
# This script determines how many files are remaining
to process in a directory.
num_files=432
# current number of files
processed
total_files=512 # total number of files to process
echo "There are $((total_files - num_files)) files
remaining."
Thank you,
Rey Harper
Jr Sysadmin
Date last updated 2024-08-28
One of the system variables is $PATH. This value specifies where Bash looks for
executable files. When you run a command, Bash doesn’t search every directory
on the storage disk looking for the command’s executable. That would be very
inefficient and time-consuming. Instead, Bash standardizes a few specific locations
for executables and only checks there. For example, Bash knows to check the /bin
and /sbin directories.
Bash doesn’t check custom directories or user home directories (even the /root
directory). However, it’s common for administrators to write and save scripts in
their home directory. To cause a script to execute from a directory that is not part
of $PATH, you must type ./ before the script name. This causes Bash to check the
current directory for the executable, which it normally would not do.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Script Permissions
Remember, your ability to use any file, including a script, is constrained by the
permissions assigned to that script. Even though you created the script, you won’t
automatically have permission to run it. You need to make sure two permissions
are set for each user who needs to run the script: the execute (x) bit on the script
itself and the (w) and execute (x) bits on the directory containing the script.
You can set these permissions using chmod just as you would with any other file.
File Extensions
For the most part, file extensions in Linux are optional. Linux checks a file’s
metadata to determine what type of file it is. This goes for Bash scripts as well—you
don’t need to name your scripts with an extension. However, many developers have
adopted the convention of adding .sh as an extension to their shell scripts, such as
myscript.sh. While this does not imbue the script with any special meaning, it can
make it easier for a person to identify that a file is indeed a script. Including a file
extension can also help search operations in which you only want to look for or
within shell scripts.
Script Syntax
Not only is Bash the default shell in Linux, but it is also a powerful scripting
language. Creating Bash scripts is incredibly useful in increasing the efficiency
and productivity of your Linux administration tasks. Bash scripts can make Linux
system calls and leverage existing tools in the user space. Essentially any program,
tool, utility, or system function that you can call at the command-line, you can
also invoke in a Bash script. Likewise, Bash scripts support modern programming
elements like loops and conditional statements to enhance the logic of the task(s)
being automated.
Just as commands at the CLI have a syntax, so too do scripting languages. A
language’s syntax defines the rules for how you write the code. Each language has
its own syntax, but many share a few commonalities. Because of its association with
the underlying Linux operating system, the syntax of a Bash script is very similar to
what you’d input line-by-line at a CLI.
sh-bang
Bash scripts contain shell-specific instructions that may not be compatible with
other Linux shells. This will result in a Bash script running on Bash shells correctly,
while failing on other non-Bash shells in Linux. To specify that your script is written
for the Bash shell, you need to add the line #!/bin/bash at the beginning
of each script. This line will instruct the operating system to use the Bash shell
interpreter when executing a script on an incompatible Linux shell.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Script Basics
3
1. What is the purpose of sh-bang, and how would you configure the value
for Bash?
2. How does Bash handle lines that begin with the # character?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 13B
Use Shell Script Elements
3
This topic introduces the elements of a script. The features discussed can be
combined and used in an almost unlimited manner to gather the information
Linux users need. Bash scripts use many of the same commands as users do at the
command prompt, but the ability to combine these commands and the output they
generate makes scripting incredibly powerful.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
You can also use the exec command without another command as an argument
to redirect all output in the shell to a file. This is commonly used in scripts to
suppress stdout at the CLI and instead send it only to one or more files. For
example:
#!/bin/bash
exec > out.txt
pwd
ls -al
The current working directory and directory listing will output to out.txt and not
the CLI.
The source command is used to execute another command within the current
shell process. In this sense, it performs the opposite functionality of the exec
command. This is useful when you’d like to stay within your current shell while
executing a script. One example is sourcing a script that performs a change of
directory (cd). After the script executes, your location will be whatever the directory
was changed to, whereas executing the script normally would keep you where
you are.
Another situation where you might want to source a script is when your script
changes or defines environment variables. For example, the following script (export.
sh) exports a custom environment variable named MYVAR:
#!/bin/bash
export MYVAR=1
If you execute this script normally and issue the env command, you’ll see that
MYVAR is not listed. This is because the script spawned a new shell process, and
once it terminated, its changes to the shell environment were destroyed. However,
if you enter the command source export.sh, then the environment variable
will be maintained because the script executes in your current shell.
String Literals
A string literal is any fixed value that represents a string of text within the source code.
String literals are enclosed in single (') or double (") quotation marks. As long as
you are using them consistently, either type of mark is acceptable for basic string
output. However, there are circumstances where double quotes won’t preserve the
literal value of all characters within the quotes.
For example, say you’ve defined the my_str variable mentioned previously. You then
want to substitute this variable into a larger string literal:
echo "My variable is $my_str"
echo 'My variable is $my_str'
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The first line, because it is using double quotes, will print “My variable is Hello,
World!” The second line, because it uses single quotes, will literally print “My
variable is $my_str”. Therefore, you must be careful to use the correct type of
quotation mark depending on your intent.
It’s not always necessary to use a string literal. If you don’t wrap the previous echo
example in any quotation marks, then it will by default produce the same output
as if you had wrapped it in double quotes. However, it’s still good practice to wrap
strings of text in quotes just to be sure. When you assign values with spaces in them
to variables, you are required to use quotes.
Escape Characters
In any language, Bash included, certain characters have special meaning. An escape
character is used to remove that special meaning so the character can be used
literally rather than interpreted as something else by the system. This is similar to
using a string literal, but in the case of an escape character, you’re only removing
the special meaning from one character at a time.
In Bash, the escape character is a single backslash (\). For example, let’s say you
want to print a string to the command-line that contains a dollar sign. The dollar
sign has a special meaning—it is used in variable substitution. You can handle this
by using single quotation marks:
echo 'This $var is escaped'
Alternatively, if you wanted to use double quotes or no quotes at all, you could
enter either of the following:
echo "This \$var is escaped"
echo This \$var is escaped
Notice how the backslash escape character precedes the dollar sign, which is the
character you want to be interpreted literally.
Arrays
An array is a collection of values. In other words, an array enables you to store
multiple values in a single variable. This can make your code much easier to read
and maintain. For example, you might want to perform a single mathematical
operation on dozens of different values. Instead of creating a variable for each
value, you can create an array to simplify your code. Another benefit of arrays is
that you can easily update their values throughout the code.
Arrays are ordered based on their indices. Most languages start an array with
an index of 0. When you assign values to an array, you can usually perform a
compound assignment to assign all values at once. The order you place each value
in the compound assignment will determine its index—i.e., the first value will be
at index 0, the second at index 1, and so on. Languages like Bash can also use
individual assignments to assign specific values to each index.
Compound assignment in Bash arrays uses parentheses with each value separated
by a space:
my_arr=(1 "Hello" 3.1)
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Display the exit code for the most recent command by using the following
command:
# echo $?
Attempting to add a new user resulting in the error message "Permission denied.” The CLI output,
when queried with echo $?, shows the error code 1. All failures will result in an exit code that
is a nonzero number.
Many Bash scripts call upon other scripts or enable the user to leverage system
commands with the script. Exit codes are useful because they can help these
external entities detect whether initial script execution was successful and then
potentially change their behavior based on this exit code.
By default, a Bash script will generate an exit code of the last command that was
run. You can also specify exit code behavior yourself. The exit code of the last run
command is represented by the $? special variable. You can, for example, redirect
the exit code to standard output (stdout) and/or standard error (stderr). For
example:
#!/bin/bash
chmod 888 file
echo $? >&2
The script contains an error (there is no permission 888 value). These instructions
will redirect the exit code 1 to stderr. Likewise, you can use input redirection to take
an exit code from standard input (stdin) into a Bash script.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Regular Expressions
Regular expressions (or “regex” for short) are designated characters that make
pattern-matching and searching easier by representing different types of data.
Tools such as grep, sed, tr, and others use regular expressions as part of their
pattern-matching function.
Here are a few simple examples of using regex. Regex is capable of providing very
complex pattern-matching to find exactly the information requested.
To search for strings that begin with the character d, type:
$ cat textfile | grep ^d
To search for strings that end with the character z, type:
$ cat textfile | grep z$
The xargs Command
The xargs command reads from standard input and executes a command for
each argument provided. Each argument must be separated by blanks. The pipe
operator is used to make the output of the first command the input for the second
command. The xargs command is commonly used with the find command to
operate on each result that is found within the file or directory search.
Changing the permissions for all files that match a given pattern.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The cut command extracts the specified lines of text from a file. Cut is another
example of a command you might find in a file manipulation script.
Standard Redirectors
The standard way of inputting data to the computer is the keyboard, and the
standard way for the computer to output data back to you is the monitor. These
mechanisms are called stdin and stdout. In addition, error messages are also
output to the monitor by default.
It’s possible, however, to change these standard methods by redirecting the
output of commands elsewhere. You can also change where the system gets its
information. For example, the system can use a text file as a source of input instead
of the keyboard. Changing these mechanisms is called redirection.
Redirection
Operator Action Example Result
> Redirect the ls > file1.txt The output of the
standard output ls command is
to a file. redirected to a file
named file1.txt
>> Append the ls >> file1.txt The output of the
standard output ls command is
to the end of the appended to a file
destination file. named file1.txt
2> Redirect the ls file3.txt 2> The output will not
standard error errorfile.txt be displayed on
message to a file. the screen but is
redirected to a file
named errorfile.txt
2>> Append the ls file3.txt 2>> The output will not
standard error errorfile.txt be displayed on
message to the end the screen but is
of the destination appended to a file
file. named errorfile.txt
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Redirection
Operator Action Example Result
&> Redirect both the ls file1.txt file3.txt The output will not
standard output &> errorfile.txt be displayed on
and the standard the screen but is
error message to redirected to a file
a file. named errorfile.txt
< Read the input mail user@address The myletter.txt
from a file rather < myletter.txt file is taken as the
than from the input and attached
keyboard or to the email
mouse. message.
<<{string} Provide input data cat <<EOF The cat command
from the current This is a here will use the rest of
source, stopping document. the lines in this file
when a line EOF as input. It will stop
containing the accepting that input
provided string when it reaches
occurs. When the string EOF.
placed in a script, This string can be
this is called a here named anything
document. you want. The
output of the cat
command would
therefore be: This is
a here document.
This table is provided for reference and was covered previously in Lesson 4.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Script Elements
4
1. How might you combine the echo and read commands in a script to
guide users through a process?
2. You’ve created a script that includes the string dev=web server. The
script throws an error indicating too many arguments for the dev
variable. How could you set the dev variable to see the words web and
server as a single value?
3. You need to use the sed command to find a value ’server’ and replace it
with the value ’system’ in a file named inventory.txt. What is the syntax
to accomplish this?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 13C
Implement Scripts with
Logical Controls
4
Understand Variables
Variables refer to entities whose values change from time to time. Most variables
are set either by the operating system when you log in or by the shell when it
is initially invoked. Variables are the key components that comprise the shell
environment. When you want to change the details of an environment, you change
its variables and their values.
Variable assignment is the act of defining a variable as having a certain value. In
code, you assign values to variable names. The values in a variable may change
throughout the script’s execution, but this is not required. The purpose of variables
is to store values for later use and to enable you to reference these values without
explicitly writing them out in the code.
In Linux, variables can be categorized as shell variables or environment variables. Shell
variables, by default, do not have their values passed on to any child processes that
spawn after them. Environment variables, on the other hand, do get passed on.
Set Variables
To set a shell variable, simply enter VAR=value such as MYVAR=123
In order to reference a variable, you must type it in this format:
${VARIABLE NAME}
Bash variables are assigned as follows:
my_str='Hello, World!'
Note the lack of white space around the equal sign (=) in these commands—this is a
strict rule in Bash.
Retrieve Variables
To retrieve the value of a variable, you can enter echo ${VARIABLE NAME} at
the CLI. For example, echo $SHELL will print your default shell (e.g., /bin/bash).
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Environment Variables
An environment variable is a variable that is inherited from parent shell processes and
is subsequently passed on to any child processes. An environment variable consists of a
name, usually written in uppercase letters, and a value, such as a path name.
Within the environment, variables are referenced as key–value pairs in the format
KEY=value and KEY=value1:value2 for variables with multiple values.
Some of the default environment variables and their functions are provided in the
following table.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Modify Variables
The export Command
You can effectively change a shell variable into an environment variable by using
the export command. For example, if you have a shell variable SHL_VAR, you can
enter export SHL_VAR to make it an environment variable.
You can also change the value of a variable while exporting it, including existing
environment variables. You can do this by entering something similar to export
SHL_VAR="New value" at the CLI. This will set the value for all child
processes spawned from this shell.
To set the value of an environment variable for all future Bash sessions, you can add
an export statement to your .bash_profile file. To automate this process for new
users, and to ensure those with similar job roles have the same environment variable
settings, you can modify the .bash_profile file in the /etc/skel/ directory. To
set the value of an environment variable system-wide, add an export statement to
the appropriate file in the /etc/profile.d/ directory.
The syntax of the export command is export [options]
[NAME[=value]]
Use the env Command
The env command is used to run a command with modified environment variables.
By supplying the name of a variable and a value in the key–value pair format, as well
as supplying a command to run, you can change the value of the specified variable for
that particular command session. If the variable does not exist, it will be added to the
environment. Likewise, you can use the -u option to remove the specified variable
from the environment in which the specified command runs. Consider using env if you
want to override values in child processes or add new ones.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Issuing the command without any arguments will display all variables in the
environment as well as their corresponding values.
The syntax of the env command is env [options] [NAME=value]
[command]
Use HISTFILESIZE
HISTFILESIZE is an example of a shell variable that enables you to set the
maximum number of lines contained in the command history file. It also enables
you to specify the number of lines to be displayed on running the history
command. For example, by assigning a value of 20 to this variable, the history
file gets truncated to contain just 20 lines. The default value of this variable
is 1,000.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Ensure values are set for any environment variables that a software package has
a dependency on. For example, if a Java application relies on the Java runtime
environment, it may only be able to find and access that runtime environment if it is
referenced in the PATH variable.
Conditionals
Some scripts can remain simple, but the true power of scripting comes from being
able to control the flow of logic as it executes. In this topic, you’ll augment your
scripting skills through the use of conditional statements and loops.
A script’s logic determines how it will process written code during execution. In
Bash, as in most languages, there are various ways to design the logic of the code to
essentially accomplish the same results in execution. Logic is therefore important in
maximizing the efficiency and readability of code.
One of the most important components for implementing programming logic is a
control statement. A control statement begins a section of code that will define
the order in which instructions are executed. By controlling the flow of these
instructions, you can write scripts to follow one or more paths based on certain
circumstances.
A conditional statement is a control statement that tells the program it must make
a decision based on various factors. If the program evaluates these factors as true,
it continues to execute the code in the conditional statement. If false, the program
does not execute this code.
Operation of a conditional statement, executing the code only if the condition is true.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The value of $var has changed since the previous example, which means that the
first echo command won’t execute. Rather than nothing happening, the else
statement specifies what will happen if the condition is false: in this case, it is to
print a different message to the screen.
The basic syntax of an if...else statement follows:
if [ <condition to be evaluated> ]
then
<code to execute if condition is true>
else
<code to execute if condition is false>
fi
The basic syntax of an if...elif statement follows:
if [ <condition to be evaluated> ]
then
<code to execute if condition is true>
elif [ <other condition to be evaluated> ]
then
<code to execute if other condition is true>
fi
Use Exit Codes with Conditional Statements
Conditional statements like if...else are good at handling process exit codes.
For example:
chmod 888 file 2> /dev/null
if [ $? -eq 0 ]
then
echo "Permissions set successfully."
exit 0 else
echo "Could not set permissions."
exit 1 fi
If the chmod command exits with a code of 0, then the success message is echoed
to the screen, and any other process that executes this script will receive that exit
code because of the exit command. Likewise, if the exit code is 1, then a custom
error message is echoed to the screen. The default error message is suppressed
because it is being redirected to the null device.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The first line in the case statement defines what variable it is that you’re
evaluating. Below that is the first condition, red, which has a closing parenthesis
to indicate the end of the condition. On the next line is the action that will be
performed if the color is indeed red—a message will display on the screen saying as
much. The double semicolons (;;) indicate the end of the action.
This pattern is repeated and can go on for as many conditions as you’d like. In this
case, the last condition uses a wildcard (*) to indicate that if the variable doesn’t
match any of the conditions above, then the following action will execute. The
esac statement ends the case statement.
The basic syntax of a case statement is as follows:
case <variable> in
<first condition>)
<code to execute if first condition is true>
;;
<second condition>)
<code to execute if second condition is true>
;; esac
The Bash case statement varies from the C or JavaScript language switch
conditional. While case stops searching for matches once a match is found,
switch continues checking. This is a good example of slightly different
functionality between languages. However, the terminology is sometimes used
interchangeably.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
These codes are different from the exit codes generated upon process termination.
For example:
var=/etc
if test -d $var;
then
echo "The $var directory exists!"
fi
This example uses the -d option to test whether a directory exists. There are
many such conditional options you can use. Consult the man page for the test
command to see them all.
Loops
Aside from conditional statements, another useful way to control the flow of logic
in a script’s code is by implementing loops. A loop is any control statement that
executes code repeatedly based on a certain condition. In general, loops are a
great way to keep a certain block of code active until it is no longer needed. There
are three types of loops supported by Bash: the while loop, the until loop,
and the for loop. All three types of loops are enclosed within the do and done
statements.
This loop will repeat a series of commands or instructions as long as the conditions on which it
depends are true.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Shell Expansion
When a command is issued at the Bash shell, it is split into tokens or words. Shell
expansion is the process by which the shell identifies special tokens for which
it substitutes values. Variable substitution is a type of shell expansion by which
the shell identifies the $ special character and then expands a variable into its
actual value. In other words, in echo $var, the echo command doesn’t “see” a
variable; it sees whatever the value of that variable is when Bash expands it.
There are actually several more types of expansions—eight in total. Bash performs
these expansions in a defined order, similar to an order of operations in a
mathematical expression.
1. Brace expansion
2. Tilde expansion
3. Concurrently:
b) Arithmetic expansion
c) Command substitution
d) Process substitution
4. Word splitting
For the four expansions that happen at the same time, the expansion is done in
left-to-right order as each appears.
Command Substitution
Command substitution is a method of shell expansion in which the output of a
command replaces the command itself. This is useful when you want to include a
command’s output within an existing string of text. For example:
$ echo "The current directory is ’pwd’."
Notice that the command pwd is enclosed within backticks (’). Depending on what
the current directory actually is, the output might be something like: The current
directory is /root.
You can also use the format $(command) to perform command substitution:
$ echo "The current directory is $(pwd)."
Lesson 13: Implementing Simple Scripts | Topic 13C
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The second format is preferred in Bash because using backticks requires escaping
certain characters (including nested backticks).
Globbing
Globbing is another name for file/path name expansion. This method of shell
expansion is used to replace a specific wildcard pattern with values that match the
pattern. There are three special characters used in globbing: the asterisk (*), which
is used to match any number of characters; the question mark (?), which is used to
match a single character; and characters within square brackets ([ ]), which are
used to match any of the characters listed.
The following are three examples of globbing.
$ cp *.txt ~/dest
This example with an asterisk (*) copies any and all files with a .txt extension.
This is because the wildcard character appears before the period, indicating
that Bash should expand any possible combination of characters.
$ cp ?.txt ~/dest
Using a question mark (?) in the syntax will only copy .txt files with a single
character as a name, like a.txt and b.txt, but not ab.txt.
$ cp [abc].txt ~/dest
The brackets ([ ]) example will only copy files named a.txt, b.txt, or c.txt.
Positional Parameters
A positional parameter is a variable within a shell script that is assigned to an argument
when the script is invoked. For example, you can invoke the script myscript.sh:
$ ./myscript.sh arg1 arg2 arg3
The arg1 argument corresponds to the positional parameter $1, arg2
corresponds to $2, arg3 corresponds to $3, and so on. Note that the space
between arguments is used to separate positional parameters.
You can reference positional parameters directly in your scripts as you would for
any other variable:
#!/bin/bash
echo "The first argument is $1"
echo "The second argument is $2"
echo "The third argument is $3"
This is useful because your script can perform various operations on any arguments
that are passed to it, as most scripts and commands do.
You can also set positional parameters directly in your scripts by using the set
command. For example:
#!/bin/bash
set -- arg1 arg2 arg3
echo "The first argument is $1"
echo "The second argument is $2"
echo "The third argument is $3"
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
When this script is invoked without any arguments provided by the user, it will still
have positional parameters $1, $2, and $3 because they were set manually.
Operators
Operations enable you to perform tasks on the variables and values that you
specify in your code. In most cases, this task is the evaluation of an expression.
Operators are objects that evaluate expressions in a variety of ways, while operands
are the values being operated on.
There are many different kinds of operators that apply to most languages.
Arithmetic operators include addition, subtraction, multiplication, division, and
more advanced mathematical operations. Comparison operators include checking
whether operands are equal, whether one operand is less than or greater than
another operand, and more. Boolean (logical) operators connect multiple values
together so they can be evaluated, and they include AND, OR, and NOT. Finally,
string operators are used in operations that manipulate strings in various ways,
including concatenating strings, returning a specific character in a string (slicing),
verifying whether a specific character exists in a string, and more.
- Subtraction
* Multiplication
/ Division
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Schedule a Script
One of the biggest benefits of scripting is the ability to schedule tasks. By creating
a script and then telling the system to execute the script (and everything in it),
administrators can automate anything from backups to software updates to system
configurations.
Both the cron utility and systemd .timer files give administrators many options for
scheduling tasks.
Edit the crontab file with the following information to schedule the backup.sh script
to run at 2 a.m. daily:
0 2 * * * /scripts/backup.sh
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Logical Controls
5
1. You are exploring your local (shell) variables on each system that you
manage. The first variable you check is the SHELL variable. How can you
check the SHELL variable, and what do you expect it to display?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 13
Summary
4
You are encouraged to use the many scripts that are available on the Internet.
Apply the content of this lesson to those scripts to understand how the script
functions before running it. You can also create your own scripts. Start simple,
and then add complexity and features as you master each technique.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
DevOps informs the use of Infrastructure as Code, a sysadmin approach to
managing system deployments and configuration. By treating configuration files
as code and enforcing version control and change tracking on them, organizations
seek to bring greater stability, security, and automation to their environments.
The combination of orchestration tools, such as Ansible, and file management
tools, such as Git, brings Infrastructure as Code to the forefront of administrator
responsibilities.
Lesson Objectives
In this lesson, you will:
• Understand infrastructure as code.
• Implement orchestration.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 14A
Understand Infrastructure as Code
2
DevOps Concepts
DevOps is an amalgamation of software development and systems operations. It is
characterized by a shorter development life cycle, reducing the time between product
changes and the integration of those changes in the production environment.
With this shorter turnaround time, DevOps provides continuous integration and
continuous deployment (CI/CD) within a faster and more reliable workflow.
Many organizations are changing their culture to shift IT staff to a DevOps structure.
This impacts Linux sysadmins immensely. You can expect to work more closely with
developers, deploy incremental changes quickly and often, and experience greater
use of automation tools. The shared ownership between dev teams and ops teams
provides robust support, along with rapid feedback to identify and correct issues.
DevSecOps integrates security practices to the entire development life cycle instead
of treating security as a separate component. DevSecOps was discussed in an earlier
section.
Linux administrators may immediately begin working with DevOps practices while
using automation and orchestration tools, such as Ansible and Chef, or by using
version control and repository software, such as Git.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The CI/CD loop. Software development can be viewed as always in motion with no set ending, only
moving on to the next phase of the process.
Once the appropriate DevOps tools are in place, how might an organization use
CI/CD, and what is the role of a Linux administrator? You might be involved in
the deployment of container images to a cloud service provider or the in-house
development and deployment of a Python application. Your organization might use
CI/CD to publish websites to internal webservers.
Linux administrators are traditionally part of the “operations” team denoted in the
DevOps phrase. You’re responsible for ensuring resource availability, performance,
and configuration and overseeing any tasks related to the infrastructure. However,
with the advent of DevOps, you’ll work more closely with developers on these tasks,
supporting some of the dev team’s functions while handing off control of some ops
roles to programmers.
To fulfill this role successfully, you’ll need to familiarize yourself with automation
and orchestration tools, as well as with version control.
Automation, orchestration, and version control are covered in the remaining sections of
this Lesson.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Bootstrapping
Once the installation process is complete, the system is ready for its first boot.
In the past, administrators would begin to manually configure security settings,
install patches and software, create local user accounts, set the root password, and
complete other post-install tasks. With the DevOps emphasis on automation, these
settings and others are now typically managed by cloud-init scripts.
As the name suggests, one common use of these scripts is the deployment of cloud-
based virtual machines. These deployments are often part of a larger orchestrated
process that does not leave time for administrators to perform specific tasks on
each VM. The cloud-init scripts automate such tasks, placing each VM in a
repeatable, well-known baseline state.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Infrastructure as Code
3
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 14B
Implement Orchestration
4
Orchestration Concepts
DevOps emphasizes task completion without human intervention. Like scripting,
orchestration and automation offer benefits that include consistent configurations,
repeatable deployments, greater efficiency, fewer errors, and nonmanual scalability
based on thresholds.
Orchestration enables the deployment of Infrastructure as Code configuration files.
In the previous section, the example of a software-package-repository configuration
was given. Once the configuration file (for example, a YAML, JSON, or plaintext
file) is written, it can be integrated into an orchestration process that ensures the
settings are enforced.
“Human intervention” might mean that an administrator initiates the process via a
command (such as running a script) or that a particular environment threshold is met,
causing the system to kick off the automated process.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
For example, here are five common administrative tasks. Each of these is
individually automated:
1. Recognize the need for an additional database server.
2. Deploy a VM.
However, as automated tasks, they are still initiated individually, resulting in five
distinct processes. Orchestration takes the five individual tasks and consolidates
them into a single event—the deployment of a fully-configured database server
ready for consumers.
The important aspect of orchestration is that a series of tasks are combined into a
single event that executes without human intervention.
Configuration Management
Automation and orchestration tasks are also related to configuration management,
or the process of ensuring systems are configured to match security and
performance requirements. IT departments have long attempted to maintain
standardized settings across servers, but configuration management takes that goal
to a new level through integration automation.
It’s worth pointing out that configuration management via orchestration is different
from provisioning via orchestration. Provisioning refers to deployment tasks,
while configuration relates to defining settings after the deployment process is
complete. Some organizations select one tool for provisioning and a different tool
for configuration management.
Consistent configuration management is essential to avoid undocumented or
unapproved changes that may result in security breaches or downtime.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Ansible
Attributes of Ansible Benefits of Ansible
Common for Red Hat Enterprise Linux Cross-platform configuration (though
deployments Ansible itself runs on Linux)
Many orchestration management tools Configuration files are relatively easy to
read and author
Agentless Can configure containers, physical or
virtual servers, and those servers may
be on-premises or cloud-based
Can use declarative or imperative
methods
Stores configurations in reusable
modules
Relies on Python
YAML configuration files
Ansible's management platform is hosted on Linux. However, Ansible can manage the
configuration of Windows target systems.
Puppet
Attributes of Puppet Benefits of Puppet
Enables orchestration and DevOps Cross-platform configuration
processes
Enterprise and open-source versions Only applies a configuration if the
settings would change the system
(idempotency)
Uses reusable/shareable modules to Can configure containers and physical
contain specific automation tasks or virtual servers, and those servers
may be on-premises or cloud-based
Agentless
Declarative language
Recognizes configuration files in Bash,
Python, Ruby, YAML, and PowerShell
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Chef
Attributes of Chef Benefits of Chef
Three components: Cross-platform configuration
• Chef Workstation for management
instructions
SaltStack
Attributes of SaltStack Benefits of SaltStack
Event-driven automation Cross-platform configuration
Agent and agentless options Can configure containers and physical
or virtual servers, and those servers
may be on-premises or cloud-based
Python and YAML
Reusable configuration template called
a state
Imperative ordering and declarative
configuration
Terraform
Attributes of Terraform Benefits of Terraform
Agentless Cross-platform
Declarative language Incremental execution to only update
changed items
Uses Terraform configuration language Focused on configuration more than
provisioning
Primary/secondary topology
Note that Terraform's own term for their topology design has been deprecated.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Orchestration
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 14C
Manage Version Control with Git
4
If automation and configuration management relies on files that store settings and
provisioning details, then it becomes important to manage those files carefully.
This is another example of sysadmins borrowing a developer standard by using
the Git service for version control. The files relied upon by Linux itself, or Ansible,
Chef, Puppet, and other provisioning tools, may be stored in central repositories
accessed, edited, and updated by many people. Git allows the tracking of changes
and version control by using a simple but robust set of commands.
Git Concepts
Open-source software development, script management, and IaC are all file-based
solutions. As such, proper management of files is critical. Many proprietary version-
control methods exist, but in 2005, Linux Torvalds (the creator of Linux) released
Git, a free and open-source version-control system. Since then, Git has become the
de facto standard for version control.
Git excels at tracking and integrating changes, especially in the context of large,
distributed software-development projects where many programmers work on
different aspects of the same application. In addition to increased speed and
higher levels of file integrity, Git offers support for nonlinear and collaborative
development, making it useful across a number of different fields.
While Git is aimed at developers, it works for other version-control scenarios, including
authoring books and articles, outlining tutorials, developing recipes, creating music
sheets, and more.
There are many uses for Git, and those uses are not just for developers. Here are
four use cases, three of which apply directly to Linux sysadmins.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Git recently renamed a key concept in code management. The ”master” branch is now
called the ”main” branch.
Git Repositories
The core component of Git is the Git repository. This is a storage area where
versions of code and related files are stored. Version control is managed within this
local directory. The repository may be stored on a single developer’s workstation,
or this repository may be centrally stored and then cloned to the developer’s
workstation. Organizations may choose to have a centralized Git repository on-
premises or to use an online solution like GitHub. A centralized repository is not
required, however.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
There are a number of subcommands used with git, and the most often-used are
listed in the table below.
You’re probably most likely to use clone, add, commit, pull, push, and
status the most often.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The merge and rebase subcommands are slightly different. The merge
subcommand integrates changes into the main branch, and these changes are
tracked in the Git history. The rebase subcommand accomplishes the same task,
but it rewrites the Git history to make it appear all changes took place in a serial
fashion, when in reality they may have occurred in parallel by multiple developers.
The goal is a more streamlined history that is easier to review and understand.
Git in Practice
Here are three common scenarios for using Git. The first scenario creates a
local Git repository and adds files to manage. The second scenario builds on the
initial design by adding branching. The final scenario covers a more collaborative
situation.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
7. Retrieve the current status of changed files. If three files were being
worked on for a particular step in the project but only two were ready to
be committed at this time, they would show up here as “added” but not yet
committed. The commit process could be executed once edits to all three files
are complete:
$ git status
Continue working with your files, making commits whenever you want to
differentiate the updated version against the most recent previous commit.
Branching
Optionally, you can work with Git branches. In this example, you’ll work with an
existing repository that another Git user has established. You’ll create a new branch
to work with and merge changes into the original main branch. The goal is to create
a new code branch, make modifications, and then merge the code branch back into
the main branch.
1. Create a branch of the main copy of the code:
$ git branch newbranch
2. Make changes, and then integrate (merge) those changes back into the main
branch. This integrates the changes, creating a new-and-improved version
of the original. At this point, the branch that was being used to create the
changes can be removed. The changes are now a part of the main branch:
$ git merge newbranch
Collaboration
In this example, you’ll pull another Git user’s branch and push changes to the
remote repository. You can also view what other changes have been made by using
the git log command. This is an example process flow for collaborating with other
developers using Git.
1. Pull other developers’ proposed changes and merge them into the local
repository (the local working copy):
$ git pull otherbranch
2. Push your own changes to a remote repository. A development or IaC
environment will usually include a central repository, perhaps in the cloud,
and each developer has their own local copy of the repository. Changes made
locally can then be uploaded to the central repository using the git push
command:
$ git push <remote repository> mybranch
3. See what changes were merged and what other actions were taken on the
repository. Run the git log command inside the project directory. For
example, to see all of the commits in the last 10 days, type:
$ git log --since=10.days
You can use this information to troubleshoot any issues introduced in
configuration files, scripts, or any other data tracked by the repository.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
An example Git process flow. Users operate within the working directory, the staging area, the local
repository, and a remote repository with various git commands. (Images © 123RF.com.)
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Git
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 14
Summary
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
Containers provide fast, scalable deployments of applications on-premises and
in the cloud. Administrators often orchestrate container deployments to provide
consistency and agility. Containers virtualize at a higher layer than traditional
virtualization solutions that support virtual machines do. Container solutions begin
with a container engine that provides virtualization functionality. Next are the files
that make up containers, followed by the running containers.
For all the focus on container deployments, it’s important to recognize that more
traditional hardware virtualization still has its place, and Linux administrators will
frequently support virtualized devices.
Lesson Objectives
In this lesson, you will:
• Understand container basics.
• Deploy containers.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 15A
Understand Containers
2
Hardware virtualization and virtual machines are covered later in this lesson.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Common container engines for Linux include Docker, rkt, runc, and containerd.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Containers
3
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 15B
Deploy Containers
4
Getting started with containers only requires a container engine and one or
more images. Images can be pulled from container registries or created fresh on
your Linux system. Container engines have many commands to create, destroy,
start, stop, and otherwise manage containers to create robust, networked, and
interlinked environments.
The first portion of this section looks at container operations, such as building and
starting containers. The next part covers management tasks and commands. The
topic finishes by examining container registries.
ps List containers.
rm Remove containers.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
This scenario has you using a very lightweight Linux distribution named Alpine. This is a
very common container image to start with.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Recall that the image is a static template, and the container is a running instance of
that image. Run a container from the image:
$ sudo docker run {image-name}
However, if you need to work within the container itself, start it interactively by
adding the -it options. In this case, you will have a Bash shell:
$ sudo docker run -it {image-name} bash
You now have a running container. The Alpine image doesn’t do a lot, but it serves
as a starting point. It can be further customized with additional applications.
Check the status of containers on the system by typing:
$ sudo docker ps -a
The FROM line indicates which initial image will be used. The RUN line defines any
commands that will be executed. In this example, RUN indicates that the nano text
editor will be installed via the apt-get command.
Next, build the image. For Docker images, use the docker build command to
build the image from the Dockerfile. You can add the --tag option to provide the
image with a descriptive name.
$ sudo docker build --tag alpine
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Administer Containers
The docker container command manages attributes for specified
containers. The syntax for the docker container command is:
docker container subcommand {options} {arguments}
Some of the more common subcommands for docker container are listed
in the table below.
One of the first items you must know to manage running containers is the container
ID. This value is assigned to the container when it starts. To display running
containers, including their container ID, type:
$ sudo docker container ls
It may be necessary to restart the container. Now that you have the container ID,
type:
$ sudo docker restart {container-ID}
To stop a running container, type:
$ sudo docker stop {container-ID}
Container Registries
Container images are usually centrally stored in repositories known as registries.
Registries are an easy way to share images within a community, whether that
community is a single organization or the entire world. Registries are either public,
meaning that they are available on the Internet to anyone, or private and available
on a restricted network only to authorized users.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Many public registries exist. Docker Hub is very common, but Google, AWS, Microsoft,
and many other organizations also host registries.
Container Networks
Containers receive network access via network drivers. These drivers are configured
to match network- and container-communication requirements.
The various container network drivers provide different functions for administering
containers:
• host: Networking between the container and host with the use of the host’s
network access.
Network drivers such as overlay and bridge rely on Network Address Translation
(NAT) to track IP addresses between the containers, hosts, and remote services.
Orchestration Concepts
Initial container deployments tend to be straightforward. A container engine is
selected and installed, and a few new containers are deployed via images. Over
time, however, as the containers host more complex applications and as the
container topology scales, the environment needs more advanced features.
Tools such as Kubernetes provide orchestration and management features that
increase the reliability and features of the simpler container environments.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Container Deployment
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 15C
Understand Virtualization Concepts
4
Virtual Machines
Virtual machines are configured much like standard physical systems. An amount
of memory is allocated, storage is defined, processor access is granted, and
networking is configured—all of these attributes enable the VM to participate on a
network just like a traditional Linux server or workstation.
Virtual machines can host applications and services.
Diagram of a virtual machine configuration including a hardware layer, a hypervisor, guest VMs,
and a virtual machine manager.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Virtualization Tools
Many virtualization host servers will run Linux without a graphical user interface.
Such a configuration enables more hardware resources to be available to the virtual
machines. Management of the virtual machines must then occur at the command-
line. The common Linux virtualization engine is the Kernel-based Virtual Machine
(KVM).
The virsh command is an interactive shell to KVM virtual machines and includes
the following subcommands.
save {VM} {file-name} Save the state of a virtual machine with the
given file name.
Recall that one interesting aspect of command-line commands is the ability to add them
to a script. You could script the above VM deployment to automate the process, making
the VM deployment fast and consistent.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Virtual Networks
Virtualization also takes place at the network layer. Virtual machines (VMs) may
have one or more virtual network interface cards (vNICs). These vNICs are
configured like physical NICs and are attached to virtual switches. Each virtual
NIC has its own MAC address and IP address to permit the VM to participate on a
physical or virtual network as an independent node. In addition, the VM can join a
Virtual Local Area Network (VLAN). Virtual switches are used to better manage
network traffic.
Virtual machines can share a virtual bridge with the host device, which enables
network access for the virtual machines. Virtual machines typically have four
options for network access, each of which provides different operational
functionality.
• None: As if the virtual machine has no NIC installed.
• Local: Network access only to other virtual machines on the same host.
• Host-only: Access only to the host computer but not to the physical network or
Internet.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Virtualization
5
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 15
Summary
4
docker pull docker pull Pull an image from Lesson 15, Topic B
{image-name} a registry.
docker docker Manage Lesson 15, Topic B
container container attributes
subcommand for specified
{options} containers.
{arguments}
push Exact syntax Upload images to Lesson 15, Topic B
depends on the a registry.
specific container
engine.
pull Exact syntax Download images Lesson 15, Topic B
depends on the from a registry.
specific container
engine.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LESSON INTRODUCTION
Most operating systems follow the same boot path; it’s the utilities involved that
vary. For Linux, the primary boot loader that manages the startup process is
GRUB2. Once the system starts and the boot loader launches, it handles the process
until the Linux kernel starts and takes over. GRUB2 has specific configuration
requirements that involve assembling the main configuration file from a series of
supporting configuration files.
When deploying Linux, you must first decide on a physical or virtual machine
platform and then walk through a series of installation tasks that involve selecting
source files, hardware configurations such as partitioning, and software. Once the
installation is complete, you will manage post-installation tasks. These tasks consist
of final security settings and updates.
Lesson Objectives
In this lesson, you will:
• Understand the Linux boot process.
• Deploy Linux.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 16A
The Linux Boot Process
2
The boot process consists of many steps, which begin with the hardware layer and
move up through the BIOS, boot loader, Linux kernel, and authentication layers.
Understanding this process is helpful for troubleshooting and performance tuning.
The process requires many components, which this Topic covers.
Boot Sources
Installation files may be stored on various media and available from several
sources. Most organizations will have a standard Linux distribution for deployment
on internal systems.
Storage Disk
Typically the system BIOS/UEFI is configured to boot from the internal storage disk.
Source files may have been copied to the disk from a remote source or from a
currently installed operating system that you will replace.
USB
In this configuration, Linux would boot from a removable USB flash drive or storage
disk that contains the Linux source files. The system BIOS may need to be adjusted
to boot from USB storage rather than an internal storage disk or DVD drive.
Typically, you must configure USB disks to be bootable.
ISO Image
An ISO image is a system image, originally that of an optical disc. Today, it is a
common file format for packaging and distributing images of operating systems
that users can boot from to install the OS. Typically, you write the ISO image to an
optical disc or USB thumb drive, insert the media into the computer, and instruct a
boot environment like UEFI to boot from that media. ISOs are also commonly used
to construct virtual machines.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
PXE
Preboot Execution Environment (PXE) is a part of the UEFI standard that enables
a client to retrieve the necessary boot loader and system files from a server over
the network. The client configures UEFI to boot from PXE, and during the startup
process, it will search for Dynamic Host Configuration Protocol (DHCP) servers that
also act as PXE servers. Once the proper server is found, it transfers the necessary
boot files to the client over the Trivial File Transfer Protocol (TFTP).
BIOS/UEFI
The Basic Input/Output System (BIOS) is a standard for firmware interfaces
stored on a computer motherboard’s ROM chip. The BIOS firmware runs when
the computer powers on, enabling it to test the various hardware components
in a computer and run the boot loader to start the operating system. The BIOS
has access to the ports used by basic hardware input devices like a mouse and
keyboard. Users can also load up a BIOS interface instead of an operating system to
make various hardware-level changes. BIOS was the dominant standard for home
and enterprise computers for several decades.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The boot loader uses three main components that work together to load the
operating system in stages.
1. The boot sector program is loaded by a boot environment on startup and has
a fixed size of 512 bytes. Its main function is to load the second-stage boot
loader; however, it can also load another sector or a kernel.
2. The second-stage boot loader loads the operating system and contains a
kernel loader.
3. Finally, the boot loader installer controls the installation of drive sectors and
can only be run when booting from a drive. It coordinates the activities of the
boot sector and the boot loader.
The most common Linux boot loader is GRUB2. Details and modifications to the GRUB2
boot loader are covered in a later section.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The mkinitrd command creates the initrd image for preloading the kernel
modules.
The syntax of the mkinitrd command is mkinitrd [options]
{initrd image name} {kernel version}
The mkinitrd command uses several different options, collected in the table
below.
The following example creates an initrd image from the current kernel version and
names the image initrd-<kernel version>.img
# mkinitrd /boot/initrd-$(uname -r).img
$(uname -r)
The dracut command can also generate an initramfs image, similar to how
mkinitrd generates an initrd image. In fact, on some distributions, mkinitrd
is a compatibility wrapper that calls the dracut command.
The following is an example of using the dracut command to create an initramfs
image:
# dracut /boot/initramfs-$(uname -r).img
$(uname -r)
The /boot Directory
As defined by the Filesystem Hierarchy Standard (FHS), the /boot/ directory
contains files that facilitate the Linux boot process.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The /boot/grub directory contains configuration files for a type of boot loader
called GRUB2. The /boot/grub2/ directory does likewise, but it does so for
GRUB 2, which is an improved version.
The /boot/efi directory contains boot files for an EFI system partition (ESP),
which is a required partition for systems that boot from UEFI. It contains boot
loader, device driver, and system application files that are executed by UEFI. Boot
loader files are typically named with an .efi extension.
The /boot/initramfs<kernel-version>.img file is an initramfs
image, which is an alternative to initrd that uses different methods to do the same
basic thing: initialize a temporary root file system on boot. Whereas initrd requires
a special driver to be compiled into the kernel, initramfs does not. In addition,
the initrd image is a block device formatted with a fixed-size file system, while the
initramfs image is an archive file that can be sized dynamically.
/boot/vmlinuz-<kernel-version> is a compressed executable file that
contains the Linux kernel itself. The boot loader loads this file into memory during
the boot process to initialize the operating system. A related file is vmlinux,
which is essentially the non-compressed version of the kernel used for debugging.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
1. The processor checks for the BIOS/UEFI firmware and executes it.
2. BIOS/UEFI checks for bootable media from internal storage devices or peripherals
like USB flash drives and DVD-ROMs. It locates a valid device to boot the system.
3. BIOS/UEFI loads the primary boot loader (probably GRUB2) from the MBR/GPT
partition into memory. It also loads the partition table along with it.
4. GRUB2 prompts the user to select an operating system to boot. If the user
does not respond, then the default operating system is booted.
5. The boot loader determines the kernel and locates the corresponding kernel
binary. It then uploads the respective initrd image into memory and transfers
control of the boot process to the kernel.
7. The kernel mounts the main root partition and releases unused memory.
The systemd program runs to set up the user environment. It becomes
process ID 1.
9. If graphical mode is selected, then a display manager starts and the login
window is displayed on the screen.
10. The user enters a user name and password to log in to the system.
11. The system authenticates the user. If the user is valid, then various profile files
are executed.
12. The shell starts, and the system is ready for the user.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
3
1. Differentiate between the older system BIOS and the modern UEFI
standards.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 16B
Modify Boot Settings
4
The boot loader program manages the startup process. It offers OS selection
choices, loads the initrd file, and loads the kernel. The GRUB2 boot loader is found
on most modern Linux distributions and is highly configurable. The configuration
process is different from that of other services, so this section covers that process
and the tools needed.
Identify GRUB2
The GNU GRand Unified Bootloader (GNU GRUB) is a boot loader developed
by the GNU Project that became popular on Unix-like systems. It enables users
to choose which operating system or kernel version to boot in a multi-platform
environment. Although the original version of GRUB was the primary boot loader
for Linux distributions, it had several limitations and was eventually phased out in
favor of a newer version of GRUB. This original version is sometimes referred to as
GRUB legacy.
GRUB2 is more than simply a newer version of GRUB; it is a complete redesign and
rewrite of the legacy GRUB system. GRUB2 offers administrators more control over
the boot process, boot devices, and boot behavior. In addition, it comes with several
improvements, including:
• Support for non-x86 architecture platforms.
• Support for live booting (booting an OS from storage media and running the OS
entirely in memory, without installation).
• Rescue mode, which attempts to fix boot issues like corrupted or missing
configurations.
Because of these improvements, GRUB2 has become the default boot loader on
almost all modern Linux distributions.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
You will rarely need to actually install GRUB2; it's usually part of the operating system
installation process.
Configure GRUB2
The GRUB2 boot loader is highly configurable. The grub.cfg file stores the
configurations, though administrators don’t edit this file directly. Instead, the
grub2-mkconfig command is executed to reference multiple configuration files
and assemble a correct grub.cfg file. Any mistakes to this file can cause boot errors
on the system.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
This file is an executable shell script. Don’t edit this file directly, as it is generated
using the grub2-mkconfig command that leverages configuration scripts stored
elsewhere on the file system. This command is covered later in this section.
The /etc/grub.d/ directory contains scripts used to build the main grub.
cfg file. Each script provides various functions to GRUB2 and is numbered so that
the scripts can execute in a sequence. It’s usually not a good idea to edit the existing
scripts in this directory. If you want to add a custom script, you can place it in this
directory with a ##_ file name prefix, depending on the order you want the script to
be executed. You can also add your script to the existing 40_custom file so that it
executes last by default.
Observe that the /etc/grub.d directory is stored in /etc, which normally stores system
configurations. However, the grub.cfg file is stored in the /boot directory. Some portions
of GRUB2 are stored in each location.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Hardware Problems
Boot problems could also be due to a failed or missing storage device as a result of
a hardware failure.
Swap potentially failed hardware with a known good device, or check for updated
device drivers.
Switched System
During the boot process, it’s possible that users may inadvertently switch from the
GUI target to the CLI target. In those instances, it’s helpful to be able to display your
current environment and be able to change to a different one if needed.
To display the current boot environment, type:
# systemctl get-default
To change the default boot target from CLI to GUI, type:
# systemctl set-default graphical.target
To change the default boot target from GUI to CLI, type:
# systemctl set-default multi-user.target
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Boot Settings
5
1. Why don’t you usually need to install GRUB2 on most Linux systems?
2. How is working with the grub.cfg file different from working with most
Linux configuration files?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Topic 16C
Deploy Linux
4
Manual Linux deployments usually guide users through the process of selecting
installation media, defining partitions, selecting software, and configuring post-
installation settings. While there are thousands of available Linux distributions (and
you can even create your own!), the installation steps are usually the same. It’s the
software that guides you through the process that differs.
Break the installation process into three steps:
• Prepare the platform.
• Install Linux.
Recall that since Linux is FOSS, it is easy to try out many different distributions.
Raspberry Pi
One inexpensive option for Linux is the Raspberry Pi hardware platform. These
small powerful systems easily run Linux and are very affordable. While Raspberry
Pi was originally created to introduce young people to development projects, many
production environments use Pi today.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
You are strongly urged to use the most current version of whatever Linux distribution
you select. These versions have the most up-to-date security patches and features.
A sample Linux installation screen. Most distros start with similar-looking configuration options.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Non-root administrative accounts are more restricted than root user accounts.
However, they are still given the authority to complete common sysadmin tasks,
such as user and group maintenance, filesystem mounting, system service
configuration, and system reboots and shutdowns. The root account has more
privileges than are necessary for most tasks.
Post-Deployment Steps
Most installation programs prompt you to update software, set the firewall, and
complete other tasks. Not all of them do, however, and there may be additional
settings required for your environment, too.
System and application updates provide the most current security fixes, application
features, and drivers to help ensure security and stability. It’s critical to update the
system upon deployment and maintain updates throughout its life cycle.
Recall that the security concept of hardening specifies that the system should be kept up
to date.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The deployment may be automated and cloud-init scripts may execute to complete
some or all of the installation steps.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Review Activity:
Linux Deployment
5
1. What are some reasons for updating the system immediately after
installation?
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Lesson 16
Summary
4
The early phase of the boot process is managed by the GRUB2 boot loader, which
acquires its configuration from the grub.cfg file. This file is constructed by the
grub2-mkconfig command from several supporting files. Sysadmins edit these
files rather than the main grub.cfg file.
The Linux installation process is usually menu-driven with options that include
selecting source files, defining partitions, choosing software based on the server’s
role in the organization, and completing post-installation configurations. It’s worth
noting that a password for root is set and most modern Linux distributions also
create a non-root administrator account.
Guidelines
These best practices and guidelines are provided as revision tools or as quick
references in your job role.
Deploying a standalone Linux system is straightforward, and the installation is
typically easy. If you use a physical computer, confirm device driver compatibility
before beginning.
• Select an installation platform (either a physical or a virtual computer).
• Select a distribution that supports the role the system will play in your
organization.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
2.0 Security
2.1 Summarize the purpose and use of security best
practices in a Linux environment. Covered in
Managing public key infrastructure (PKI) certificates Lesson 12, Topic B
Public key
Private key
Self-signed certificate
Digital signature
Wildcard certificate
Hashing
Certificate authorities
Certificate use cases Lesson 12, Topic B
Secure Sockets Layer (SSL)/Transport Layer
Security (TLS)
Certificate authentication
Encryption
Authentication Lesson 12, Topic C
Tokens
Multifactor authentication (MFA)
Pluggable authentication modules (PAM)
System Security Services Daemon (SSSD)
Lightweight Directory Access Protocol (LDAP)
Single sign-on (SSO)
Linux hardening Lesson 12, Topic A
Security scanning Lesson 8, Topic D
Secure boot
UEFI
System logging configurations
Setting default mask
Disabling/removing insecure services
Enforcing password strength
Removing unused packages
Tuning kernel parameters
Securing service accounts
Configuring the host firewall
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
4.0 Troubleshooting
4.1 Given a scenario, analyze and troubleshoot
storage issues. Covered in
High latency Lesson 7, Topic D
Input/output (I/O) wait
Low throughput Lesson 7, Topic D
Input/output operations per second (IOPS) scenarios Lesson 7, Topic D
Low IOPS
Capacity issues Lesson 7, Topic D
Low disk space
Inode exhaustion
Filesystem issues Lesson 7, Topic D
Corruption
Mismatch
I/O scheduler Lesson 7, Topic D
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
IaC Commands
Command Syntax Purpose Covered in
git git [options] Manage Git repositories. Lesson 14, Topic C
{subcommand}
docker pull docker pull Pull an image from Lesson 15, Topic B
{image-name} a registry.
docker docker Manage Lesson 15, Topic B
container container attributes
subcommand for specified
{options} containers.
{arguments}
push Exact syntax Upload images to Lesson 15, Topic B
depends on the a registry.
specific container
engine.
pull Exact syntax Download images Lesson 15, Topic B
depends on the from a registry.
specific container
engine.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
CLI may be faster to work with and consume fewer resources. GUI is usually easier to work with and
supports graphics-based applications.
Distributions tend to focus on addressing particular needs, such as an end-user workstation, multimedia
editing, and high-performance service hosting.
3. Why do servers tend to rely on CLI administration and desktops rely on GUI environments?
Servers attempt to dedicate all possible resources to the provided services and do not usually run end-user
applications that often require a GUI. Desktop systems often run user applications that benefit from or
require a graphical component.
4. How might anyone contribute improvements to a piece of free and open-source software?
Anyone might notice a need or requirement in software, create a solution to the problem, and then release
the modified software. As the cycle is repeated, the software continues to improve.
Most Linux configurations are stored in text files, so changing the configuration requires editing the text files.
Configuration files.
The su command switches to a different user account (usually root). The user can exercise all privileges
associated with that account. The sudo command allows a user to run only specific, delegated commands
that normally require administrative privileges.
2
Review Activity: Help in Linux
1. Name three things a man page might provide a user.
Man pages provide a summary of the command’s function, examples of using the command, explanation of
options.
2. Why might vendor websites be the best source of information about an application or service?
The vendor site probably contains the most current information to configure the application or service,
provides the version history, and supplies examples of use.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
3
Review Activity: Troubleshoot in Linux
1. A user contacts you to find out why they cannot access a directory. Using the troubleshooting
methodology, how would you narrow the scope of the problem?
Checking with another user in the same group who has the same level of access to the directory will allow
you to determine whether the problem is widespread.
Escalate a problem when you cannot solve it yourself (although it won’t be good for your career if you give
up too easily). You might also escalate if you do not have authorization to perform the necessary changes or
if the system is under some sort of warranty.
3. True or False? Documentation should be created only at the end of the troubleshooting process.
False. The last step of the methodology is to ensure that findings, actions, and outcomes are documented,
but you cannot do this effectively without existing notes. Most troubleshooting takes place within a ticket
system. Ideally, a documented job ticket would be opened at the start of recording the incident.
4
Review Activity: User Account Management
1. Why are user passwords stored in the /etc/shadow file and not the /etc/passwd file?
The /etc/passwd file can be read by all processes and therefore isn’t as secure. The /etc/shadow file
can only be read by root.
Any files stored in this directory are automatically copied to the home directory of new user accounts. Profile
files and other configurations can be easily set using /etc/skel.
The user may be more comfortable with a different shell than Bash, such as the Zsh or Ksh.
5
Review Activity: Group Account Management
1. Suggest at least two ways to display group membership information.
3. What is the result if an administrator forgets to add the -a option when adding a user to a
group?
The user is added to the specified group but removed from all other groups.
Membership in multiple groups provides access to different resources. For example, a user who is a member
of both the sales group and the marketing group can be granted access to both types of resources.
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
6
Review Activity: Privilege Escalation
1. A developer at your organization needs the ability to reboot a test server, but their account’s
standard privileges do not permit this. The developer requests the system’s root user password
in order to use su to reboot the server. Is there a more secure option that aligns with the
principle of least privilege?
A better option is sudo, which allows the administrator to delegate only the necessary task (in this case,
rebooting the server). The root password combined with su would grant more than just the reboot privilege.
The su root command switches the user identity to that of root within the user profile settings of the original
user. The su - root command switches the user identity to that of root with the root user’s own profile
settings.
3. You must delegate the shutdown -h privilege to SOMEUSER. What tool is used to modify the /etc/
sudoers file, and what line must be added to that file?
The visudo command is run to edit the file. The following line is added to the file: SOMEUSER ALL=(ALL)
NOPASSWD: SHUTDOWN_CMDS
4. Whose password must be entered with sudo? Whose password must be entered with su?
The user’s own password must be entered with sudo. The destination user’s password must be entered
with su.
7
Review Activity: User and Group Troubleshooting
1. List at least three scenarios where you might need records of who logged in to a Linux system.
2. Another administrator asks you to explain the value of editing the /etc/sudoer’s file with visudo
rather than a traditional text editor. What is your response?
The visudo editor confirms the syntax of the /etc/sudoers file. The file is very sensitive, and misconfiguration
could prevent administrative access to the system.
An administrator locked the account while the user was on a leave of absence, an incorrect password was
entered too many times, and password settings are misconfigured.
4. During a security audit it is discovered that a user does not have a password set. When you
check the /etc/passwd file, the password field is properly populated with the x character. What
file would actually display whether a password has been set for the user?
/etc/shadow
5. A user places sudo before a command, but the command still fails to run. What might be the
cause?
The /etc/sudoers file is not configured for the user or for the command.
6. An administrator asks you how to delegate Linux administrative privileges to a specific user.
What group is used for such delegation?
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
8
Review Activity: Standard Linux Permissions
1. How does the principle of least privilege help mitigate threats and mistakes?
It mitigates threats and mistakes by providing users with only the level of access required and no more. By
not having more access than needed, mistakes such as accidental or malicious changes or deletions may be
avoided.
2. What octal value is used in absolute mode to set permissions at all access for all identities?
777
3. Write the command by using symbolic mode that removes the read permission from others for
fileA without impacting other permissions.
Sets the dirA directory owner to USERA and the associated group to sales. The -R option causes the owner
and group change to apply to all existing files and directories in dirA.
9
Review Activity: Special Linux Permissions
1. How would SGID benefit users when set on the /projects directory where multiple users are
members of the associated group and need access to each other’s files in the directory?
SGID assigned the group association to files created in the /projects directory, allowing group members to
have access to each other’s files.
A sysadmin might do this to keep the configuration file from being accidentally deleted by another user or by
the system (for example, during an upgrade).
10
Review Activity: ACL Configuration
1. Explain the benefit offered by ACLs compared to standard Linux permissions.
ACLs provide additional flexibility by permitting multiple users and/or multiple groups to have different
levels of access.
2. What commands are used to set ACL entries for USERA with rwx and USERB with r-- for fileA?
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
1
Review Activity: The Linux File System
1. You are installing a new application on your Linux system. The documentation states that
configuration files and log files will be added to your system. Where will these files likely be
stored, and how does the FHS make such installations easier?
Configuration files will likely be stored in the /etc directory, and log files will likely be stored in /var/log. The
FHS makes it easier for developers to automate installations since directories such as /etc and /var/log are
consistent across distributions. The FHS also makes it easier for administrators to understand where such
files are likely to be stored.
2. You are in the new-projects directory, which is stored in the projects directory within your home
directory. What is the absolute path to the new-projects directory?
/home/USERNAME/projects/new-projects
3. A user submits a ticket regarding a file access issue. The first file, projectA.txt, had a second
hard link named my-project.txt. The same data was available via either link. The user deleted
the my-project.txt file, and the data was still available via projectA.txt. The second file, projectB.
txt, had a sym link that pointed to the projectB.txt link. When the projectB.txt link was deleted,
the data was no longer available via the sym link. The user wants to know why the first file is
still available after a link deletion but the second is not.
The first file still exists, and one hard link pointing to its content remains after the other hard link was
deleted. Hard links point to the actual data stored on the drive. Data always has at least one hard link. When
the only hard link to the second file was deleted, the sym link was broken because sym links do not point to
data, they point to hard links (that then point to data).
12
Review Activity: File Management Commands
1. You have been assigned a helpdesk ticket to answer a user question. The user is attempting to
rename files but cannot find the rename command. What command do you teach the user?
2. A user asks how to delete a directory named /projects containing 100 directories. The user
does not want to delete the files individually and does not want to be prompted to confirm the
deletion of each file. What is the appropriate command expression, and why?
rm -fR /projects
Most Linux distributions ask for confirmation when removing files. This is tedious when many files are
involved, though it’s an important safety check. The -f option forces the removal without confirmation.
3. A user complains that they redirected the output from several commands into a text file, but
the only content that appears in the file is the output from the most recent command. How
would you explain to the user what happened and how to correct the problem?
The > redirector overwrites any existing content in the target file. In the future, the user should use the >>
redirector to append new content to existing content in the target file.
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
13
Review Activity: File Location
1. You are conducting a security audit and need to document user access to log files—specifically
whether any files are world-readable or whether any allow rwx access to all users. How can the
find command be used in such a project, and what specific command might you use?
find /var/log -perm 400 (for world-readable access) and find /var/log -perm 777 (for
rwx to all users)
3. A senior sysadmin suggests that commands such as sed, awk, and sort are just as useful
in automation as at the command-line. How might commands such as these be used in
automation?
File management commands such as sed, awk, sort, cut, paste, tr, wc, printf, echo, and
diff can be integrated into automation scripts to find, organize, and display information or provide
configurations.
14
Review Activity: Text Files
1. A user contacts you and wants an easier text editor to use than Vim. There is no GUI installed on
the system in question. What text editor do you suggest and why?
Suggest the Nano editor. It is less confusing because it does not use modes and the common commands are
displayed in the interface.
2. Explain how the keyboard responds depending on which mode Vim is currently in. How do
modes add to Vim’s functionality?
The keyboard issues commands to Vim in some modes (Command and Execute) and manages content in
Insert mode. By allowing Vim to respond differently to keystrokes, many actions and features are possible
within the editor.
3. Why are text editors more important on Linux systems than on other systems?
System settings and service configurations are stored in text files. For a sysadmin to change the server’s
configuration, these files must be edited. Many Linux servers do not have a GUI and therefore do not have
mouse-driven, menu-based interfaces. CLI text editors are the tools sysadmins use to reconfigure systems.
15
Review Activity: Text File Management
1. Why is it a good practice to back up a configuration file before making changes?
The original file can be put back in place if the updated file causes issues.
2. Why should the integrity of a file downloaded from the Internet be checked by tools such as SHA
or MD5?
Files may be corrupted or changed during the download process. Checking file integrity with hashing tools
identifies whether any changes have occurred.
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
16
Review Activity: Software Management
1. What are the software-management phases?
They should do this to ensure the availability of proper software versions, authorized software, and
legitimate software.
3. Why is compiling software more common with Linux systems than with other operating
systems?
The open-source nature of Linux software means there is access to the source code for customization and
understanding of the software.
Version and software control, access to approved software, maintain network efficiency by only downloading
software once to the network and then distributing it
These files maintain existing configuration file settings rather than overwriting them with vendor defaults.
Use the apt update command, and then use the apt upgrade command.
2. Explain the difference between the two steps in upgrading software with apt.
The apt update command updates the database of available packages, and the apt upgrade command
upgrades the actual packages.
19
Review Activity: Source Code
1. What is the effect of using ./ before an executable file?
The ./ causes Bash to check the current directory for the executable instead of the normal command path.
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
2. Why is it more common to compile software with Linux than with other operating systems?
The source code is readily available in open-source environments and can be modified before compiling. In
proprietary environments, the source code is not available and software is almost always precompiled.
20
Review Activity: Software Acquisition
1. How can wget or curl be used to download files from the Internet in a way that a web browser
can not be used?
They can be used in an automated file download script and a browser cannot.
The application source code and supporting files may be bundled into a tar archive and compressed for a
more efficient download.
21
Review Activity: Software in Sandbox
1. What is the advantage of sandboxing?
Isolating a piece of software from any other software, the operating system, and system resources decreases
its ability to damage the system.
2. True or False? The original practice, known as chroot, that predates the current method of
sandboxing, is deprecated and no longer used.
2
Review Activity: Storage Concepts
1. Explain the key differences between MBR and GPT partition tables.
MBR is limited to four partitions and a maximum drive size of 2 TB, while GPT does not have such limitations.
Quotas help by better controlling how much data users are allowed to store on the system.
23
Review Activity: Storage Deployment
1. What does /dev/sdc3 specify?
It specifies the third partition (3) on the third storage disk (c).
2. What role does the partprobe command play in the process of adding storage?
The partprobe command checks for changes to the partition table, updating the system with any new or
removed partitions.
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
mkfs.xfs /dev/sdb2
A mount point is a directory where storage capacity is attached to the filesystem and made accessible to
users.
The three layers are physical volumes, volume groups, and logical volumes.
24
Review Activity: Storage Options
1. Why is RAID 5 fault tolerant and RAID 0 not?
RAID 5 maintains parity information about stored data that can be used to recreate data missing from any
one failed disk. RAID 0 does not store parity information.
2. You purchase two 100 GB storage disks to use in a RAID 1 mirror. Assuming the entire storage
capacity of both disks is at your disposal, what is the maximum amount of data your RAID 1
array can store?
100 GB
25
Review Activity: Storage Troubleshooting
1. What command reports real-time disk latency information?
ioping
2. List the commands necessary to show configuration information for each of the three layers
of LVM.
3. When trying to save a file to a storage disk, you receive a message stating the drive is out of
space. The df command indicates there is plenty of free space. What might be the issue?
inode exhaustion
4. You have added a partition to an existing disk by using fdisk. The partition is not displayed by
the cat /proc/partitions command. What other command do you need to run?
partprobe
26
Review Activity: Processes
1. Differentiate between stopped processes and zombie processes.
Stopped processes are terminating and releasing their resources. Zombie processes are child processes
awaiting parent-process acceptance of their termination.
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
The kill signal -15 asks a process to gracefully exit. The kill signal -9 terminates the process ungracefully.
3. What keys are used to cause top to display resources by memory consumption or by CPU
consumption?
The nice command is used to launch new processes at a specified priority, and the renice command is used
to re-prioritize running processes.
27
Review Activity: Memory
1. Explain the concept of virtual memory.
Because both RAM and storage drives are storage locations, if the RAM fills additional storage, space can be
borrowed from storage devices and information can be swapped between the two.
A swap partition is a dedicated partition on a storage device that is used as virtual memory space.
The free command displays physical memory use. The vmstat command displays virtual memory use.
28
Review Activity: The Linux Kernel
1. What is a kernel module?
A kernel module is a prewritten piece of code that adds functionality beyond what’s built into the kernel.
The output contains kernel messages covering drivers, modules, parameters, and other functions, including
status and error information.
/var/log/dmesg
29
Review Activity: System Services
1. When using the systemctl command, how does enabling a service differ from starting a service?
Answers will vary. Enabling a service causes it to start when the system starts. Starting the service launches
the service for the current runtime.
3. What are the target names for the GUI and CLI startup options?
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
30
Review Activity: System Service Configuration
1. A sysadmin has several virtual machines that are frequently on and off the development
network. The administrator complains of time synchronization problems with applications on
the VMs. What time service can you suggest to help?
chrony
Forwarding log files makes it easier to archive logs and easier to search or parse logs.
The at command is most useful for one-time commands, and cron is most useful for commands that are
repeated.
4. When would a script run if it were configured in cron with the following settings? 30 1 * * *
31
Review Activity: Localization Settings
1. Where are regional time-zone files stored on Red Hat–derived systems? And Debian-derived
systems?
2. True or false? The localectl command configures the system locale and keyboard settings as one
collective setting that is aligned with the locale’s specific cultural elements.
False. The keyboard layout can be configured separately and independently of the locale, allowing the wide
variety of keyboard layouts to be used with different locale settings.
32
Review Activity: Network Fundamentals
1. Differentiate between MAC addresses, IP addresses, and hostnames.
MAC addresses are physical addresses encoded on NICs, IP addresses are logical addresses configured by
administrators or DHCP, and hostnames are logical human-friendly names assigned by administrators.
2. Explain the difference between the Network ID and the Host ID portions of an IP address.
The Network ID is assigned to a network segment, and all nodes on the segment have the same Network ID,
making them local to each other. The Host ID is unique to each node within the Network ID to differentiate
hosts from each other.
IPv6 has more addresses, native encryption, and more efficient routing.
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
3
Review Activity: Network Settings
1. Why would an administrator need to use the ip link set eth0 up command?
2. Describe the dynamic and static IP address assignment processes, and list the types of devices
that likely rely on each process.
The dynamic process relies on a DHCP server with a range of available addresses. Clients lease addresses
automatically, requiring no user intervention. Common devices are workstations, laptops, phones, and
tablets. The static process relies on an administrator manually configuring the IP address settings, and
common devices are servers, routers, switches, and other network devices.
The /etc/resolv.conf file lists available nameservers, and the /etc/nsswitch.conf file defines the order for
name resolution between the local /etc/hosts file and the nameservers listed in /etc/resolv.conf.
34
Review Activity: Remote Administrative Access
1. A developer wants to integrate an SSH connection to a remote server into a script. The
developer needs to avoid a password challenge for the SSH connection. What solution can you
recommend?
These commands allow for a command-line-based download from a web server and can therefore be scripted.
3. What advantage does the rsync utility have over SCP and SFTP?
What disadvantage does it have?
35
Review Activity: Network Troubleshooting
1. A helpdesk technician approaches you for help with a network troubleshooting challenge.
The tech states that the workstation shows two IP addresses, neither of which matches the
expected configuration. The first IP address is 127.0.0.1 and the second is 169.2540.99.42. What
can you explain about each address?
The 127.0.0.1 address is the loopback address, assigned to each host to reference itself. The 169.254.99.42
address is from Automatic Private IP Addressing (APIPA) and indicates the client attempted to lease an IP
configuration from a DHCP server but failed to do so.
2. A helpdesk technician approaches you for help with a network troubleshooting challenge. The
tech states that a workstation can ping a remote server by IP address but cannot ping it by
name. What type of problem is this?
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
36
Review Activity: Firewall Configuration
1. How does a firewall help mitigate threats between two network segments?
The firewall only permits allowed traffic to move between the segments, blocking unallowed traffic. For
example, FTP file transfers might be blocked between the segments, or any connections at all might be
blocked.
2. What commands are necessary to persistently permit custom TCP port 9876 through the local
firewalld configuration on the public zone?
and
firewall-cmd --reload
37
Review Activity: Network Traffic
1. An administrator wants to better understand the structure of TCP/IP packets, including
addressing, transport layer protocols, and the data payload. How would the Wireshark utility
help with this understanding?
Wireshark shows the packet headers, including source and destination MAC addresses, source and
destination IP addresses, transport layer protocols and any synchronization information used, and the
payload (actual data being sent). If the payload is not encrypted, it is readable by humans.
2. A developer is working on a custom application that sends data to three different remote
servers. The developer wants to see, at the network level, what data is sent to each server.
What tools can you suggest to help with this, and what selection criteria might you suggest for
those tools?
Select either the tcpdump or Wireshark protocol analyzers. Wireshark has an easy-to-use GUI that can filter
results, while tcpdump is easily scriptable.
3. A junior administrator needs to generate a report displaying the operating systems running on
all nodes on the 192.168.1.0/24 network segment. What command might you suggest?
38
Review Activity: System Hardening
1. Explain the principle of least privilege, and provide at least two examples of its use.
The principle of least privilege states that users and services should be given as little access to resources as
possible. Examples include limiting the resources that services can access and setting file permissions for users.
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
4. Differentiate between symmetric and asymmetric encryption, and explain the rule associated
with asymmetric encryption.
Symmetric encryption uses one key to both encrypt and decrypt. Asymmetric encryption uses two keys
(public and private). The rule is if data is encrypted with one key, only the other key can decrypt it.
39
Review Activity: Certificates
1. What are some of the contents of a digital certificate?
Self-signed certificates are created by your organization to show trust within the organization and are not
trusted by outside entities. Third-party certificates are created by Certificate Authorities that are trusted by
your organization and outside entities.
This might be useful when performing file downloads from the Internet, file transfers on the local network,
and backups.
40
Review Activity: Authentication
1. What is the purpose of sssd?
2. What is the relationship between PAM modules and PAM control flags?
Modules specify an action such as an authentication attempt, and control flags manage how that action is
enforced (such as whether it is required or optional).
41
Review Activity: SELinux and AppArmor
1. What command displays the SELinux context for files?
ls -Z
2. You’re troubleshooting a file-access issue and wish to see whether SELinux is to blame. What is
one way you could test this by using the Permissive and Enforcing modes?
Assuming the system is properly configured with Enforcing mode, set the system to Permissive mode with
the setenforce 0 command and attempt the access again. If access is successful in Permissive mode but
unsuccessful in Enforcing mode, SELinux is likely the culprit. Be sure to use setenforce 1 to return the system
to Enforcing mode.
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Targeted enforces SELinux settings only on specific resources, leaving all other resources unconfined. Strict
enforces SELinux settings on all resources unless the administrator deliberately excludes specific resources.
42
Review Activity: Script Basics
1. What is the purpose of sh-bang, and how would you configure the value for Bash?
sh-bang lets Linux know what shell the script is written for and should execute in. Many shells have their
own syntax. The sh-bang value for Bash is #!/bin/bash
2. How does Bash handle lines that begin with the # character?
Bash ignores them, allowing script authors to insert comments, instructions, and examples.
43
Review Activity: Script Elements
1. How might you combine the echo and read commands in a script to guide users through a
process?
Combining the two allows the script and the user to communicate. The echo command displays instructions
and questions from the script while the read command accepts user input in response to the questions.
2. You’ve created a script that includes the string dev=web server. The script throws an error
indicating too many arguments for the dev variable. How could you set the dev variable to see
the words web and server as a single value?
3. You need to use the sed command to find a value ’server’ and replace it with the value ’system’
in a file named inventory.txt. What is the syntax to accomplish this?
4
Review Activity: Logical Controls
1. You are exploring your local (shell) variables on each system that you manage. The first variable
you check is the SHELL variable. How can you check the SHELL variable, and what do you expect
it to display?
The SHELL variable can be checked with echo $SHELL and /bin/bash can be expected as the output.
for loops execute a given number of times, no more and no less. while loops execute as long as a given
condition is met, whether that’s zero, one, or more times.
File globbing, such as defining a list of files as *.sh, is a shorthand method of defining a list of files with a
common name attribute.
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
45
Review Activity: Infrastructure as Code
1. How would an organization’s change to DevOps management impact Linux administrators?
Linux administrators would work more closely with developers, use a CI/CD pipeline to manage servers, and
integrate more automation and orchestration.
IaC provides standardized security configurations that are easy to change to adapt to new threats.
Declarative defines both the configuration and the tools needed to set the configuration. Iterative defines
the specific commands to achieve the desired configuration.
46
Review Activity: Orchestration
1. How does orchestration provide scalability?
Orchestration allows administrators or automated systems to quickly provision new resources in response
to spikes in demand.
Automation refers to an individual task accomplished without human intervention. Orchestration refers to a
series of automation tasks that completes an entire deployment.
Requirements such as cross-platform support, familiarity with particular languages, support for containers,
and agent or agentless options might influence and organization’s selection.
47
Review Activity: Git
1. If an IT department stored all scripts written by sysadmin in a Git repository, what benefits
might the department realize?
They might be located on the user’s local workstation, on a local/internal network, in the cloud, or in a public
repository such as GitHub.
Such a request might be submitted when contributing code to a project managed by project maintainers
who must approve your changes.
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
48
Review Activity: Containers
1. What are three advantages of containers?
Containers are scalable, offer high availability, and can be quickly deployed.
An image is a static specification for a container. When the image is run, the executing code is a container.
The data processed inside a container and the changes to the container’s configuration are not stored. (Note
that data may be persistently stored outside the container.)
49
Review Activity: Container Deployment
1. Differentiate between running a container with the docker run {image-name} command versus
with the docker run -it {image-name} bash command option.
Running the docker run {image-name} command causes the container to start up and run without
establishing an administrative interface. Running a container with the docker run -it {image-name} bash
command causes the container to start up and run but then launches the Bash shell within the container
and establishes an administrative connection to the shell.
Authorized users have full control of the images stored there, including versions, image access, and change
management.
By acting as a central storage area for container images, the registry provides a place from which CI/CD
processes can pull images as needed for rapid and automated deployments for scaling.
50
Review Activity: Virtualization
1. Differentiate between virtualization layers for VM virtualization versus container virtualization.
VM virtualization virtualizes at the hardware layer, while container virtualization virtualizes at the OS layer.
2. How might you automate a virtual machine deployment, and what command is used?
You might automate a VM deployment by including the virt-install command in a script that provides
specifications such as processor, memory, storage, and network settings.
The virtual bridge manages network connectivity between the VM and the host server and/or the network.
The bridge may allow no network access to any other system, allow network access that is limited to other
VMs on the host and the host itself, or allow full network access.
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
51
Review Activity: Linux Boot Process
1. Differentiate between the older system BIOS and the modern UEFI standards.
BIOS tests hardware, manages hardware settings, and runs the boot loader. UEFI does the same but handles
larger memory spaces, larger storage disks, and includes security enhancements.
The initrd loads with the kernel and contains everything needed to boot the system. It is loaded during the
initial startup phase to allow for flexible configurations.
52
Review Activity: Boot Settings
1. Why don’t you usually need to install GRUB2 on most Linux systems?
2. How is working with the grub.cfg file different from working with most Linux configuration
files?
Most Linux configuration files are edited directly, but grub.cfg is assembled from a group of configuration
files. Those files are edited directly.
The grub2-mkconfig command constructs the grub.cfg file from various configuration files.
53
Review Activity: Linux Deployment
1. What are some reasons for updating the system immediately after installation?
Updates provide security enhancements, stability components (such as device drivers), and application
features. Updating is part of security hardening.
2. Why is a non-root administrative account often created as part of the installation process?
Logging in as root is usually a poor security choice, but administrative tasks still need to be completed.
Therefore, a non-root administrative account is less privileged than root, but it can complete most necessary
administrative tasks.
3. Why is it a good idea to deploy a Red Hat–derived and a Debian-derived distribution at least
once?
It’s useful to compare features such as package managers and GUI tools between the two Linux families.
Solutions
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Compression Reducing the amount of and platform updates, which are rapidly
space that a file takes up on disk using committed to production, with code
various algorithms to describe it more updates, which are rapidly committed to
efficiently. File storage compression a code repository or build server.
uses lossless techniques. NTFS-
control statement A programming
formatted drives can compress files
element that enables a program to
automatically while ZIP compression
execute instructions in a specified order.
adds files to a compressed archive.
Lossy compression, such as that used cron job Scheduled task that is
by JPEG and MPEG image and video managed by the Linux cron daemon.
formats, discards some information
CUPS A print management system
in the file more or less aggressively,
for Linux that enables a computer to
allowing for a trade-off between picture
function as a print server.
quality and file size.
current working directory (CWD)
conditional statement A control
The directory that the user is currently
statement used in programming to
accessing.
evaluate whether a particular condition
is true or false. cybersecurity Protection of computer
systems and digital information
confidentiality The fundamental
resources from unauthorized access,
security goal of keeping information and
attack, theft, or data damage.
communications private and protecting
them from unauthorized access. daemon A program that runs in the
background without the need for
confidentiality, integrity, and
human intervention.
availability (CIA triad) Three principles
of security control and management. Dandified YUM (DNF) An improved
Also known as the information security version of the YUM package manager.
triad. Also referred to in reverse order desktop environment A client to a
as the AIC triad. display server that tells the server how
container An operating system to draw graphical elements on the
virtualization deployment containing screen.
everything required to run a service, DevOps A combination of software
application, or microservice. development and systems operations,
container engine A piece of software this term refers to the practice of
that processes user requests and runs integrating one discipline with the other.
one or more containers on top of a DevSecOps A combination of software
single operating system. development, security operations, and
container image A static file with systems operations, this term refers
executable code that can create a to the practice of integrating each
container on a computing system. As discipline with the others.
a static file, it cannot be changed, and digital certificate Identification and
it can be deployed consistently in any authentication information presented
environment. It is a core component of a in the X.509 format and issued by a
containerized architecture. certificate authority (CA) as a guarantee
context-based permissions A that a key pair (as identified by the
permissions scheme that describes public key embedded in the certificate)
multiple types of information about is valid for a particular subject (user or
processes and files that are used in host). Also known as a certificate.
combination to make decisions related digital signature Message digest
to access control. encrypted using the sender’s private
Continuous Integration/Continuous key that is appended to a message to
Deployment (CI/CD) Software authenticate the sender and prove
development method combining app message integrity.
Glossary
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
distro One of several fully functional ext4 One of the default file systems in
operating systems and members of modern Linux versions that supports
the Linux family that run the Linux journaling and large volumes.
kernel, GNU software, and additional
Fibre Channel (FC) High-speed network
components. Also known as a Linux
communications protocol used to
distribution.
implement SANs.
domain name system (DNS) Service
file storage A storage method where
that maps fully qualified domain name
data is managed as a discrete file within
labels to IP addresses on most TCP/IP
an operating system’s file system.
networks, including the Internet.
Common on workstations, servers, and
dpkg A package management system NAS devices.
used by Linux distributions derived from
file system Structure for file data
Debian Linux.
indexing and storage created by a
Dynamic Host Configuration Protocol process of formatting a partition that
(DHCP) Protocol used to automatically allows an OS to make use of a mass
assign IP addressing information to storage device, such as an HDD, SSD, or
hosts that have not been configured thumb drive.
manually.
File Transfer Protocol (FTP) Application
encryption Scrambling the characters protocol used to transfer files between
used in a message so that the message network hosts. Variants include S(ecure)
can be seen but not understood or FTP, FTP with SSL (FTPS and FTPES) and
modified unless it can be deciphered. T(rivial)FTP. FTP utilizes ports 20 and 21.
Encryption provides for a secure means
Filesystem Hierarchy Standard (FHS)
of transmitting data and authenticating
A set of guidelines for the names of files
users. It is also used to store data
and directories and their locations on
securely. Encryption uses different types
Linux systems.
of cipher and one or more keys. The size
of the key is one factor in determining Filesystem in Userspace (FUSE)
the strength of the encryption product. Permits the creation of non-privileged
Also known as cipher and algorithm. virtual file systems without privileged
access to the kernel by providing an
environment variable A type of
interface between the two.
variable whose values are inherited
from parent processes and passed on to firewall Software or hardware device
child processes. that protects a network segment or
individual host by filtering packets to an
escape character A character that is
access control list.
used to remove the special meaning
from another character so it can be free and open-source software (FOSS)
interpreted literally. Computer code that embodies the
principles of both the free software
execute mode A text editing mode that
movement and the open-source
enables users to execute commands
software (OSS) movement.
within the editor.
full disk encryption (FDE) Encryption of
exit code A value that a child process
all data on a disk (including system files,
passes back to its parent process when
temporary files, and the pagefile) can be
the child process terminates. Also
accomplished via a supported OS, via
known as exit status.
third-party software, or at the controller
ext2 A non-journaled Linux file system level by the disk device itself.
introduced in 1993 and now the file
fully qualified domain name (FQDN)
system on some flash storage media.
Unique label specified in a DNS
ext3 Standard Linux file system that hierarchy to identify a particular host
includes journaling and has since been within a subdomain within a top-level
replaced with ext4. domain.
Glossary
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
gedit The default GUI text editor used in hashing Function that converts an
GNOME desktop environments. arbitrary-length string input to a fixed-
length string output. A cryptographic
Git Type of version tracking software
hash function does this in a way that
used primarily with collaborative
reduces the chance of collisions, where
development projects to ensure integrity
two different inputs produce the same
and version control.
output. Also known as message digest
globbing A method of shell expansion and cryptographic hash.
used to replace a specific wildcard
home directory A container for a user’s
pattern with values that match the
personal files and other files specific to
pattern.
that user.
GNOME The default desktop
hop One link in the path from a host to
environment for most Linux
a router or from router to router. Each
distributions that run the X Window
time a packet passes through a router,
System or Wayland.
its hop count (or TTL) is decreased by
GNU GRand Unified Bootloader (GNU one.
GRUB) A boot loader developed by the
hostname A human-readable name
GNU Project that became popular on
that identifies a network host.
UNIX-like systems.
HyperText Transfer Protocol/
GNU nano A small, user-friendly text
HTTP Secure (HTTP) Application
editor that evolved from the Pico text
protocol used to provide web content
editor created for UNIX-like systems.
to browsers. HTTP uses port 80.
Also known as nano.
HTTPS(ecure) provides for encrypted
GNU Parted A utility that is used to transfers, using TLS and port 443. Also
manage partitions on a storage device. known as HTTP Secure.
graphical user interface (GUI) An hypervisor Software or firmware that
environment for passing commands to creates and manages virtual machines
a computer by using a graphical, mouse- on the host hardware.
driven interface rather than by using
I/O scheduling The process by which
text-based commands.
the operating system determines the
group An access control object that order of input and output operations as
contains multiple users with similar they pertain to block storage devices.
security requirements.
identity and access management
GUID partition table (GPT) Modern (IAM) Security process that provides
disk partitioning system allowing large identification, authentication, and
numbers of partitions and very large authorization mechanisms for users,
partition sizes. computers, and other entities to work
with organizational assets like networks,
hard link A reference to a file that
operating systems, and applications.
enables a file’s data to have multiple
Also known as identity management
names on the same file system.
(IdM) and access management.
hardening Process of making a
immutable flag An attribute of a file
host or app configuration secure by
or directory that prevents it from being
reducing its attack surface, running only
modified, even by the root user.
necessary services, installing monitoring
software to protect against malware index node (inode) An object that
and intrusions, and establishing a stores metadata about a file or directory
maintenance schedule to ensure the on a file system.
system is patched to be secure against
infrastructure as code (IaC)
software exploits.
Provisioning architecture in which
hash The theoretically indecipherable deployment of resources is performed
fixed-length output of the hashing by scripted automation and
process. Also known as hashed value. orchestration.
Glossary
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
init A daemon that initializes a system responsible for controlling the rest of
and acts as the parent to all processes. the operating system.
Also known as init daemon.
kernel module A system-level object
initrd image An archive file containing that extends the functionality of the
all the essential files that are required kernel.
for booting the operating system.
kernel panic A mechanism by which the
input/output operations per second system detects there has been a fatal
(IOPS) Performance indicator that error and responds to it.
measures the time taken to complete
kernel space The area of system
read/write operations.
memory in which the kernel executes
insert mode A text editing mode that the services it provides.
enables users to insert text by typing.
Kernel-based Virtual Machine
integrity The fundamental security goal (KVM) Hypervisor used to implement
of keeping organizational information virtualization in Linux.
accurate, free of errors, and without
latency Time taken for a signal to reach
unauthorized modifications.
the recipient, measured in milliseconds.
integrity checking The process Latency is a particular problem for
of verifying that data has not been two-way applications, such as VoIP
modified, whether intentionally or (telephone) and online conferencing.
unintentionally, in any way.
least privilege Basic principle of
Internet Protocol address (IP) security stating that something should
Format for logical host and network be allocated the minimum necessary
addressing. In IPv4, a 32-bit binary rights, privileges, or information to
address is expressed in dotted decimal perform its role. Also known as principle
notation, such as 192.168.1.1. In IPv6, of least privilege.
addresses are 128-bit expressed
Lightweight Directory Access Protocol
as hexadecimal (for example,
(LDAP) Protocol used to access network
2001:db8::0bcd:abcd:ef12:1234).
directory databases, which store
Internet Small Computer Systems information about authorized users
Interface (iSCSI) IP tunneling protocol and their privileges, as well as other
that enables the transfer of SCSI data organizational information.
over an IP-based network to create a SAN.
Lightweight Directory Access
ISO image A disk image for OS booting Protocol Secure (LDAPS) A method
and installation named after the ISO of implementing LDAP using SSL/TLS
9660 file system standard used by encryption. Also known as Secure LDAP.
compact disks (CDs).
Linux Open-source OS packaged in
JavaScript Object Notation (JSON) distributions supported by a wide range
A file format that uses attribute-value of hardware and software vendors.
pairs to define configurations in a
Linux kernel A free and open-source
structure that is easy for both humans
monolithic kernel that manages all
and machines to read and consume.
other resources on the Linux operating
KDE Plasma The second-most common system.
desktop environment for Linux
Linux Unified Key Setup (LUKS)
distributions that run the X Window
A platform-independent full drive/
System or Wayland.
disk encryption (FDE) solution that is
Kerberos Single sign-on authentication commonly used to encrypt storage
and authorization service that is based devices in a Linux environment.
on a time-sensitive, ticket-granting
load balancing The technique of
system.
distributing network traffic or computing
kernel All operating systems have a workload among multiple devices in a
kernel, which is a low-level piece of code network.
Glossary
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Glossary
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Glossary
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Glossary
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Glossary
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
application layer (less overhead from arranged in pairs that are twisted to
headers and lost packets). Also known reduce interference. Typically, cables are
as goodput and throughput tester. 4-pair or 2-pair.
token A physical or virtual item user account The credentials and
that contains authentication and/or profile settings that represent a subject
authorization data, commonly used in on a computing host or network system.
multifactor authentication.
user space The area of system memory
Transmission Control Protocol/ outside of kernel space that includes
Internet Protocol (TCP/IP) Network software that accesses kernel services.
protocol suite used to implement the
variable Identifier for a value that can
Internet and most WANs and LANs. It
change during program execution.
uses a four-layer network model that
Variables are usually declared with a
corresponds roughly to the OSI model
particular data type.
as follows: Network Interface (Physical/
Data Link), Internet (Network), Transport vim Command-line text editor that
(Transport), Application (Session, extends the original vi software.
Presentation, Application). Vim uses a command mode for file
operations and an insert mode for
Transport Layer Security (TLS)
editing. Also known as vi.
Security protocol that uses certificates
for authentication and encryption to virtual file system (VFS) An abstraction
protect web communications and other layer that translates file system
application protocols. information between a real file system
and the Linux kernel.
Trivial File Transfer Protocol (TFTP)
Simplified form of FTP supporting only virtual local area network (VLAN)
file copying. TFTP works over UDP Logical network segment comprising a
port 69. broadcast domain established using a
feature of managed switches to assign
troubleshooting methodology
each port a VLAN ID. Even though
Structured approach to problem-solving
hosts on two VLANs may be physically
using identification, theory of cause,
connected to the same switch, local
testing, planning, implementation,
traffic is isolated to each VLAN, so they
verification, and documentation steps.
must use a router to communicate.
udev A Linux device manager that
virtual machine (VM) Guest operating
automatically detects and configures
system installed on a host computer
hardware devices.
using virtualization software (a
uncomplicated firewall (UFW) A hypervisor).
simplified interface for configuring the
Virtual NICs (vNICs) Connections
iptables firewall service.
between a virtual machine instance and
Unified Extensible Firmware Interface a physical network interface card (NIC)
(UEFI) Type of system firmware in the host server.
providing support for 64-bit CPU
virtualization Computing environment
operation at boot, full GUI and mouse
where multiple independent
operation at boot, and better boot
operating systems can be installed to
security.
a single hardware platform and run
unit file A configuration file that simultaneously.
systemd uses to determine how it will
volume group (VG) Aggregated space of
handle system resources that systemd
one or more physical volumes in logical
can manage.
volume management (LVM).
unshielded twisted pair (UTP) Media
Wireshark Widely used protocol
type that uses copper conductors
analyzer.
Glossary
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
XFS One of the default file systems in Yellow Dog Update Manager (YUM)
modern Linux versions that supports Package manager for installing,
journaling and efficiency in handling maintaining, inventorying, and removing
large files. software from the Red Hat family of
Linux distributions.
YAML Ain’t Markup Language (YAML)
Language for configuration files and Zypper An openSUSE package manager
applications such as Netplan and that supports .rpm packages.
Ansible.
Glossary
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Dynamic Host Configuration ethtool command, 297, 297, file management commands,
Protocol (DHCP), 290 325 92–107. see also file
client, 298–299, 299 exec command, 390–391 management scenario
dhclient command, 299 ExecStart= directive, in .service command modifiers,
dhclient.conf config file, 299 unit files, 256 104–106
server, 290, 298 ExecStop= directive, in .service to display file contents with
dynamic IP addresses, 298–299 unit files, 256 head and tail commands,
configure, 298 Execute mode, in Vim, 14 100–101
DHCP server, 298 Execute Mode commands, in to display files, 99–101
Vim text editor, 122–123 display strings with grep
E exit codes, 393–394, 394 command, 101–102, 102
exit codes used with navigate directories, 92–95
e2label command, 190, 214
conditional statements, 408 redirectories, 102–104
echo command, 98, 108, 110,
exit command, 394 file management scenario,
390
export command, 403, 418 95–99
e-commerce certificate, 364
ext2, ext3, ext4 file systems, 89 closing the project, 98–99
Edit, in Vim, 14
ext4 filesystem, 185 copy and move project files,
Emacs text editor, 121
external storage, 174 97–98
enabling a service, 254
extract text files, with tar create directory structure,
encryption, 198, 358–361
command, 128–130, 130 96, 96
full disk, 359
create project files, 96
goals, 359–360
display project file contents,
hashing, 361, 361 F 98
private key, 360–361
FC (Fibre Channel), 202, 203 existing current directories,
public key, 360
fdisk command, 182, 182–183, 95
types, 360–361
183, 213 remove directories and
understanding, 358–359,
Fedora Linux, 4, 145, 154, 186, files, 98–99
359
280, 330, 468 starting the project, 95–96
enforcing mode, 377
Fibre Channel (FC), 202, 203 summarizing, 99
env command, 403–404, 404,
file command, 87, 87, 116 working the project, 97–98
418
file extensions, 388 file manipulation commands,
environment variables, 401,
file links 110–114
402
configure, 88–90 awk command, 113
troubleshoot, 405–406
hard links, 89 cut command, 112
escape characters, 392
inodes, 88–89 diff command, 113
/etc/apt.conf, 160
link types, 89 echo command, 110
/etc/bashrc, 34
symbolic links, 89–90, 90 paste command, 112
/etc/default/grub file, 464, 465
file locations, 108–115 printf command, 111
/etc directory, 86, 296
file manipulation sed command, 113–114
/etc/fstab file, 189
commands, 110–114 sort command, 112
/etc/inittab file, 260
search commands, 108–110 tr command, 111
/etc/nsswitch.conf file, 302, 302
file management, 83–118 wc command, 111
/etc/passwd file, 32, 32, 33, 35,
best practices and file manipulation commands in
41, 54, 55
guidelines, 116 scripting, 397–398
/etc/profile, 34
command reference table, file naming conventions, 87
/etc/resolv.conf file, 301
116–118 files. see also file management
/etc/shadow file, 32, 33, 33, 41,
commands, 92–107 scenario
55
file locations, 108–115 access control lists on,
/etc/skel directory, 34
Linux file system, configure, 77–79
/etc subdirectory, 85
84–91 commands to display,
/etc/sudoers file, 48, 49, 49–50,
summary, 116–118 99–101
52
file storage, 175
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
gVim text editor, 121 head command, 99, 100–101, index.html home page, 272,
gzip command, 132, 138 117 272
to unpack download, 163 header files (.h file extension), index node (inode), 88–89
162 infrastructure as code, 419–436
H help in Linux, 20–23 command reference table,
here documents, redirection 436
hard disk drive (HDD), 174
with, 399 orchestration, implement,
disk and partition
HISTFILESIZE, 404 424–428
references, 180–181, 181
history and philosophy of Unix summary, 436
hwinfo command, 179–180
and Linux, 2–3, 3 understand, 420–423
lsblk command, 180
/home directory, 86, 86 version control with Git,
lsscsi command, 180
/home subdirectory, 85 429–435
in storage deployment,
/home/username directory, 18 infrastructure as code, in Git
179–181
$HOME variable, 86, 86 use case, 430
hard disk partitioning, 175
host, 445 init command, 431
hardening servers, 356–357
host command, 321, 321, 326 init daemon, 252
hard links, 89
hostname, 287 initrd image, 457, 457
hardware information, 216–222
hostnamectl command, 300, inode exhaustion, 209–210
bus information, display,
325 Input/Output Operations per
217, 217
htop command, 226, 226 Second (IOPS), 206–207
CPU information, display,
HTTP. see Hypertext Transfer Insert mode, in Vim, 14, 15
219, 220
Protocol (HTTP) Insert Mode commands, in Vim
dmidecode command, 217
HTTPS (Hypertext Transfer text editor, 123
hardware information tools,
Protocol Secure), 290 insmod command, 241, 249
216–217
hwinfo command, 179–180, install
hwinfo command, 216–217
216–217, 217, 219, 248 in systemd unit files, 255
memory information,
Hypertext Transfer Protocol in .target unit files, 258
display, 220, 220–221,
(HTTP) install command, 243
221
in boot process, 455 installing Linux, 453–474
udev device manager,
configure firewall to permit best practices and
218–219
inbound, 271, 272 guidelines, 473
hardware problems, 466
network ports, 263, 290 boot process, 454–461
hardware RAID, 176, 200, 206,
Hypertext Transfer Protocol boot settings, modify,
211
Secure (HTTPS), 290 462–467
hardware resources, 215–250
hypervisors, 449 command reference table,
best practices and
474
guidelines, 248
command reference table, I deploy Linux, 468–472
summary, 473–474
248–250 id, in SysVinit system, 260
integrity, 358
hardware information, id command, 39, 58
integrity checking, 135, 365–367
216–222 identity and access
hash functions, 365–367
Linux kernel management, management (IAM), 369
SHA commands, 367
239–247 if conditional, 407
Internet layer, 286, 287
memory management, ifconfig command, 293–294,
Internet Protocol (IP) address,
234–238 325
288–290
process management, if...else conditional, 407–408
assign, 297–298
223–233 iftop command, 316, 316, 325
configuration, 290
summary, 248–250 image operations, container,
described, 287
hash, 135 442–444
DHCP client, 298–299, 299
hash functions, 365–367 customized image, 443,
DHCP server, 290, 298
hashing, 361, 361 443–444, 444
DNS, 290
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
GNU Parted utility, 183–184 ownership, 69–70, 70 principle of least privilege, 62,
HDD references, 180–181, principle of least privilege, 356
181 62 printf command, 111
manually test mount, special, 74–76 printing, configure, 274–275
186–187 standard, 62–73 CUPS, 274–275
move data to new storage, strings, interpreting, 64–66 lpr command, 275
188 summary, 81–82 print variables, 404
partprobe command, 184 symbolic mode, 68 private key encryption, 360–361
/proc/partitions directory, three-digit and four-digit privilege escalation, 47–53
184 modes, 67 described, 47
in storage deployment, view, 64, 64–66 disabled root account,
181–186 permission strings, 47–48
test the storage, 187, interpreting, 64–66 “get root” idiom for, 47
187–188, 188 permissive mode, 377 polkit (PolicyKit) toolkit,
types, 175–176 persistent setting, 252 51–52
XFS filesystem, 185–186 persistent storage, 445 with su, 48
partprobe command, 184 pgrep command, 223–224, 244 with sudo, 48–50
passwd command, 35–36, 36, physical deployment, 468–469 troubleshoot, 52
39, 40, 55, 58 Physical Volumes (PV), 192, processes running on the
password 192, 193, 194, 195, 211 system, 225–229
history, test passwords pidof command, 224, 244 CPU time, 226
against, 373 ping command, 338, 338–339, htop command, 226, 226
module, 372 352 lsof command, 227–228,
PAM for managing, 373 ping test, 314 228
set, 35–36, 36 pipe character ( | ), 101–102, ps command, 227, 227
paste command, 92, 112 102 sar command, 229
path tools, to test connectivity, piping, 105 systemd-analyze blame
338–341 pkaction command, 51 command, 228, 228
mtr command, 340–341, pkcheck command, 51 top command, 225, 225, 226
341 pkexec command, 47, 51, 51–52, uptime command, 229
ping command, 338, 338–339 59 process identifiers (PID), 223
tracepath command, pkexec program argument, 51 process management, 223–233
339–340 pkill command, 230 job control, 231–232
traceroute command, pkttyagent command, 51 manipulate processes,
339–340, 340 pluggable authentication 223–225
PATH variable, 404 models (PAM), 41 process, defined, 223
permissions, 61–82 Pluggable Authentication process ID, display, 223–224,
absolute mode, 67 Module (PAM), 371–373 224
access control lists, 77–80 configurations, 372, 372 process identifiers, 223
access identities, 63 described, 371–372 process signals, 224–225
access issues, troubleshoot, passwords managed with, process states, 229–231
72, 75 373 running processes and
access levels, 63 policy requirements, test open files (see processes
attributes, 70–72 passwords against, 373 running on the system)
best practices and polkit (PolicyKit) rules, 51–52 set priorities for CPU
guidelines, 81 configure, 51 processes, 231
command reference table, pkexec and other polkit /proc/partitions directory, 184
81–82 commands, 51, 51–52 /proc subdirectory, 85
default, 66 positional parameters, 414–415 project files, create, 96
in GUI desktop Preboot Execution ps command, 224, 225, 227,
environments, 68, 69 Environment (PXE), 455 227, 229, 229, 231, 249
operators, 68 pseudo-swap, 235
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
pstree command, 230, 230 YUM package manager, Git, 430, 432–433
public key encryption, 360 145, 147–149 location of, 141–142
public key infrastructure (PKI) redirection, 103, 398–399 reasons for sysadmins to
certificates, 364–365 with here documents, 399 control, 152–153
certificate authorities, standard redirectors, types of, 153
364–365 398–399 updating configuration files,
described, 364 redirection operators, 103–104 154–155
self-signed certificates, 365 redirectories, 102–104 YUM and DNF to configure,
wildcard certificates, 365 redirectors, standard, 398–399 153–154
pull command, 431, 445, 452 redundant arrays of RequiredBy= directives, in
Puppet, 426 independent disks (RAID), systemd unit files, 255
push command, 431, 445, 452 176–177, 198–199, 198–200 required flag, 372
pwd command, 6, 12, 12, 29 disk mirroring (RAID 1), 198, Requires= directive
199, 200 in .service unit files, 255
Q disk striping (RAID 0), 198, in systemd unit files, 255
198, 200 requisite flag, 372
querying package managers
disk striping with parity reserved ranges, 289
Debian, 159, 159
(RAID 5), 199, 199, 200 resize2fs command, 190–191,
installation database, 141,
display settings, 211 214
141
hardware RAID, 176, 200, resize storage, 195
RPM, 150–152
206, 211 resolvectl command, 319, 319,
quota report, 177
software RAID, 176–177, 325
200, 211 restarting a service, 263
R standards, 198–200 retrieve variables, 401–402
RAID. see redundant arrays of throughput and, 206 rm command, 98–99, 106, 117
independent disks (RAID) registries, container, 444–445 rmdir command, 98–99, 117
Random Access Memory regular expressions (regex), rmmod command, 241, 249
(RAM), 234, 235, 235 395 role context, 376
ransomware, 168 relative path, 88 root cause analysis, 26
Raspberry Pi hardware reloading a service, 263 root context, 375
platform, 468–469 remote administrative access, /root directory, 86
read, write, and execute (rwx), 305–312 /root subdirectory, 85
63 CLI remote-access tools, route command, 303, 314
read command, 390 308–310 router issues, 318
read-only memory (ROM), 456 configure key-based routers, 288
rebase command, 431, 432 authentication, 307–308 router saturation, 318
recover and access data, 210 configure SSH, 305–306 routing issues, 318
Red Hat Enterprise Linux data transfer tools, 310–311 rpm commands, 145–147, 172
(RHEL), 4, 145, 186, 330, 331, remote GUI tools, 311 option for, 146
375, 380, 426 remote desktop, 308 using, 146–147
Red Hat Package Manager remote log forwarding, 266 RPM package manager. see Red
(RPM), 145–156 remote systems, test, 314–315 Hat Package Manager (RPM)
choosing commands to use, certificates with the openssl RPMs, 175, 206
150 s_client command, 315 RSA SecurID®, 370
Debian compared to, display network nodes with rstate, in SysVinit system, 260
142–143 Nmap, 314, 314 rsync command, 310–311
DNF package manager, 145, repositories rsyslog
149–150 APT configuration files, 160 configure, 264–265
query packages on, 150–152 configuration files for RPM, modules portion of, 264
repositories, 152–155 153–155 severities and facilities,
rpm commands, 145–147 Debian-based, 160 264–265, 265
rsyslog service, 246
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Server Message Blocks (SMB), shell script elements, 390–400 command reference table,
201, 201, 203 built-in shell commands, 172
service command, 260–261, 390–391 compile from source code,
284 common script utilities, 162–164 (see also software
service failures, 259–260 394–398 compilation)
service mesh, 446 exit codes, 393–394 Debian-based software
services, defined, 252 identify, 391–393 packages and repositories,
services, managing, 251–284 redirection, 398–399 157–161
best practices and shell variables, 401 RPM software packages and
guidelines, 283 troubleshoot, 405–406 repositories, 145–156
command reference table, shielded twisted pair (STP), 288 run software in a sandbox,
284 show command, 431 168–170
localization settings, shred command, 198, 214 summary, 171–172
configure, 277–282 shutdown command, 11 understand, 140–144
summary, 283–284 SIGHUP signal, 224–225 software RAID, 176–177, 200,
system services, configure, SIGKILL signal, 224–225 211
263–276 SIGTERM signal, 224–225 software version control, 152
system services, manage, Simple Mail Transfer Protocol solid-state disk (SSD), 174, 208,
252–262 (SMTP), 290 211
.service unit files, 255–256 single sign-on (SSO), 369 sort command, 112
session module, 372 sleeping (process state), 230 source command, 391
sestatus command, 379, 379 Small Computer Systems special devices, 218–219
setfacl command, 77, 78, 79, Interface (SCSI), 175 special Linux permissions,
79, 82 throughput and, 206 74–76
set group ID (SGID), 74–75 smart cards certificate, 364 absolute mode to set,
setsebool command, 379 Snaps, 169 74–75
set user ID (SUID), 74–75 socket tools, to test set group ID, 74–75
set variables, 401 connectivity, 341–343 set user ID, 74–75
sftp command, 310 lsof command, 343, 343 sticky bit, 75
sha1sum command, 367, 367 netstat command, 341–342 symbolic mode to set,
sha256sum command, 367 ss command, 342–343, 343 74–75
sha384sum command, 367 software acquisition, 165–166 troubleshoot access, 75
sha512sum command, 367 curl command, 165–166 ss command, 342–343, 343,
sha#sum commands, 367, 383 download sites, review, 165 353
sh-bang command, 388 tar command to manage SSH. see Secure Shell (SSH)
shell commands, 390–391 source code, 166 SSH port forwarding, 308
echo command, 390 wget command, 165–166 standard error (stderr), 103
exec command, 390–391 software compilation, 162–164 standard input (stdin), 103
read command, 390 commands, 162–163 standard output (stdout), 103
source command, 391 GCC, 162 starting a service, 254
shell expansion, defined, 413 package management stat command, 87, 87, 116
shell parameter expansion, distinguished from, 140–141 static IP addresses, 298
412–415 process to build the status command, 431
command substitution, 413 executable file, 163 sticky bit, 75
globbing, 414 reasons for, 162 stopped (process state), 230
positional parameters, remove compiled software, storage, troubleshoot, 205–212
414–415 163 capacity issues, 208–210
shell expansion, defined, software management, device issues, 210–211
413 139–172. see also repositories disk performance, 205–208
variable substitution with acquire software, 165–167 filesystem issues, 210
braces, 413 best practices and storage-area network (SAN),
shells, 6, 9 guidelines, 171 202, 202–203
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
verify, prevent, analyze, and Universal Serial Bus (USB), 174, user login attempt failures, 55
document, 26 187, 208 user management issues,
troubleshoot user and group booting from, 454 troubleshoot, 54
issues, 54–57 Unix-style ps command, 227 usermod command, 34, 34, 58
login commands, 55–56, UNIX System V, 260 to add users to groups, 45,
56 unshielded twisted pair (UTP), 45
login issues, 54–55 288 exit code for, 39, 45
login process, 55 until loop, 411 modify and delete user
management issues, 54 updatedb command, 109–110, accounts, 37, 38
tunables, 381 118 in verification, 38
tune2fs command, 191, 214 uptime command, 229 user profiles, 34
tunneling, SSH, 308 urandom device, 219 users and groups, 31–59
twisted-pair Ethernet cable, use cases, certificate, 363–364 command reference table,
288 use cases, firewall, 328–329 58–59
type context, 376 user accounts, manage, 32–42 group accounts, manage,
Type= directive, in .service unit account configuration 43–46
files, 255 commands, 39–41 privilege escalation, 47–53
Type= option, in .mount unit account management summary, 58–59
files, 257 commands, 34–36 troubleshoot, 54–57
modify and delete user user accounts, manage,
U accounts, 37–39 32–42
user configuration files, user space, 239
Ubuntu Desktop, Server, Core,
32–34 user subdirectory, 243
4, 22, 142, 157, 169, 281, 300,
user account storage, 32, 32–33, user_u context, 375
330, 333, 444, 468, 469
33 /usr/bin subdirectory, 85
udev device manager, 218–219
useradd command, 34, 34, 58 /usr/lib64 subdirectory, 85
identify block, character,
exit code for, 38, 45 /usr/lib subdirectory, 85
and special devices, 218–219
options for, 34–35 /usr/local subdirectory, 85
use, 218
set a password, 35–36, 36 /usr/share subdirectory, 85
ufw command, 333–335,
user login attempt failures, /usr subdirectory, 85
352
55
umask command, 62, 66, 81
umount command, 186–187,
use the adduser command V
instead of, 36, 36
214 variables, 401–406
in verification, 38
Uncomplicated Firewall (UFW), alias command, 405, 405
user configuration files, 32–34
333–335, 334 env command, 403–404,
system and user profiles, 34
advanced settings, 334–335 404
user account storage, 32,
described, 333–334 environment, 402
32–33, 33
graphical user interface, export command, 403
user context, 375–376
334 HISTFILESIZE, 404
userdel command, 34, 34, 58
selecting a firewall, 335 modify, 403, 403–406
exit code for, 39, 45
unconfined_u context, 375 print, 404
in group management, 44
Unified Extensible Firmware retrieve, 401–402
modify and delete user
Interface (UEFI), 456 search paths, 404
accounts, 38
in GPT, 176 set, 401
-r option added to the
uninterruptible process state, troubleshoot shell and
command to remove the
230 environment, 405–406
account, 38, 54
unit understand, 401
in verification, 38, 39
in systemd unit files, 255 variable substitution with
User= directive, in .service unit
in .target unit files, 258 braces, 413
files, 256
unit files, 254–255, 255 /var/log directory, 86
user (u) identity, 63
universally unique identifiers /var subdirectory, 85
user lockouts, 373
(UUID), 462 vendor control, 152
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022
Index
LICENSED FOR USE ONLY BY: PRANAV KAMBLE · 31662591 · OCT 10 2022