Linux LPIC-1 Study Guide PDF
Linux LPIC-1 Study Guide PDF
Table of Contents
Topic 1: Performing Basic Linux Tasks ........................................................................................ 1
Identify the Linux Design Philosophy................................................................................................... 3
Enter Shell Commands .......................................................................................................................20
Get Help with Linux............................................................................................................................37
Topic 2: Managing Users and Groups........................................................................................51
Assume Superuser Privileges..............................................................................................................53
Create, Modify, and Delete Users.......................................................................................................67
Create, Modify, and Delete Groups ....................................................................................................83
Query Users and Groups ....................................................................................................................93
Configure Account Profiles ...............................................................................................................107
Topic 3: Managing Permissions and Ownership ......................................................................121
Modify File and Directory Permissions .............................................................................................123
Modify File and Directory Ownership ...............................................................................................140
Configure Special Permissions and Attributes...................................................................................146
Troubleshoot Permissions Issues......................................................................................................164
Topic 4: Managing Storage.....................................................................................................174
Create Partitions ..............................................................................................................................176
Manage Logical Volumes..................................................................................................................208
Mount File Systems..........................................................................................................................222
Manage File Systems........................................................................................................................231
Navigate the Linux Directory Structure.............................................................................................249
Troubleshoot Storage Issues ............................................................................................................265
Topic 5: Managing Files and Directories .................................................................................286
Create and Edit Text Files .................................................................................................................288
Search for Files.................................................................................................................................311
Perform Operations on Files and Directories ....................................................................................322
Process Text Files .............................................................................................................................337
Manipulate File Output ....................................................................................................................364
Topic 6: Managing Kernel Modules.........................................................................................380
Explore the Linux Kernel ..................................................................................................................382
Install and Configure Kernel Modules...............................................................................................395
Monitor Kernel Modules ..................................................................................................................408
Topic 7: Managing the Linux Boot Process ..............................................................................417
Linux LPIC-1 I
Configure Linux Boot Components ...................................................................................................419
Configure GRUB 2 ............................................................................................................................442
Topic 8: Managing System Components .................................................................................459
Configure Localization Options.........................................................................................................461
Configure GUIs .................................................................................................................................476
Manage Services ..............................................................................................................................498
Troubleshoot Process Issues.............................................................................................................519
Troubleshoot CPU and Memory Issues .............................................................................................547
Topic 9: Managing Devices .....................................................................................................570
Identify the Types of Linux Devices ..................................................................................................572
Configure Devices ............................................................................................................................588
Monitor Devices...............................................................................................................................603
Troubleshoot Hardware Issues .........................................................................................................614
Topic 10: Managing Networking.............................................................................................629
Identify TCP/IP Fundamentals ..........................................................................................................631
Identify Linux Server Roles ...............................................................................................................648
Connect to a Network ......................................................................................................................669
Configure DHCP and DNS Client Services ..........................................................................................694
Configure Cloud and Virtualization Technologies..............................................................................710
Troubleshoot Networking Issues ......................................................................................................725
Topic 11: Managing Packages and Software...........................................................................759
Identify Package Managers ..............................................................................................................761
Manage RPM Packages with YUM ....................................................................................................771
Manage Debian Packages with APT..................................................................................................783
Configure Repositories .....................................................................................................................790
Acquire Software .............................................................................................................................798
Build Software from Source Code.....................................................................................................806
Troubleshoot Software Dependency Issues ......................................................................................815
Topic 12: Securing Linux Systems ............................................................................................823
Implement Cybersecurity Best Practices...........................................................................................825
Implement Identity and Access Management Methods....................................................................847
Configure SELinux or AppArmor .......................................................................................................869
Configure Firewalls ..........................................................................................................................885
Implement Logging Services .............................................................................................................908
Back Up, Restore, and Verify Data....................................................................................................924
Linux LPIC-1 II
Topic 13: Working with Bash Scripts .......................................................................................955
Customize the Bash Shell Environment ............................................................................................957
Identify Scripting and Programming Fundamentals ..........................................................................977
Write and Execute a Simple Bash Script............................................................................................989
Incorporate Control Statements in Bash Scripts..............................................................................1006
Topic 14: Automating Tasks..................................................................................................1028
Schedule Jobs.................................................................................................................................1030
Implement Version Control Using Git .............................................................................................1042
Identify Orchestration Concepts.....................................................................................................1052
Topic 15: Installing Linux ......................................................................................................1064
Prepare for Linux Installation .........................................................................................................1066
Perform the Installation .................................................................................................................1082
Linux LPIC-1 1
In this topic, you will:
• Identify the high-level design concepts that make up the Linux operating system.
• Use fundamental Linux shell commands to get started with the command-line interface (CLI).
• Use various resources to find help on the Linux operating system.
Linux LPIC-1 2
Linux LPIC-1 3
OPEN SOURCE SOFTWARE
Open source software (OSS) refers to computer code that any user is permitted to view, copy,
and modify for any reason, as well as distribute to anyone. Users are granted these rights when
the author of the software releases the source code under one of several open source licenses.
The opposite of OSS is proprietary software— software that is released under a license that
imposes restrictions on one or more of the rights just mentioned (view, copy, modify,
distribute).
OSS provides several advantages to users, administrators, and programmers alike. Perhaps the
most important element of OSS is that it encourages the ongoing improvement of software in a
collaborative, community-driven environment. Individuals or groups of developers may build
upon another developer's work to create enhanced or customized software, all while avoiding
legal issues. There are many examples of OSS, one of which is the Linux kernel.
Linux LPIC-1 4
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 5
FREE SOFTWARE VS. OPEN SOURCE SOFTWARE
The term free so=ware is oNen used interchangeably with OSS, and both share a great deal of
overlap. However, some draw a disPncPon between the two. Richard Stallman, the founder of
the free soNware movement, argues that the terms share different values—in his words, "Open
source is a development methodology; free soNware is a social movement." In other words,
OSS is most concerned with fostering open collaboraPon, whereas free soNware is most
concerned with upholding users' rights. Note that "free" is being used in the sense of freedom,
not in the sense of having no monetary cost.
In an aUempt to resolve this terminology dispute, some developers have adopted the term free
and open source so=ware (FOSS) to describe any project that embodies the values of both
movements.
Linux LPIC-1 6
FREE AND OPEN SOURCE LICENSES
There are several FOSS licenses that a developer can release their soNware under. These
licenses may differ when it comes to addiPonal restricPons or compaPbility with other licenses.
The following are some examples of FOSS licenses:
• Apache License
• Berkeley SoNware DistribuPon (BSD) license family
• CreaPve Commons Zero (CC0)
• Eclipse Public License (EPL)
• GNU General Public License (GPL)
• MassachuseUs InsPtute of Technology (MIT) License
• Mozilla Public License (MPL
Linux LPIC-1 7
THE GNU PROJECT
The GNU Project is a free software project led by Richard Stallman. Announced in 1983, it was
the first project of its kind, and effectively launched the free software movement. The GNU
Project's goal is to create an operating system that is composed of entirely free software. By
the early 1990s, the GNU Project had not completed a full OS, but had created several
programs. Stallman wrote much of the GNU software himself, including the GNU C Compiler
(GCC) and the Emacs text editor. Later, several programmers worked together to develop more
utilities that are compatible with GNU software.
Stallman chose the recursive acronym "GNU's Not Unix" to show that GNU software was
similar in design to the proprietary Unix operating system, but did not actually contain any Unix
code.
Linux LPIC-1 8
FREE SOFTWARE FOUNDATION AND THE GNU GPL
Shortly after kicking off the GNU Project, Stallman founded the nonprofit Free Software
Foundation (FSF) to promote the philosophy behind free software. Stallman and the FSF
created the GNU General Public License (GPL) to support the GNU Project. One of the
requirements of the GPL is that any derivative of a GPL work must also be distributed under
that same license—a concept known as copyleft.
Linux LPIC-1 9
THE LINUX OPERATING SYSTEM FAMILY
Linux is a family of operaPng systems based on the Linux kernel, the central core of the OS that
manages all components in the system. The Linux kernel was developed by Finnish programmer
Linus Torvalds in 1991, while he was a student at the University of Helsinki.
FOSS, the GNU Project, and the Unix design philosophy have all played an important role in the
development of Linux. Torvalds released the Linux kernel under version 2 of the GPL. Most
distribuPons of Linux add GNU soNware wriUen by Stallman and other free soNware
components on top of the Linux kernel. In other words, Linux is the first complete operaPng
system family to qualify as FOSS, and like GNU soNware, it follows the principles of simplicity
and modularity set forth in the Unix design philosophy.
Linux LPIC-1 10
Fundamentally, Linux is a combinaPon of the Linux kernel and GNU soNware.
GNU/LINUX
Because most members of the Linux OS family incorporate GNU uPliPes along with the Linux
kernel, the FSF prefers to call the OS family "GNU/Linux" rather than just "Linux." This supports
the idea that the Linux kernel was the "missing piece" to the GNU Project, and gives credit to
GNU for its tools and the free soNware movement itself. However, Torvalds and others disagree
with this assessment, and the name "Linux" is by far the most common way of referring to the
OS family.
Linux LPIC-1 11
ADVANTAGES OF USING LINUX
To summarize, the following are some of the major advantages of using Linux:
• Its FOSS nature promotes transparency.
• Its design emphasizes simplicity and modularity.
• It is highly customizable.
• It is highly reliable and stable.
• It has strong integration with several major programming languages, like C, C++, Python®,
Ruby, etc.
• It places an emphasis on security and privacy.
• Most distributions are free of monetary cost.
• It has a passionate community willing to provide support.
Linux LPIC-1 12
DISADVANTAGES OF USING LINUX
No system is perfect, including Linux. The following are some potential disadvantages:
• It has a sharper learning curve than other general purpose operating systems like Windows®
and macOS®.
• Desktop software is not as well-supported as it is in other operating systems like Windows
and macOS.
• There is no definitive or official version, which can be confusing to new users.
• With some exceptions, there is no official vendor-provided support.
Linux LPIC-1 13
LINUX DISTRIBUTIONS
As a family of operaPng systems, there is no official OS called "Linux." Instead, there are disPnct
members of the family called Linux distribuTons, or distros. All Linux distros are based on the
Linux kernel; they differ primarily in what addiPonal soNware they add on top of the kernel to
create a fully funcPonal OS, as well as the version of the kernel they run. There are also
differences in community, rate of release, and other factors. Choosing a distribuPon is a maUer
of idenPfying which one most closely aligns with your business needs as well as your familiarity
with its tools.
Linux LPIC-1 14
LIST OF LINUX DISTRIBUTIONS
There are hundreds of distros available. The above table includes some of the most historic
and/or popular ones.
Linux LPIC-1 15
MORE ON CENTOS
The CentOS Linux distribution is a stable, predictable, manageable, and reproducible platform
derived from the sources of RHEL. CentOS is maintained by the CentOS Project, a community-
driven free software effort that has its own governing board. The members of the CentOS
Project work independently of the RHEL team. However, CentOS benefits from Red Hat's
ongoing contributions and investment, and the CentOS trademark is owned by Red Hat.
This course uses CentOS because it provides a free enterprise-class computing platform that
aims to be functionally compatible with the upstream product (RHEL) that it derives from.
CentOS does not contain Red Hat's product or certifications, although it is built from the same
sources as the upstream enterprise products. More details about this are available in the
CentOS FAQ here: https://wiki.centos.org/FAQ/ General.
For production environments, the licensed and fully supported RHEL product is recommended.
Linux LPIC-1 16
USES FOR LINUX
One of the main advantages of Linux is that it is highly extensible. As a result, Linux has been
applied to many different computing roles. The above table describes these roles.
Linux LPIC-1 17
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 18
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 19
Linux LPIC-1 20
The design of the Linux operating system emphasizes a particular kind of user interface; one in
which the user types text commands into a prompt in order to interact with the system. This
differs from the primarily visual operating systems like Windows and macOS. Therefore, one of
the most crucial skills in Linux administration is becoming comfortable at entering text
commands. In this topic, you'll enter a few basic commands to become more familiar with the
process.
THE CLI
The command-line interface (CLI) is a text-based interface between the user and the operating
system that accepts input in the form of commands. The CLI presents a command prompt to
the user, and the user enters a command to interact with the system in a variety of ways.
Working at the command-line is an important tool in any administrator's arsenal. Developers
and administrators often use the CLI, whereas regular users will typically rely on a graphical
user interface (GUI).
Linux LPIC-1 21
CLI ADVANTAGES AND CHALLENGES
Some advantages to using the CLI include:
• It's faster for the system to process.
• It's faster for administrators to enter informaPon.
• Commands can be stored in text files called scripts that you can execute with one
• command, resulPng in a long series of acPviPes by the system.
• Scripts can be scheduled to execute on a regular basis.
• AddiPonal opPons are available in the CLI that may not be present in the GUI.
Linux LPIC-1 22
SHELLS
A shell envelops the core portion of the operating system—referred to as the kernel—
permitting the user to pass commands and information to the kernel. The kernel is also able to
respond back to the user via the shell. The shell can be thought of as an interpreter between
human and kernel languages. Linux users issue commands in the shell to tell the operating
system what to do. The operating system responds back to the user with the results.
Linux LPIC-1 23
A shell can be implemented as either a CLI or a graphical user interface (GUI). The following
table lists some common CLI-based shells that are used in Linux.
Shell Description
This is the original Unix shell that is still available on Linux systems,
Bourne shell (sh)
though not widely used.
This is the default Linux shell and a replacement for the Bourne
Bash (bash)
shell. Its full name comes from the term Bourne-again shell.
This shell is based on the C programming language and was
C shell (csh)
designed to support C language development environments.
KornShell (ksh) This shell uses the features of the C shell with the syntax of the
Bourne shell. It is common on Unix systems.
Linux LPIC-1 24
MORE ON BASH
As a Linux user, it is essential to be comfortable using the default Bash shell. Virtually every
Linux distribution will use this shell as the translator between the user and the system. It is
possible to install and use other shells in Linux if users are more comfortable with them, but
the default will almost always be Bash.
Some characteristics of Bash include:
• It's been around for a very long time, so it is well documented with many existing scripts.
• It's commonly used in Linux and macOS (where it is also the default) and with various other
operating systems.
• It's not always consistent, since there have been a great many modifications by various
groups since its creation.
• It includes history and tab completion features.
BASH SYNTAX
Command-line administration includes the idea of "syntax," or the proper way of structuring a
command and any supporting information. The many CLIs have their own unique ways of
entering information. You need to understand this syntax to be able to effectively communicate
with the interface.
Bash shell syntax contains three main components: the command, options to modify the
command, and an argument for the command to act upon. It is common for new users to Bash
to forget the spaces between the three components.
The basic syntax of Bash is therefore: command [-options] [arguments]
The above table lists an example of each type of basic syntax format using the ls command.
Linux LPIC-1 25
The ls -la command displaying the list of files in the /usr directory.
Linux LPIC-1 26
ERRORS
If you fail to enter a command in the proper syntax, Bash will return an error. Typically, these
error messages are descriptive and will help you to understand what Bash expects. For
"command not found" errors, check for typos in the command. For "no such file or directory"
errors, check for typos in the directory, file, or file path names.
Linux LPIC-1 27
FILE VIEWING COMMANDS
Linux system configurations are held in text files, so you'll need to be able to view the contents
of those files.
The cat command is used to view the contents of a file without the option to edit that file. An
example of using cat is cat file1 to show the contents of file1 on the screen.
The less command is used to view the contents of a file when those contents won't fit entirely
on one screen. This command breaks the content output into pages that you can scroll through
at the CLI. An example of using less is less file1 to break the contents of file1 into multiple
pages when its contents are lengthy enough to go past a single screen. Press Page Up and Page
Down to scroll screens, and press q to exit the command.
Linux LPIC-1 28
FILE EDITING COMMANDS
Just as you'll need to view the contents of text files, you'll also need to edit them.
vim
1. vim file1 to open file.
2. Press i to insert.
3. Press Esc to leave insert.
4. :wq to save/quit.
nano
1. nano file1 to open file.
2. Enter text directly.
3. Press Ctrl+O to save.
4. Press Ctrl+X to quit.
gedit
1. Select Applications→Accessories→Text Editor.
2. Enter text directly.
3. Use menu to save/quit.
Linux LPIC-1 29
POWER MANAGEMENT COMMANDS
Periodically, it may be necessary to reboot or shut down the system. There are several
commands to accomplish this, but for now you will focus on the shutdown command. Some
examples of the shutdown command include:
• shutdown -h now shuts down the system with no time delay.
• shutdown -h -t 90 shuts down the system in 90 seconds.
• shutdown -r now reboots the system with no time delay.
Linux LPIC-1 30
SUPERUSER COMMANDS
In Linux, the user with administrator credentials is the superuser. The superuser is typically
named root. It is generally a bad practice to log onto the system as the superuser, and you
should get in the habit of logging in with a non-privileged account. However, there will be times
when you need to assume the privileges of the superuser in order to perform an administrative
task.
The su - command ("substitute user") switches user credentials, and su - root switches
credentials to the root user. The system will prompt you to enter the root user's password for
authorization purposes. Once you are logged in as root, you will be able to perform tasks that
you were previously unable to.
Linux LPIC-1 31
SHELL HISTORY
The Bash shell keeps a history file of all commands entered. You can reference this file and
repeat commands, increasing efficiency and consistency of entered commands.
Linux LPIC-1 32
TAB COMPLETION
The Bash shell supports tab completion, enabling users to type in enough of a command, file
name, or directory name to be unique, then filling in the remainder of the entry. This feature
reduces typographical errors and speeds up the entering of commands.
Linux LPIC-1 33
SHELL TIPS AND TRICKS
While the command-line interface can be intimidating, there are several ways of making it
easier to work with and more efficient. As you get more comfortable with Bash, you may find
you prefer working at the CLI much of the time.
Here are a few tips to help make working at the command-line easier:
• Tab completion: Get in the habit of using tab completion for speed and to minimize typos.
• Use history instead of re-writing long commands: When you make a typographical error in a
command or file name, do not manually re-type 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.
• Read the command backward: When troubleshooting your commands, start from the right
and read to the left. This method makes it a great deal easier to notice missing or duplicate
characters.
• 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.
Linux LPIC-1 34
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 35
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 36
Linux LPIC-1 37
Now that you are familiar with the Linux shell, you may want to begin using commands in your
system. However, there will be times when you need assistance with the various available
commands. In this topic, you will identify the help and support options offered by Linux.
LINUX DOCUMENTATION
Documentation is a necessity in any major computing project, and Linux is no different.
Documentation helps users of the Linux operating system, no matter their role or experience
level, to perform a wide range of activities and resolve a wide range of issues. However, just like
there is not one official form of Linux, neither is there a single, authoritative source of
documentation. Documentation is spread across multiple sources that appear in multiple
forms, each one suited to a particular context.
Some of major sources of Linux documentation include:
• Manual pages
• Built-in help commands
• Online documentation projects
• Usenet newsgroups
• Internet mailing lists
• Question and answer websites
• Forums and social media
• Books and other print resources
Linux LPIC-1 38
MANUAL PAGES
Linux manual pages, or man pages, contain the complete documentation that is specific to
each Linux command. The man pages are available on Linux systems by default. The man page
for a specific command is displayed using the man command. They usually include information
such as the name of the command, its syntax, a description of its purpose, the options it
supports, examples of common usage of the command, and a list of related commands.
Man pages are perhaps the most immediate source of help available when you need to learn
more about what a command does or how to operate it. They are especially useful in situations
where Internet access is not available. However, man pages can be difficult to parse for
someone not familiar with how they're formatted.
Linux LPIC-1 39
SYNTAX
The syntax of the man command is man {command}
SYNOPSIS FORMAT
Most of the components of a man page are self-explanatory, but the SYNOPSIS component can
be somewhat confusing to new users. This part of a man page provides the syntax of the
command along with some example use cases. These use cases are formatted as such:
• bold text should be typed exactly as shown.
• italic text should be replaced with the appropriate argument. Note that this may be
formatted differently on certain systems, like underlined text or colored text.
• [-abc] indicates that all arguments within the brackets are optional.
• -a|-b indicates that the arguments on either side of the pipe (|) cannot be used together.
• italic text with ... (ellipsis) after it indicates that the argument can be repeated.
• [italic] text with ... after it indicates that the entire expression within the brackets can be
repeated.
Linux LPIC-1 40
man COMMAND OPTIONS
The man command supports different options. Some of the frequently used options are listed
above.
Linux LPIC-1 41
MAN PAGE SECTIONS
Man pages for commands may be listed under one or more sections. A section defines what
category the command belongs to. When a command has more than one section listed, it
means that documentation for the same command is available from more than one source.
These sections are identified by the number displayed beside the command; for example, fsck
(8)
Various man page sections are provided in the above table
Linux LPIC-1 42
MAN PAGES NAVIGATION
You can navigate through Linux man pages using a number of keys. These keys are described in
the above table.
Linux LPIC-1 43
OTHER BUILT-IN HELP OPTIONS
In addition to the man command, Linux offers other built-in options for help.
Linux LPIC-1 44
ONLINE DOCUMENTATION
The Internet is one of the best places to go to for help with Linux. There is not one single online
source that is necessarily better than the others; the choice often comes down to what type of
help you're looking for. The above table lists some of the best online sources for Linux
documentation.
Linux LPIC-1 45
The online documentation for the RHEL 7 distribution.
Linux LPIC-1 46
INTERACTIVE HELP
Online documentation is a quick and easy reference point, but it's not always the best source
for answering your Linux questions, especially if those questions are complex or apply to
unconventional scenarios. These questions are often best answered by interacting with other
people directly, whether in real-time or asynchronously. The above table lists some of the
major sources of interactive help on the Internet for Linux issues.
Linux LPIC-1 47
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 48
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 49
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 50
Now that you've performed some basic Linux® tasks, you're ready to start diving deeper into
configuring the operating system for use by yourself and others. Before users can take
advantage of Linux, you'll need to create and manage accounts for them. So, in this topic, you
will manage user and group accounts.
Linux LPIC-1 51
In this topic, you will:
Linux LPIC-1 52
Linux LPIC-1 53
USER ACCOUNTS
Accounts are objects that represent users and services to Linux. If these entities are
represented by an account, then that account can be managed. User accounts represent
identities that authenticate to the system and can use authentication credentials to do specific
tasks. User information includes group memberships.
Individuals who will be using the Linux computer should have their own unique user accounts.
Administrators will use these accounts to control the user's access to files, directories, and
commands on the system. Each account is referenced by the system using a user ID (UID),
rather than a name. Names are used for the convenience of the users.
User accounts have several attributes, including password information, group memberships,
expiration dates, comments, etc.
Linux LPIC-1 54
TYPES OF USER ACCOUNTS
There are three different types of accounts: root, standard user, and service.
The root user account plays two roles on a Linux system. The first role is that of the local
administrator. A user logged on as root can do administrative tasks such as password resets,
system configuration changes, user account management, etc. The second role played by the
root user account is to provide a security context for some applications and commands. These
applications and commands may be called by the system or manually entered by a user logged
on as root. The root user account in Linux is significantly more powerful than the local
administrator account on a Windows® system. It is a bad practice to log on to any system with
administrative credentials. On a Linux system, this can be particularly dangerous. The root user
can take destructive action on the system, often without any verification prompt.
Standard user accounts represent regular system users who may log on to run applications,
configure databases, build websites, etc. Each user should have their own account and these
accounts should not be shared. Most tasks that a user should be doing on the system should
only require standard user account privileges. It is possible to set a standard user account to
have administrative privileges. The advantage of this over permitting the user to log on as root
directly is that the privileges of the standard user can be limited, whereas the root user
privileges cannot.
Applications also consume resources on the system, so they are often represented by their own
service accounts. These accounts are usually specific to the service (such as the httpd web
service or a database service). They are disabled for regular log on, and the accounts are
usually created as part of the service installation process. They will often own configuration
files or executables associated with the service.
Linux LPIC-1 55
SUPERUSER
In Linux, the local administrator account is named root. The account is used to perform
administrative functions like managing users, configuring devices, configuring network settings,
etc. The system also runs services with root credentials. The system does not necessarily
confirm with the root user potentially destructive commands. The authority to log on to the
system with root credentials is usually associated with the knowledge of administrative
functions.
The root account is also referred to as the superuser. The security best practice is to never log
on to the system with administrative credentials, but rather to log on with a non-privileged
account and elevate credentials when necessary.
Linux LPIC-1 56
PRINCIPLE OF LEAST PRIVILEGE
In information security, the principle of least privilege states that users should be given no more
authority on the system than they need to perform their job. If a user needs to be able to read
but not write to a file, then give them only read. If a user needs to be able to restart the server
but not reconfigure the server, then only give them privileges to restart. It is much easier to
correct privilege issues by giving a little more access than it is to remove existing access. By
giving the user the access they need to do their jobs and no more than that, the system will
remain significantly more secure.
Linux LPIC-1 57
THE su COMMAND
As you have seen, it is a poor practice to log on to the server directly with root privileges. The
better practice is to log on with a standard user account, then elevate your privileges to root as
needed. One way of elevating privileges is to "substitute user" using the su command.
The su command, without an option, enables a user to switch their identity to that of another
user, but it retains the original user's profile and variables. The switched user also remains in
the home directory of the original user. Anyone using su except the root user will be challenged
for the password of the user account they are switching to.
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 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 so long as they
know the user's password.
SYNTAX
The syntax of the su command is su [-] [user name]
Linux LPIC-1 58
Substituting another user for the current one.
Linux LPIC-1 59
THE sudo COMMAND
With the su command, any user who knows the root password can "get root" and do anything
the root user can do. An account using su – root essentially is the server administrator. This is
often much more power than should be delegated to users. A better practice is to delegate
specific functions to users, rather than granting system- wide root privileges.
The sudo command enables the server administrator to delegate specific commands to specific
users, without granting them full privileges on the server. Delegation is done in the
/etc/sudoers file by using the visudo editor. Users and groups may be given specific commands
to run in order to fulfill their responsibilities without having full administrator privileges.
SYNTAX
The syntax of the sudo command is sudo [options] {command}
Linux LPIC-1 60
THE sudoedit COMMAND
Some Linux files require root user privileges to edit. This could be accomplished with a sudo
configuration, but a simpler and more secure option is to use the sudoedit command. This
command permits a user to edit a file with their own credentials, even if the file is only
available to the root user. In addition, the user can use their preferred text editor.
To use sudoedit, you must make an entry in the sudoers file. For example, the following line
could be added to the sudoers file:
The sudo configuration is appropriate for commands that need to be executed with elevated
privileges, while the sudoedit option is appropriate for files that need to be edited with
elevated privileges.
SYNTAX
The syntax of the sudoedit command is sudoedit [options] {file name}
Linux LPIC-1 61
THE visudo COMMAND
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.
Linux LPIC-1 62
SYNTAX
The syntax of the visudo command is visudo [options]
Option Used to
Linux LPIC-1 63
THE wheel GROUP
The root system account is used for a great deal more than just administrative tasks. Many
parts of the actual Linux operating system run under root credentials. Many distributions
disable the actual root account for users and instead allow administrative functions based on
membership in the wheel group.
Members of the wheel group exercise the administrative privileges of root with less potential
for damaging the system. For example, members of the wheel group can use the sudo
command to avoid having to sign in as the root user. You can use the visudo command to edit
the privileges of the wheel group, if necessary. You can add users to the wheel group to give
them privileges. Be very cautious about the membership of the wheel group.
Linux LPIC-1 64
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 65
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 66
Linux LPIC-1 67
THE useradd COMMAND
The useradd command is used to create user accounts and configure basic settings. As part of
the account creation process, useradd references several files:
• The account is stored in the /etc/passwd file.
• The account is configured according to various options set in the /etc/login.defs file.
• The account's home directory is created at the /home/<account name> directory.
• The account's home directory is populated using files from the /etc/skel directory.
By default, the useradd command does not set a password for the account. Since most Linux
distributions will not permit a blank password, the account will exist but is not yet usable.
Linux LPIC-1 68
SYNTAX
The syntax of the useradd command is useradd [options] [user name]
Linux LPIC-1 69
THE passwd COMMAND
The passwd command is used by root to set or reset a password for any user. A user can use
the passwd command themselves to reset their own password. It is also used to set the initial
password for a user after creating the account with the useradd command.
Linux LPIC-1 70
SYNTAX
The syntax of the passwd command is passwd [user name] where [user name] can be used by
root to set a specific user's password.
Linux LPIC-1 71
THE /etc/passwd FILE
The /etc/passwd file stores user account information. All accounts, default or user-specific, will
be found in this file. It is common for administrators to reference this file to learn about specific
user accounts on the system. Each account contains seven fields of information. Each field is
separated by a colon. The fields are not necessarily all populated.
Field Content
User name Name user logs into system with.
Password Password assigned to user (x means stored elsewhere).
User ID Unique number representing user.
Group ID Unique number of user's primary group.
Comment User's full name (usually).
Home directory Path to user's home directory.
Login shell Path to shell launched when user logs in.
Linux LPIC-1 72
THE /etc/shadow FILE
The /etc/passwd file was once used to store the cryptographically hashed version of
passwords. That file is world-readable, however, meaning that one user could see the hashed
version of another user's password. By entering that hashed password in a password cracking
utility, a user could discover another user's password.
The /etc/shadow file is the modern storage location for hashed passwords, as well as
additional account information. This additional information includes password requirements
and expiration information. Only root has access to the content of
the /etc/shadow file, preventing users from attempting to crack each other's passwords.
Linux LPIC-1 73
THE /etc/shadow FILE FORMAT
The following table details the format of the /etc/shadow file.
Field Content/Additional Information
User name The name the user logs into the system with.
Password The hash value of the password that is assigned to the user.
Days since password
Days are counted from January 1, 1970.
changed
Days before password
Typically set as 1 day.
must be changed
Days until user is warned A value of 99999 means the password never needs to be
to change password changed.
Days after password
expires that account is Ideally, this should be immediate.
disabled
Days the account has been
Days are counted from January 1, 1970.
disabled
Unused field Reserved for potential use in the future.
Linux LPIC-1 74
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 75
THE chage COMMAND
The chage or "change age" command is used to control password expiration, expiration
warnings, inactive days, and other information for existing accounts. Changes to a security
policy or potential security breach may prompt the administrator to alter the password settings
for existing accounts. These changes are reflected in the /etc/shadow file.
SYNTAX
The syntax of the chage command is chage [options] {user name}
Linux LPIC-1 76
THE usermod COMMAND
The usermod command is used to modify settings for regular users. It edits
the /etc/passwd file, avoiding the need for administrators to edit the file directly. There are
many modifications an administrator can make to an existing user account.
The above table lists some options for the usermod command.
SYNTAX
The syntax of the usermod command is usermod [options] {user name}
Linux LPIC-1 77
LOCK USER LOGIN
An administrator may lock a user account if that user leaves the company, if there's a security
breach, or if the user takes a long leave of absence. Locking the account renders it unusable
without deleting the account or its settings. The account can be unlocked when needed.
User accounts can be locked with either the passwd or usermod commands.
To lock:
• passwd -l {user name}
• usermod -L {user name}
To unlock:
• passwd -u {user name}
• usermod -U {user name}
Linux LPIC-1 78
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 79
THE userdel COMMAND
The userdel command is used to delete user accounts. By default, it does not delete the user's
home directory, unless you use the -r option. Deleting the user account removes all references
to it. You would have to recreate the account and re-add it to groups in order to resemble the
original identity. Use caution before deleting a user account.
SYNTAX
The syntax of the userdel command is userdel [options] {user names}
Linux LPIC-1 80
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 81
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 82
Linux LPIC-1 83
GROUP ACCOUNTS
Groups associate user accounts that have similar security requirements. Groups simplify
administrative tasks, allowing multiple users to be granted permissions to resources. Groups
are represented on the system by a group ID number (GID). Users may be a member of more
than one group.
Linux LPIC-1 84
THE /etc/group FILE
The /etc/group file is the storage location for groups. All groups, default or user- specific, will
be found in this file. It is common for administrators to reference the /etc/group file to find
information about the groups on the system. Each group contains four fields of information.
Each field is separated by a colon. The fields are not necessarily all populated.
Linux LPIC-1 85
The proper way to edit the /etc/group file is with the groupadd, groupmod, and groupdel
commands. Manually editing the file is not recommended, as a mistake could render the
system unusable.
Linux LPIC-1 86
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 87
THE groupadd COMMAND
The groupadd command creates a group. By default, the group has no members and no
password. In addition to creating a group with a friendly name, you can also specify a group ID
using the -g option.
SYNTAX
The syntax of the groupadd command is groupadd [options] {group names}
Linux LPIC-1 88
THE groupmod COMMAND
The groupmod command is used to change the group's own attributes. It will edit the
/etc/group file for you. Modifications of the group might include changing its name or GID.
SYNTAX
The syntax of the groupmod command is groupmod [options] {group names}
Linux LPIC-1 89
THE groupdel COMMAND
The groupdel command will delete groups from the /etc/group file. It does not delete user
accounts that are members of the group. Exercise caution when deleting groups as a mistake
can cause users to not be able to access resources.
SYNTAX
The syntax of the groupdel command is groupdel [options] {group names}
Linux LPIC-1 90
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 91
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
Linux LPIC-1 92
Linux LPIC-1 93
ACCOUNT QUERYING
Administrators and users may need to gather information about their identity on the system.
There are many commands that will report user and group information. This information is
useful for troubleshooting access problems or verifying what account the user is currently
logged on with.
Linux LPIC-1 94
THE whoami COMMAND
The whoami command is used to display the user name with which you are currently logged in
to the system. Sometimes, you may need to log in to a system and switch among different
users, and you may not be sure with which user you are currently logged in. In such instances,
you can use the whoami command to verify your current user name.
Linux LPIC-1 95
COMMAND PROMPT IDENTIFICATION
Many Linux distributions will show the user name of the currently logged in user at the
command prompt. For the root user, the prompt will show a # character. For standard users,
the prompt will show a $ character.
Linux LPIC-1 96
THE who COMMAND
The who command is used to determine the details of users currently logged in to a system.
The output of the who command includes the user name, the name of the system from which
the user is connected, and the date and time that the user has been connected since.
Linux LPIC-1 97
SYNTAX
The syntax of the who command is who [options]
Linux LPIC-1 98
THE w COMMAND
The w command is primarily used to display the details of users who are currently logged in to
a system and their transactions. The first line of the output displays the status of the system.
The second line of the output displays a table with the first column listing the users logged in to
the system and the last column indicating the current activities of the users. The remaining
columns of the table show different attributes associated with the users.
SYNTAX
The syntax of the w command is w [options] [user name]
Linux LPIC-1 99
Displaying user details and transactions.
SYNTAX
The syntax of the last command is last [options]
SYNTAX
The syntax of the id command is id [options] [user name]
A good example of the use of the .bashrc file is the use of aliases. Users can specify their own
abbreviated commands without impacting the experience of any other user on the system.
Another common configuration within .bashrc is environment variables. Users can also use the
file to customize the command prompt to provide the information they want.
EXAMPLE
An example of a .profile is as follows:
PATH=$PATH:$HOME/bin:/scripts
MAIL=/var/mail/$LOGNAME
EDITOR=emacs
export PATH MAIL EDITOR
The first line defines the paths of executable files; the second line defines the path for where
incoming email messages are stored; and the third line defines the default text editor. The last
line actually ensures these variables are implemented in the environment.
PERMISSIONS
Permissions are access rights assigned to users, which enable them to access or modify certain
files and directories. Permissions can be set at different levels and for different access contexts.
They enable you to configure who is allowed to access an object, and who is restricted from
accessing that object. Controlling access through permissions mitigates risk by ensuring that
users are only able to access what they need to get their job done, and no more.
THE ls -l COMMAND
The ls -l command gives you a long list of the files and directories in your current working
directory. Each item in the list contains seven columns, three of which display permission
information. The contents of the columns are described in the following table.
• The first character indicates the type of file; d for directory and hyphen ( - ) for file.
• Characters at the second, third, and fourth positions denote owner permissions.
• Characters at the fifth, sixth, and seventh positions denote group permissions.
• Characters at the eight, ninth, and tenth positions denote other permissions.
• The final character indicates the access method for the file; period (.) for SELinux security
context and plus (+) for any other combination of alternative access methods.
SYNTAX
The syntax of the chmod command is chmod [options] {mode} {file/ directory name}
Option Used To
SYNTAX
In symbolic mode, the syntax of the chmod command is:
chmod {access context}{operators}{permission attributes} {file/directory names}
As an example, to add read and write permissions to myfile for the owner and the group:
chmod u+rw,g+rw myfile
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.
SYNTAX
The syntax of the umask command is umask {number}
OWNERSHIP
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.
SYNTAX
The syntax of the chgrp command is chgrp {group name} {file/ directory name}
SPECIAL PERMISSIONS
Special permissions are used when normal permissions become inadequate. With special
permissions, less privileged users are allowed to execute a file by assuming the privileges of the
file's owner or group This enables the user to temporarily take on these higher level privileges
in a limited context.
SGID, or setgid, is the permission that allows a user to have similar permissions as the group
owner of the file. In addition to files, SGID can also be set on directories. Any subdirectories
created in this directory will automatically inherit the SGID permission. Likewise, all new files
and subdirectories created in this directory will inherit the directory's group ID, rather than the
group ID of the user who created the object. This inheritance is useful because users in a
shared environment don't need to change their group when they create objects in the
directory. Note that the SGID permission is not applied to existing objects in the directory, nor
is it applied to objects that are moved from other locations into the directory.
SUID and SGID are both set using the chmod command, and you can do so using either
symbolic mode or absolute mode. When using ls -al to see permissions, the execute permission
for the owner will appear as s for the SUID, and the execute permission for the group will
appear as s for the SGID.
Note the last three bits in absolute mode are whatever standard permissions you choose.
The following is the syntax for setting the SGID on a directory, using symbolic and absolute
mode, respectively:
chmod g+s {directory names}
chmod 2### {directory names}
Removing the SUID and SGID is as simple as using the - (minus) operator in symbolic mode, or
setting the first permission bit to 0 in absolute mode.
SYNTAX
The syntax for setting the sticky bit is as follows, using symbolic mode and absolute mode,
respectively:
chmod +t {directory names}
chmod 1### {directory names}
As with SUID/SGID, use - or 0 to clear the sticky bit.
The above table describes some of the options of the lsattr command.
SYNTAX
The syntax of the lsattr command is lsattr [options] {file/ directory names}
The above table describes some of the options of the chattr command.
SYNTAX
The syntax of the chattr command is chattr [-R] [-v {version}] [+-{attributes}] {file/directory
names}
SYNTAX
The syntax of the setfacl command is setfacl [-bR] [-mx {acl_spec}] {file/directory names}
ACL SPECIFICATION
The ACL specification can be formatted in one of several ways:
• When working with users, the format is u:{user name}:{permissions}
• When working with groups, the format is g:{group name}:{permissions}
EXAMPLE
The following is an example of modifying the ACL on a directory where the user http is given
read access:
setfacl -m u:http:r-- /home/directory
TROUBLESHOOTING
Troubleshooting is the recognition, diagnosis, and resolution of problems. Troubleshooting
begins with the identification of a problem, and it does not end until services have been
restored and the problem no longer adversely affects users. Troubleshooting can take many
forms, but all approaches have the same goal: to solve a problem efficiently with a minimal
interruption of service.
It may also be beneficial to list all of the members of a group so you identify which accounts to
add or remove as necessary. However, there is not necessarily one simple command that is
universal to Linux distributions that can accomplish this. You can search the /etc/group file for
the desired group, but this only displays groups in the standard database (i.e., not other
authentication methods), and it doesn't show users whose primary group is the group you're
searching for. The lid and libuser-lid commands are pre-installed on some distributions and can
retrieve all members of a group, including members whose primary group is the group being
searched for. The getent command, available on some distributions, enables you to retrieve
group members of non-standard authentication methods.
A file system by itself does not interpret the data contained in files because this task is handled
by specific applications. File systems vary depending on several parameters, such as the
purpose of the file systems, the information they store about individual files, the way they store
data, and the data security mechanisms they implement.
NTFS
The New Technology File System (NTFS) is a proprietary file system created by Microsoft® as
the primary file system for Windows®. NTFS provides many enhanced features over FAT,
including file- and folder-level security, file encryption, drive compression, and scalability to
very large drives and files.
Linux does not support NTFS by default; however, a utility called NTFS-3G can enable support
for NTFS on Linux systems.
Each inode on a file system is identified by a unique integer called an inode number. Whenever
the system or an application tries to access a file, it searches for the appropriate inode number
in a data structure called an inode table. The inode table maps an inode number to its
corresponding file or directory name.
Some file systems set a maximum number of inodes when that file system is created, usually by
considering the overall size of the file system. The total number of files and directories cannot
exceed this inode maximum. However, some file system types, like XFS, use a dynamic inode
allocation system that scales as a percentage of the file system's capacity. In other words, these
file systems do not set a strict inode limit.
EXAMPLES
Examples of real file systems on a Linux system can include xfs, ext4, and several other types.
Examples of virtual file systems can include proc, which contains system information during
runtime; devtmpfs, which contains device nodes loaded by the kernel during system
initialization; debugfs, which contains information useful in debugging the Linux kernel; and
many more.
SYNTAX
The syntax for setting ext# file system labels is e2label /dev/{device name}{partition number}
{label name}
The syntax for setting XFS file system labels is xfs_admin -L {label name} /dev/{device
name}{partition number}
Partitions are identified using a partition table, which is stored in one or more areas of the
drive. The size of each partition can vary but cannot exceed the total free space of the storage
drive.
Most operating systems, including Linux, use drive partitions. Data of different types can be
stored in separate locations on the drive, such as separating system files from user-accessible
files.
Option Used To
-b {sector size} Specify the number of drive sectors.
Option Used To
d Remove a partition.
SYNTAX
The syntax of the parted command is parted [options] {device name}
After creating a partition with fdisk, you cannot add a file system to that partition unless the
kernel can read it from the partition table. You might receive an error like "Re-reading the
partition table failed" during the fdisk operation. Rebooting the machine updates the table, or
you can issue partprobe instead to update the table without a reboot.
The partprobe command comes packaged with the GNU parted utility.
SYNTAX
The syntax of the partprobe utility is partprobe [options] [device name]
SYNTAX
One syntax option of the mkfs command is mkfs [options] {device name}
Field Description
Device/partition name Name of device/file system to mount.
Default mount point Where to mount file system.
File system type Type of file system used by device/partition.
Mount options Values activated when file system is mounted.
dump options Indicates if dump should back up file system.
fsck options Order in which fsck should check file system.
File system type Specifies the type of file system used by the device or partition.
Specifies a set of comma-separated options that will be activated
Mount options
when the file system is mounted.
Indicates if the dump utility should back up the file system. Usually,
dump options zero is specified as the dump option to indicate that dump can
ignore the file system.
fsck options Specifies the order in which the fsck utility should check file systems.
When you manage partitions and other device information, for the most part, you'll use this
naming convention to refer to those devices.
DEVICE MAPPING
Thus far, you've worked with physical storage devices, also called physical volumes. However,
there is a way to further abstract these devices into virtual storage devices— a process called
device mapping. In Linux, the device mapper creates the virtual device and passes data from
that virtual device to one or more physical devices.
Several Linux applications leverage the device mapper to perform various tasks. For example,
volume encryption and integrity checking services use device mapper to act upon data that is
transmitted between physical and virtual devices.
DM-MULTIPATH
DM-Multipath is a feature of the Linux kernel that provides redundancy and improved
performance for block storage devices. It leverages the device mapper to support multiple I/O
paths (connection interfaces) between the CPU and the storage devices. If one path fails, DM-
Multipath will switch to one of the other paths that remain, keeping the storage device
available for reading and writing. The multipath-tools package enables you to manage DM-
Multipath for storage devices, and the typical configuration file is located at
/etc/multipath.conf
One potential downside to LVM is that the initial setup can be somewhat complex.
In some cases, this directory may just include links to the actual logical volume location.
Tool Used To
pvscan Scan for all physical devices that are being used as physical volumes.
Tool Used To
Tool Used To
vgrename Rename a volume group.
vgreduce Remove physical volumes from a volume group to reduce its size.
vgextend Add physical volumes to volume groups.
vgmerge Merge two volume groups.
vgsplit Split a volume group into two.
vgremove Remove volume groups.
Tool Used To
lvscan Scan all physical devices for logical volumes.
lvcreate Create logical volumes in a volume group.
lvdisplay List attributes of logical volumes.
lvchange Change attributes of logical volumes.
lvs Display information about logical volumes.
Tool Used To
lvrename Rename logical volumes.
lvreduce Reduce the size of logical volumes.
lvextend Extend the size of logical volumes.
lvresize Resize logical volumes.
lvremove Remove logical volumes.
MOUNT POINTS
A mount point is an access point to information stored on a local or remote storage device. The
mount point is typically an empty directory on which a file system is loaded, or mounted, to
make the file system accessible to users. If the directory already has content, the content
becomes invisible to the users until the mounted file system is unmounted.
SYNTAX
The syntax of the mount command is mount [options] {device name} {mount point}
Option Used To
auto Specify that the device has to be mounted automatically.
noauto Specify that the device should not be mounted automatically
nouser Specify that only the root user can mount a device or a file system.
user Specify that all users can mount a device or a file system.
exec Allow binaries in a file system to be executed.
Option Used To
noexec Prevent binaries in a file system from being executed.
ro Mount a file system as read-only.
rw Mount a file system with read and write permissions.
Specify that input and output operations in a file system should be
sync
done synchronously.
Specify that input and output operations in a file system should be
async
done asynchronously.
SYNTAX
The syntax of the umount command is umount [options] {mount point}
SYNTAX
The syntax of the lsblk command is lsblk [options] [device name]
SYNTAX
The syntax of the blkid command is blkid [options] [device name]
SYNTAX
The syntax of the fsck command is fsck [options] {device/file system name}
SYNTAX
The syntax of the resize2fs command is resize2fs [options] {device/file system name} [desired
size]
SYNTAX
The syntax of the tune2fs command is tune2fs [options] {device/ file system name}
Option Used To
-x Print a detailed report about block numbers in the file system.
Force the utility to display the file system status irrespective of the
-f
file system flags.
Display file system data from an image file created using the
-i
e2image command.
Tool Used To
Display details about the XFS file system, including its block
xfs_info
information.
Change the parameters of an XFS file system, including its label and
xfs_admin
UUID.
xfs_metadump Copy the superblock metadata of the XFS file system to a file.
xfs_growfs Expand the XFS file system to fill the drive size.
xfs_copy Copy the contents of the XFS file system to another location.
TYPES OF FILES
Linux contains regular files that include text files, executable files or programs, input for
programs, and output from programs. Besides these, the Linux file system consists of other
types of files, as described in the following table.
Subirectory Description
/usr/bin Includes executable programs that can be executed by all users.
/usr/local Includes custom build applications that are stored here by default.
Includes object libraries and internal binaries that are needed by the
/usr/lib
executable programs.
Serves the same purpose as /usr/lib, except that it is meant only for 64-bit
/usr/lib64
systems.
Includes read-only architecture independent files. These files can be shared
/usr/share
among different architectures of an operating system.
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.
In many shells, including KornShell, C shell, and Bash, the Plde character ( )̃ represents your
home directory.
Remember, you can enter pwd to identify your current working directory.
You can refer to a particular file by providing a path to the specific directory that contains the
file.
For example, the home directory jsmith contains a subdirectory, work, which contains a file
named mywork. To refer to that file, use the following path name:
/home/jsmith/work/mywork. Notice that the forward slash (/) character is used to separate
items in the path. The slash that precedes home represents the root directory, from which the
path to the file mywork begins.
EXAMPLES
The following examples show accessing the same locaPon using absolute and relaPve paths,
respecPvely.
Command Used To
Traverse the directory structure using absolute or relative paths to
cd
change your current working directory.
List the files and directories in the current working directory or the
ls relative/absolute path you specify. In long listing format (-l), the first
bit indicates the type of file.
SYNTAX
The syntax of the du and df commands is du/df [options] [object names]
Although the kernel handles scheduling, you can actually configure the scheduler with different
behavior types. Some behaviors are more appropriate than others in certain situations, and you
may find that setting a new type increases read/write speeds. Changing the scheduler is
typically done during the troubleshooting process in order to finely tune storage performance
when every bit of that performance matters.
Note that this sets the scheduler for runtime only; the setting will revert upon reboot. To
persist your changes, you must modify the system's boot loader configuration.
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
I/O load between the available devices.
SYNTAX
The syntax of the iostat command is iostat [options] [device names]
Consider using ioping to troubleshoot latency issues with a storage devices, especially if you
believe your read and/or write speeds are slower than they should be.
Option Used To
-c {count} Specify the number of I/O requests to perform before stopping.
Set the minimum valid request time. Requests faster than this are
-t {time}
ignored.
Set the maximum valid request time. Requests slower than this are
-T {time}
ignored.
QUOTA ACTIVATION
Before you can use these commands, you must actually activate user and/or group quotas on
the file system. You can do this by editing the fstab file to add the options usrquota and
grpquota to the relevant file system.
XFS QUOTAS
You can use the xfs_admin utility to configure quotas on XFS file systems. This utility can run in
both interactive and non-interactive mode. When run noninteractively, use the -c option to
specify which commands to run, and the -x option to enable expert mode, which is required for
most administrative tasks. Tasks include setting limits on writing blocks and inodes, setting
warning limits, generating quota reports, and more.
repquota -u {user name} Display the quota report for a particular user.
warnquota -u Check if users are not exceeding the allotted quota limit.
warnquota -g Check if groups are not exceeding the allotted quota limit.
If a user claims they cannot create a file, verify that they have the appropriate permissions for
the directory. From there, you might check to ensure the storage area is available (mounted
partitions, both local and network), and that there is free space on the destination storage
location. After those more simple steps, verify that the inode pool has not been exhausted by
using the df -i command. If the inode pool has been exhausted, you'll need investigate the
affected file system to see if it contains many unnecessary files, like temporary files, and delete
them with the rm command.
In the event that a storage location appears to be unavailable, start your troubleshooting by
verifying the physical connection for the storage device. From there, you would verify whether
the storage device is recognized by the system—see the /dev/ and /proc/ directories for that
information. You should also check configuration files for errors, including the /etc/fstab file.
This is also true if you're mounting drives from network servers, such as NFS or Samba. Finally,
you can consider using tools like fsck, the XFS toolset, or the ext4 toolset.
TEXT EDITORS
A text editor is an application that enables you to view, create, or modify the contents of text
files. Text editors were originally created to write programs in source code, but are now used to
edit a wide variety of text-based files. Various types of text editors are compatible with Linux.
However, text editors do not always support the formatting options that word processors
provide. Text editors may work either in the CLI or GUI, and may have different modes of
operation.
Text editors are important because, in Linux, most configuration components are text files:
system configuration, network configuration, kernel configuration, shell environment
configuration, etc. In the CLI, you'll be configuring most of these components by opening the
relevant files in a text editor and adjusting some lines of text. So, being comfortable with a text
editor is essential.
A visual text editor that was originally created for Unix®, and was
vi
later cloned into FOSS versions.
Emacs A flexible, powerful, and popular text editor used in Linux and Unix.
Key Function
i Switches to insert mode and inserts text to left of cursor.
A Switches to insert mode and adds text at end of line.
I Switches to insert mode and inserts text at beginning of line.
o Switches to insert mode and inserts text on new line below cursor.
O Switches to insert mode and inserts text on new line above cursor.
v Switches to visual mode to enable selection, one character at a time.
V Switches to visual mode to enable selection, one line at a time.
: Switches to execute mode to enable users to enter commands.
Esc Returns to command mode.
Despite these advantages, nano lacks many of the features that make Vim so powerful, like
split screen, text completion, syntax coloring, and more.
NAVIGATION
Like other text editors, you can navigate in nano using the arrow keys, Page Up, Page Down,
Home, etc. If you are missing these keys, nano also provides shortcuts for them, e.g., Ctrl+V to
navigate to the next page and Ctrl+Y to navigate to the previous page.
COPYING TEXT
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.
The -type option enables you to specify the type of object you're looking for, such as d for
directory or f for file. The -name option is where you specify the name of the object you're
looking for. The following example searches a user's home directory (and all subdirectories) for
all files named 2019_report:
SYNTAX
The syntax of the find command is find [options] {search locations} {search criteria} [actions]
Option Used To
-print Displays the location of the files found.
-exec Executes the command that follows.
-ok Executes the command that follows interactively.
-delete Deletes files found.
-fprint Stores results in the target file.
The which command can therefore help you locate where a program has been installed in case
you need to modify this. It can also help you identify which version of a command you're using
if there are multiple binaries of the command stored in different locations, one of which may
be more ideal. By identifying where a command is running from, you can troubleshoot
unexpected behavior from that command.
SYNTAX
The syntax of the which command is which [options] {program names}
Where /bin/ls indicates the location of the ls command and /usr/ share/man/man1/ls.1.gz
/usr/share/man/man1p/ls.1p.gz indicates the location of the man pages for the ls command.
Option Used To
-b Search only for binaries.
-m Search only for manual sections.
-s Search only for sources.
-u Search for unusual entries.
SYNTAX
The syntax of the cat command is cat [options] {file names}
Option Used To
-e Exit the program the second time it reaches the end of the file.
-E Exit the program the first time it reaches the end of the file.
-i Ignore case in searches.
-n Suppress line numbers.
NAVIGATION
Navigation in less uses many of the same commands you've seen before, like the arrow keys to
scroll line-by-line and Page Up and Page Down to scroll by page. You can also use / to search a
file for a particular text string, and press n and N to move to the next or previous instance of
the searched string, respectively. Press q to quit the program.
SYNTAX
The syntax of the cp command is cp [options] {file/directory name to copy} {file/directory
name destination}
For example, to copy the ~/myfiles directory and its contents to /opt/myfiles:
cp -R ~/myfiles /opt/myfiles
SYNTAX
The syntax of the mv command is mv [options] {file/directory name to move} {file/directory
name destination}
For renaming purposes, the syntax is mv [options] {old file/ directory name} {new
file/directory name}
SYNTAX
The syntax of the touch command is touch {file names}
SYNTAX
The syntax of the rm command is rm [options] {file/directory names}
For example, to remove the ~/myfiles directory and its contents: rm -R ~/myfiles
SYNTAX
The syntax of the ls command is ls [options] [file/directory names]
ls COLORS
In the Bash shell, when you execute the ls command, you may have noticed that the results
sometimes appear in different colors. These colors distinguish different types of files. By
default, some of the colors are:
• Default color: Normal/text file
• Blue: Directory
• Sky blue: Symbolic link or audio file
• Green: Executable file
• Yellow with black background: Device
• Pink: Image file
• Red: Archive file
• Red with black background: Broken link
SYNTAX
The syntax of the mkdir and rmdir commands is mkdir/rmdir {directory names}
The printf command also supports conversion characters, which use a percent sign (%) to
indicate when they are being used. Conversion characters are typically used in scripts to change
the output of a variable, like dictating the number of decimal places to print after a precise
calculation.
SYNTAX
The syntax of the tr command is tr {character 1} {character 2} where {character 1} is the
character to be replaced.
wc COMMAND OPTIONS
The wc command provides various options that enable you to specify the nature of the output.
Option Used To
-c Display the byte count.
-m Display the character count.
-l Display the newline count.
-w Display the word count.
Option Used To
-k{column numbers} Specify field values. For example, -k2 indicates the second field.
-n Compare and sort lines based on the string numerical value.
Sort fields in descending order. By default, the fields are sorted in
-r
ascending order.
-t{delimiter} Separate one field from another.
SYNTAX
The syntax of the sort command is sort [options] {file names}
Option Used To
-c Specify the number of the character to cut from each line.
-d{delimiter} Separate one field from another.
Specify the field numbers to cut on as separated by the delimiter.
-f{field numbers} For example, -f2 indicates the field between the first and second
instances of the delimiter.
-s Suppress a line if the delimiter is not found
SYNTAX
The syntax of the cut command is cut [options] {file names}
The less than symbol (<) with a line after it means that line should be removed from the first
file because it doesn't appear in the second. The greater than symbol (>) with a line after it
means that line should be added from the second file. In addition, the diff command also
denotes the line numbers for each file that would be affected by deletion, addition, and change
operations.
Option Used To
-b Ignore spacing differences.
-i Ignore case differences.
-t Expand tab characters in output lines.
-w Ignore spacing differences and tabs.
-c Display a list of differences with three lines of context.
Output results in unified mode, which presents a more streamlined
-u
format.
The awk command can be used to process text files in a variety of ways, such as extracting text
matching a certain pattern; deleting text matching a certain pattern; adding text matching a
certain pattern; and much more.
SYNTAX
The syntax of the awk command is awk [options] ['patterns {actions}'] {file names}
Addresses tell sed to act only on certain lines or to act only on text that matches a given regular
expression pattern. They are optional. Addresses are followed by the action to be performed
when a match is found. The last argument is the name of the input file. The option, address,
and action parameters are typically enclosed within single quotation marks.
Some of the common command options and their uses are given in the following table.
Option Used To
d Delete the lines that match a specific pattern or line number.
-n, p Print only the lines that contain the pattern.
s Substitute the first occurrence of the string in the file.
Globally substitute the original string with the replacement string for
s, g
each occurrence in the file.
SYNTAX
The syntax of the ln command is ln [options] {target name} [link name]
ln COMMAND OPTIONS
The ln command has various options. Some of the frequently used options are given in the
following table.
Option Used To
--backup Back up existing destination files.
-f Remove existing destination files.
-s Make symbolic links instead of hard links.
-i Prompt to remove destination files.
-v Print the name of a file before linking.
EXAMPLES
The following is an example of creating a hard link using the ln command, where /
backup/backup-report is the target of the link, and ~/backup-report is the link itself:
ln /backup/backup-report ~/backup-report
The following is an example of the same, but creating a symbolic link instead of a hard link:
ln -s /backup/backup-report ~/backup-report
TEXT STREAMS
A text stream is a sequence of one or more lines of text that applications can leverage to read
from or write to a particular device or system component. This enables the application to
interface with components like the CLI, files, network sockets, and more, while hiding those
components' details from the application.
In most Linux shells, there are three types of streams: standard input, standard output, and
standard error.
PIPING EXAMPLE
The ls -l | grep audit command mentioned earlier that 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.
SYNTAX
The general syntax of the xargs command is command [options] [arguments] | xargs [options]
{command}
The find command searches for all files in /foo that have a .pdf extension, then pipes the result
to the xargs command. Because the results are delimited by a space, the xargs command will
execute the rm command for each file in the results— removing all PDF files in the directory.
When used with the -a option, tee appends the output to each output file instead of
overwriting it.
SYNTAX
The general syntax of the tee command is command [options] [arguments] | tee [options]
{file names}
ls -l | tee listing.txt
KERNEL
The kernel is the core of an operating system. All other components rely on it. The kernel
manages file system access, memory, processes, devices, and resource allocation on a system.
The kernel also controls all the hardware devices plugged into the system. It is one of the first
elements to be loaded on startup and remains in the main memory during the computer's
operation. The kernel also contains system-level commands and other functions that are
normally hidden from users.
Software running in user space is able to access resources provided by kernel space through the
use of system calls. These calls provide a user space application with the resources it needs to
perform a task. For example, an application might issue a system call to the kernel so that it can
leverage input/output (I/O) services that write data to a storage device.
The split between these two memory regions is useful because it promotes greater stability and
security. Software in one space cannot necessarily interfere with software in the other.
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 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.
One important quality of the Linux kernel is its modularity. This enables users to configure and
extend kernel functionality to meet their needs.
The Linux kernel is continually updated by creator Linus Torvalds and many other volunteers.
Each new version of the kernel is given a kernel version number to distinguish it from past and
future versions. The current naming convention for kernel versions is major.minor where major
is the major version number and minor is the minor version number. For example, version 4.19
was released in October 2018.
Handles system calls sent from user applications to the kernel. This enables user space
System Call applications to request services from the kernel space, like processing time and memory
Interface allocation.
(SCI) This layer also enables the kernel to schedule and process system calls and manage multiple
system calls simultaneously.
Handles different processes by allocating separate execution space on the processor and
Process ensuring that the running of one process does not interfere with other processes.
management Through scheduling, the kernel implements sharing of processor time for executing multiple
processes.
Manages the computer's memory, which is one of the complex tasks performed by the kernel.
Like processor sharing, the system's memory also needs to be shared among different user space
Memory resources.
management The kernel maps or allocates the available memory to applications or programs on request and
frees the memory automatically when the execution of the programs is complete, so that it can
be allocated to other programs.
Manages the filesystem, which involves storing, organizing, and tracking files and data on a
computer.
File system
The kernel also supports a virtual file system (VFS) that provides an abstract view of the
management
underlying data that is organized under complex structures, so that it appears to be a single
structure.
Manages devices by controlling device access and interfacing between user applications and
Device hardware devices of the computer.
management When a user space application sends a system call, the kernel reads the request and passes it on
to the drivers that manage the activities of that particular device.
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.
Command Used To
Display the currently loaded kernel modules, their sizes, usage
lsmod
details, and their dependent modules.
Display information about a particular kernel module, such as the
file name of the module, license, description, author's name,
modinfo module version number, dependent modules, and other parameters
or attributes. The syntax of this command is modinfo [options]
{module name}
Install a module into the currently running kernel. This command
insmod inserts only the specified module and does not insert any dependent
modules. The syntax of this command is insmod {module name}
Remove a module from the currently running kernel. The syntax of
rmmod
this command is rmmod {module name}
SYNTAX
The syntax of the modprobe command is modprobe [options] [module names]
Option Used To
-f Force the module to be inserted or removed.
Conduct a dry run, i.e., output results without actually executing
-n
operations.
-s Print errors to the system log (syslog) rather than stderr.
-v Enable verbose mode.
SYNTAX
The syntax of the depmod command is depmod [options]
MORE ON SYMBOLS
Symbols provide a way for modules to call upon the functions or other programming objects of
other modules. For example, module1 has a C function named foo() that performs some useful
task. Another module, module2, wants to use foo() when it is linked to the kernel, rather than
incorporate that routine in its own code. This is only possible if module1 explicitly exports foo()
for external use. It does this by using EXPORT_SYMBOL() or one of its variants on the function.
The foo() function then becomes available as a symbol for any other module in the kernel to
leverage.
Command Used To
Specify an alternative name for a module with a
alias {alternative name} {module name}
long name.
Ignore internal aliases, which occur when modules
blacklist {module name}
define their own aliases.
Run the specified command without inserting the
install {module name} {command}
module into the kernel.
The /proc/sys/ directory lists the parameters that you can configure on your system. Like the
directories containing kernel modules, this /proc/sys/ directory is divided into several
categories, including the following.
Directory Includes Parameters Related To
crypto Encryption and other cryptographic services.
debug Debugging the kernel.
dev Specific hardware devices.
fs File system data.
kernel Miscellaneous kernel functionality.
net Networking functionality.
user User space limitations.
vm Virtual memory management.
Option Used To
-a Display all parameters and their current values.
-w {parameter}={value} Set a parameter value.
Load sysctl settings from the specified file, or /etc/sysctl.conf if no
-p[file name]
file name is provided.
-e Ignore errors about unknown keys.
Apply a command to parameters matching a given pattern, using
-r {pattern}
extended regular expressions.
Option Used To
Options passed to the kernel by the boot loader at boot time,
/proc/cmdline
such as mounting the kernel as read-only.
CPU information, such as its architecture, name, clock speed,
/proc/cpuinfo
cache size, and more.
A list of character and block device drivers loaded into the
/proc/devices
currently running kernel.
A list of file systems types that are supported by the kernel, as
/proc/filesystems
well as if any are currently mounted.
Information about RAM usage, including total memory, free
/proc/meminfo
memory, and much more.
Information about modules currently installed on the system. An
/proc/modules
alternative to the lsmod command.
/proc/stat Various statistics about the system since it was last rebooted.
In addition to using the dmesg command, you can also access the message buffer from the
/var/log/dmesg file. In either case, you can leverage dmesg to look for potential issues with
kernel components or to validate that certain modules are being loaded.
BOOTING
Booting is the process of starting or restarting a computer and loading an operating system for
the user to access. In the boot process, a booting environment reads a small program that is
stored in read-only memory (ROM). This program then executes various operations in RAM that
bootstrap the operating system and make it available for use.
Linux, like other operating systems, must be booted for it to function. There are various options
associated with the boot process that you can configure, if necessary.
Boot loaders are able to protect the boot process with a password to prevent unauthorized
booting of the system. In addition, boot loaders can load more than one operating system into
the computer's memory, but the user needs to select the desired operating system to use
during boot.
Component Description
PASSWORD PROTECTION
One security feature that both BIOS and UEFI include is the ability to set a password. If this
password is not provided at boot time, the system will not boot. Since BIOS/UEFI firmware
differs between hardware manufacturer, the process of setting this password is not consistent.
However, most firmware places this password protection option in a "Security" or "Password"
section.
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.
• MBR-partitioned drives can have a maximum of four primary partitions.
• The boot data is stored in one sector, which increases the risk of corruption
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.
RAW PARTITION
Other than formatting a partition as MBR or GPT, you can also format a partition as raw. A raw
partition enables users and applications to read from and write to a block storage device
directly, without using the system cache. This is useful in situations where software like a
database management system (DBMS) has its own caching mechanism. The DBMS has greater
control over I/O caching in a raw partition and can bypass the caching normally done by the
kernel.
The initrd is useful because there are many potential variables that can complicate the boot
process. For example, the kernel needs to find and load the necessary device driver modules,
as well as the actual root file system itself. There's also the possibility that the root file system
uses one of several advanced storage methods, like LVM or NFS, which have different mount
requirements than a standard partition. Rather than hardcode all of this behavior in the kernel
and introduce bloat, the initrd's temporary root file system can handle these tasks.
Option Used To
SYNTAX
The syntax of the mkinitrd command is mkinitrd [options] {initrd image name} {kernel
version}
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)
Because of these improvements, GRUB 2 has become the default boot loader on almost all
modern Linux distributions.
SYNTAX
The syntax of the grub2-mkconfig command is grub2-mkconfig [-o {file name}]
Localizing a Linux system is important for organizations that provide Linux services to personnel
and customers all over the world. An administrator in Japan will likely be more comfortable
working on a Linux server if that server is localized to use the Japanese language, rather than
English. Working with the local time and with a compatible keyboard will also enhance the user
experience for international users.
The individual files are not raw text files, but are special files used by the system. One way to
change the system's time zone is by creating a symbolic link to one of these individual time
zone files to the /etc/localtime file.
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.
FORMATTING OPTIONS
The following table lists some of the formatting options available.
Formatting Option Prints
%A The full weekday name.
%B The full month name.
%F The date in YYYY-MM-DD format.
%H The hour in 24-hour format.
%I The hour in 12-hour format.
%j The day of the year.
%S Seconds.
%V The week of the year.
%x The date representation based on the locale.
%X The time representation based on the locale.
%Y The year.
Subcommand Used To
Show the current date and time information, including local time,
status universal time, RTC time, time zone, and more. This is the same as
issuing timedatectl by itself.
Set the system's time to the time provided. The format should be as
set-time
follows: 2018-10-31 15:03:16
Set the system's time zone to the time zone provided. The zone is in
set-timezone
the format specified by the /usr/share/ zoneinfo structure.
List all available time zones in the format specified by the
list-timezones
/usr/share/zoneinfo structure.
Enable or disable synchronization with a Network Time Protocol
set-ntp {0|1}
(NTP) server.
Option Used To
Execute the operation on the remote host specified by IP address or
-H {remote host}
hostname.
Execute the operation on the remote host specified by IP address or
--no-ask-password
hostname.
Synchronize the local (system) clock based on the hardware clock
--adjust-system-clock
when setting the hardware clock.
-M {local container} Execute the operation on a local container.
CLOCK TYPES
The timedatectl command exposes three different clocks that the system can use:
• The local clock. This clock reflects the current time in the system's locale (i.e., the time
zone).
• The universal time. This clock reflects the time irrespective of the local time zone. It uses the
international standard Coordinated Universal Time (UTC), which is the same as Greenwich
Mean Time (GMT).
SYNTAX
The syntax of the hwclock command is hwclock [options]
Like the timedatectl command, the localectl command offers various subcommands for
managing the system locale and keyboard layout.
Subcommand Used To
Show the current locale and keyboard layout. This is the same as issuing
status
localectl by itself.
set-locale Set the system locale to the locale provided.
list-locales List all available locales on the system.
set-keymap Set the keyboard layout to the provided layout.
list-keymaps List all available keyboard layouts on the system.
Option Used To
Execute the operation on the remote host specified by IP address or
-H {remote host}
hostname.
Prevent the user from being asked to authenticate when performing a
--no-ask-password
privileged task.
--no-pager Prevent the output from being piped into a paging utility.
Prevent a keymap change for the console from also being applied to the
--no-convert
X display server, and vice versa.
In many systems, the default encoding is UTF-8 using the Unicode character set. For example,
the capital letter C is associated with the positional number U+0043 in Unicode. UTF-8 encodes
this number (43) in binary as 01000011. However, not all software uses this encoding. For
example, some software might default to an older encoding standard like ASCII. If you've ever
opened a text file and seen garbled and unreadable characters and symbols, then the text
editor is probably assuming the wrong encoding.
In Linux, the locale settings determine what encoding scheme the system will use. The same
general locale may have different encoding options. For example, de_DE.utf8 and
de_DE.iso88591 both set Germany and the German language as the locale, but the former sets
the encoding as UTF-8 and the latter sets an ASCII encoding standard.
GUIs
A graphical user interface (GUI) enables users to interact with a system or application through
visual design elements rather than pure text as in a command-line interface (CLI). In Linux, a
GUI provides similar functionality to the GUIs of other operating systems like Windows® and
macOS®. Users can select icons that represent files, folders, and programs to open or modify
them; configure settings through menus; interact with applications through a windowed
interface; and work from a desktop environment.
As the name implies, display servers manage communications over a specific network- aware
protocol. This enables remote clients to access GUI elements of a Linux system, like specific
windows. However, the server can still provide its services to local clients.
Linux supports several different display servers. Two of the most prominent are implemented in
the X Window System and Wayland.
Like all display servers, the X server coordinates client input and application output to
determine how to draw elements on the screen. The X server also communicates with a
separate compositor. The compositor reads a memory buffer that each application writes to,
then uses the information in this buffer to combine each individual application window on the
screen so that multiple windows can appear at once. Whenever the X server receives an event
(e.g., a button was clicked and must now be highlighted), it must inform the compositor so that
it can re-composite the portion of the screen that is affected by the event.
Wayland was first released in 2008, and although X.Org Server still dominates in Linux
distributions, adoption of Wayland has been slowly increasing. For example, Fedora® started
using Wayland as its default display server starting with version 25, released in November of
2016.
Desktop environments implement the desktop metaphor, in which the user's monitor is treated
as if it were the top of a physical desk, where various objects are placed and accessible to the
person sitting at the desk. The primary structural element of a desktop metaphor is the
application window, and within each window there can exist various graphical elements like
buttons, icons, menus, toolbars, and more.
The client computer typically constructs the remote session in its own window, and, when that
window has focus, any input on the local client (e.g., a keystroke) gets translated and sent to
the remote desktop as if the keystroke were being performed on that system directly.
X FORWARDING
As you know, X (X11) is network-aware and can enable clients to access GUI elements over a
network. You can forward X traffic through an SSH tunnel in order to encrypt these
communications.
On Linux, there are two main methods that initialize a system: SysVinit and systemd. The
method that is active on your Linux system will affect how you manage services on that system.
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.
ENVIRONMENT VARIABLES
Unit files can also be used to set system environment variables/parameters, which are values
that are passed from a parent process to any child process it creates. By adding directives for an
environment variable, you can make it easier for a service or other unit to work with custom
values.
As an example, the rescue.service unit file sets the following Environment directive:
[Service]
Environment=HOME=/root
The HOME environment variable is therefore set to the root user's home directory, enabling
the rescue mode daemon to log in to the shell with that path as its home directory. When
configuring your own unit files, you could use a similar directive, perhaps supplying a different
path. You can also set any variable you want—not just HOME.
Target files include dependency information that enables these different modes of operation.
For example, graphical.target will boot the system into a GUI environment. It does this by
referencing other unit files like gdm.service (the GNOME Display Manager) that are required in
order to initialize the GUI and its related components.
SYNTAX
The syntax of the systemctl command is systemctl [options] [subcommand] [arguments]
Subcommand Used To
status {service} Retrieve service status.
enable {service} Enable service to start on boot.
disable {service} Disable service so it doesn't start on boot.
start {service} Activate service immediately.
stop {service} Deactivate service immediately.
restart {service} Restart service immediately.
set-default {target} Set default target for system to use on boot.
isolate {target} Force system to immediately change to target.
mask {unit file} Prevent unit file from being enabled or activated.
daemon-reload Reload daemon and all unit files.
Aside from systemd's improvements, one major difference between it and SysVinit is that
SysVinit has runlevels. Runlevels control the state of the operating system in much the same
way that systemd targets do; they determine what types of daemons should be running in
order to create a specific type of environment. In fact, systemd targets were created to map to
existing runlevels. Like with systemd targets, you can change a system's runlevel and set a
default.
SysVinit
systemd Target Description
Runlevel
0 poweroff.target Shuts down system.
SINGLE-USER MODE
Single-user mode boots the operating system into an environment where the superuser must
SYNTAX
The syntax of the telinit command is telinit [options] {runlevel}
id:rstate:action:process
The id is just a unique identifier for the entry; rstate defines what runlevels the entry applies
to; and action specifies one of several tasks that determine how SysVinit handles the command
defined in the process field.
Depending on the distribution, SysVinit scripts may instead be stored in /etc/rc.d/ or this
directory may contain symbolic links to the /etc/init.d/ directory.
SYNTAX
The syntax of the chkconfig command is chkconfig [options] [service] [subcommand]
The following are some subcommands and options that can be used with chkconfig to control
services.
Option Used To
{service} on Enable a service to be started on boot.
{service} off Disable a service so that it is no longer started on boot.
{service} reset Reset the status of a service.
--level {runlevel} Specify the runlevel in which to enable or disable a service.
Subcommand Used To
SYNTAX
The syntax of the service command is service [options] [service] [subcommand]
You can use pgrep to help you identify a process based on multiple factors when you don't
know its exact PID. Identifying the PID is typically the first step in managing the process.
SYNTAX
The syntax of the pgrep command is pgrep [options] {pattern}
SYNTAX
The syntax of the ps command is ps [options]
SYNTAX
The syntax of the top command is top [options]
Key Used To
Enter Refresh the status of all processes.
Shift+N Sort processes in the decreasing order of their PID.
M Sort processes by memory usage.
P Sort processes by CPU usage.
u Display processes belonging to the user specified at the prompt.
k Terminate the process for which you specify the PID.
r Renice the process for which you specify the PID.
q Exit the process list.
SYNTAX
The syntax of the systemd-analyze command is systemd-analyze [options] [subcommand]
SYNTAX
The syntax of the lsof command is lsof [options]
Processes are prioritized based on a number from -20 to 19, called a nice value or niceness
value. The lower the number, the higher the priority. A process with a nice value of -18 will be
more likely to be given CPU time than a process with a nice value of 15. A processes inherits a
nice value from its parent, and by default, that value is 0.
SYNTAX
The syntax of the nice command is nice [-n {nice value increment}] [command]
When you renice a process group with the -g option, it causes all processes in the process
group to have their nice value altered. When you renice a user with the -u option, it alters the
nice value of all processes owned by the user. By default, the processes affected are specified
by their PIDs.
SYNTAX
The syntax of the renice command is renice [-n {nice value}] [options] {identifier}
It is possible to run commands in the background, where they still execute but do not consume
the shell. You can use the fg (foreground) and the bg (background) commands to move the
process into view.
COMMAND SUMMARY
The following table summarizes the purpose of each command used in the previous example.
Option Used To
fg %{job ID} Bring a job to the foreground.
Ctrl+Z Halt a job temporarily so you can use the bg command.
bg %{job ID} Push a job to the background.
Start a command running in the background when added to the end
&
of a command.
SYNTAX
The syntax of the nohup command is nohup {command/script}
There are many different kill signals. Each signal has a name and one or more corresponding
number values; you can use either with the kill command. Some of the most common signals
are described in the above table.
EXAMPLES
The following are some examples of implementing kill signals. To terminate a process with ID
921 gracefully:
kill 15 921
Each logical processor core has its own entry. A CPU might support multithreading, which
performs multiple operations simultaneously on a single physical core. Logical cores represent
each possible thread. So, a CPU marketed as being a quad-core processor might have eight
logical cores.
Some useful fields in the /proc/cpuinfo file include:
processor —The number of the logical core, starting with 0.
vendor_id —The CPU manufacturer.
model name —The specific model of CPU.
cpu MHz —The logical core's clock speed, measured out to the thousandths decimal place.
cache size —The CPU's cache size.
flags —Characteristics about the CPU as well as supported features.
Most relevant to CPU troubleshooting, however, is the load average field. A CPU's load is
expressed as the number of processes that are either using or waiting to use the CPU. It can
also include the number of processes in the queue for storage I/O. Using uptime you can find
the average load over three different periods of time, from left to right in the output: the last 1
minute, the last 5 minutes, and the last 15 minutes.
You can use these values to determine when your CPU becomes overloaded, which may lead to
performance issues. For example, if you have 4 logical cores, and the load average in the last 15
minutes is 4.0, then your CPU was being used fully. If your load average were 8.0, then your
CPU would be 100% overloaded.
Like the uptime command, you can use sar to identify excessive load on the CPU. You're given
more details about when excessive usage occurs, as well as what might be causing that
excessive usage.
SYNTAX
The syntax of the sar command is sar [options]
SYNTAX
The syntax of the free command is free [options]
BUFFER/CACHE OUTPUT
Memory can be cached, meaning that it is stored temporarily so that the data it contains can be
accessed much quicker in the future. The Buffers field in /proc/meminfo indicates memory
that is assigned to a specific block device. This memory is used to cache file system metadata,
like directory contents, permissions, etc. The Cached memory is similar, but instead of storing
file metadata, it stores the actual contents of files. The free command combines these two
values together upon output.
free OPTIONS
There are several command options available for the free command.
Option Used To
Display memory in bytes, kilobytes, megabytes, gigabytes, and
-b, -k, -m, -g, -tera
terabytes, respectively.
-s {seconds} Update memory statistics at a delay of the specified seconds.
-o Disable the display of the buffered/cached information.
-t Display a total line that combines physical RAM with swap space.
-h Make the output more human-readable.
SYNTAX
The syntax of the vmstat command is vmstat [options] [delay [count]]
OUTPUT DELAY
It's recommended to supply vmstat with a delay for a more accurate report. For example,
vmstat 5 5 will run the command on a five-second delay for five intervals.
Although this mechanism is mostly automated by the kernel, you do have the ability to control
some of its behavior. You can mount the oom control group at the desired mount point. If, for
example, you want to designate a group of processes as the first to be killed, you can create a
directory at this mount point and create a tasks file in this directory that lists the PIDs of the
relevant processes. Then, create an oom.priority file with a high integer value like 256 to give
the processes a higher priority for the OOM killer. Or, to prevent the processes from being
killed entirely, give 0 as the priority value.
Option Used To
Verify that the device is free from bad sectors before mounting
-c
the swap space.
Set the page size to be used by the mkswap command. A page is a
-p chunk of memory that is copied to the storage device during the
swap process.
Activate the swap space using labels applied to partitions or file
-L {label}
systems.
Option Used To
• Identify the different types of devices that support the Linux OS.
• Configure devices.
• Monitor devices.
• Troubleshoot various issues having to do with hardware devices.
As you've seen, Linux has robust remote connection support, whether through a GUI with
remote desktop apps, or through a terminal with SSH. A thin client will typically have
fundamental I/O devices like a keyboard, mouse, and monitor connected to it. It may or may
not be running Linux, and if it is, it will typically be a lightweight distribution with very few
features available or permissible to the user. The server the client connects to will usually
construct a virtual environment so that the user can work in a sandbox, segmented from other
portions of the server or network. The server, like the client, may be running Linux or another
operating system.
When you connect a video/audio peripheral to a system running any OS, including Linux, you
need to be mindful of the connection types it uses and what types are available on the system.
Microphones and webcams commonly use USB, whereas USB is much less effective for
streaming video/audio output in real-time. Monitors, for example, are more likely to use
interfaces like HDMI and DisplayPort that can carry both video and audio signals with a high
degree of real-time performance. Some monitors may use older interfaces like DVI and VGA
that only carry video.
You can connect to a printer using one or more interfaces and methods. Most modern printers
offer local connection support through a USB interface. However, in office environments
especially, clients often connect to printers over a network. In this case, the printer may include
a Wi-Fi adapter, an Ethernet adapter, or both, so that the printer is identifiable on the LAN.
Multiple clients can therefore connect to and use the same printer at once. A Linux computer
can even function as a print management server that interfaces with one or more physical
printers.
In many cases, network adapters are built into a computer's motherboard. However, some
adapters can be added to the system on an expansion bus, or as an external peripheral that
connects through an interface like USB. A system can have more than one adapter; this is
especially common in servers and security systems like firewalls. In addition, each type of
network connection protocol requires its own type of adapter. A Wi-Fi adapter sends and
receives wireless signals in a WLAN, whereas an Ethernet adapter will include an Ethernet port
that you can plug a cable into to connect to a LAN.
GPIO pins are commonly found on single-board microcontrollers like Arduino and Raspberry Pi
devices. While these devices are often used by hobbyists and as a way to teach fundamental
computing concepts, they also have applications in the IoT space. Specialized Linux
distributions like Raspbian can be used to control GPIO functionality on single-board
microcontrollers through various programming libraries.
In the past, SATA was seen as a good solution for situations where capacity and cost were
paramount. SATA supports multiple-terabyte drives and is relatively cheap to manufacture.
However, its slower data transfer rate compared to alternative standards (6 gigabits per second)
made it less suitable for enterprise environments, and it was most commonly used for backup
purposes and in consumer storage. The most current revision of SATA (revision 3.2) combines
SATA with another bus technology called PCI Express, which allows it to supports a raw data
rate of up to 16 Gb/s—finally rivaling its competitors.
Traditionally, SCSI uses a parallel interface, which tends to cost more to manufacturer than a
serial interface. However, in the past, SCSI provided high transfer rates and therefore became
popular in enterprise storage arrays where speed was important. The Serial Attached SCSI
(SAS) standard was developed to apply a serial interface to SCSI technology. SAS offers greater
speeds than traditional SCSI—up to 24 Gb/s in the recent SAS-4—and supports higher-capacity
drives. The serial interface also supports a more reliable data transfer rate. SAS has become the
go-to technology for many enterprise storage environments.
When it comes to non-storage devices, there are many applications of PCIe. It's common for
video cards to connect using this interface, as well as expansion cards that add more ports like
USB and SATA for the system to use. In more recent years, PCIe has been used to connect SSDs
that leverage the Non-Volatile Memory Express (NVMe) interface, which is specifically designed
for integration with PCIe. NVMe SSDs are even faster than SSDs connected over SATA and SAS;
they will likely become a prominent force in enterprise storage.
Location Description
• Files representing info reported by kernel.
/proc/
• /proc/devices lists all character/block devices.
• Creates hierarchical view of device info.
/sys/
• /sys/devices/ includes files that expose device details.
• Device driver files.
/dev/ • Example: Mount block device through /dev/sda1
• /dev/mapper includes LVs, encrypted devices, etc.
• Config files for many components.
/etc/ • /etc/X11/ has files for configuring I/O devices impacting X.Org
Server.
Modern Linux distributions support hotplugging for many standard bus types, particular for
USB, FireWire, SATA, and other related technologies. Even expansion bus technology like PCIe
can support hotplugging.
Similar to writing rules for GRUB, you name this rule file in the format ##- name.rules where ##
determines its order in being executed by udev.
Rules files can also be placed in the /run/udev/rules.d/ directory. These also take
precedence over the system rules path. Rules in this path are volatile, meaning that
they will apply at runtime but will be lost in the event of a system reboot. Volatile
rules can be useful when you need to temporarily override a system rule without
actually making the change persist.
Subcommand Used To
Retrieve device information stored in the udev database, as well as
detailed device attributes from the /sys/ file system. For example, you
info
can view a device's vendor ID, product ID, serial number, and much
more.
Modify the running state of udev. For example, providing the --reload-
control rules option will ensure that udev is reading from any new rules files
you've added.
Execute rules that apply to any device that is currently plugged in. You
can also specify an action using the -c option, such as add, remove, or
trigger
change. As the names imply, these will trigger events where a device is
added, removed, or changed in the running kernel.
monitor Watch for events sent by the kernel or by a udev rule.
test Simulate a udev event running for a device, with results on output.
SYNTAX
The syntax of the udevadm command is udevadm [options] [subcommand] [arguments]
CUPS is designed for scheduling print jobs, processing administrative commands, and providing
printer status information to local and remote programs. CUPS provides a web-based interface
for configuring the service. Changes made through this interface modify the
/etc/cups/cupsd.conf and /etc/cups/cups-files.conf files.
SYNTAX
The syntax of the lpr command is lpr [options] [file names]
Option Used To
-E Force encryption when connecting to the server.
You can use the -v flag to see detailed information about each device, similar to using the
udevadm info command. You can also filter results by bus (-s) and by vendor/product (-d).
SYNTAX
The syntax of the lsusb command is lsusb [options]
SYNTAX
The syntax of the lspci command is lspci [options]
SYNTAX
The syntax of the lpq command is lpq [options]
Another example is the dmesg command. Recall that this prints all messages sent to the
kernel's message buffer after system boot, including messages sent by device drivers. If
hardware devices encounter errors in operation or are unable to load the expected modules
into the kernel, the output of dmesg might indicate so. Use this output to monitor for issues
related to device drivers and the underlying hardware they control.
To address the problem, make sure you can correctly identify the layout of the physical
keyboard—not just its overall design type (e.g., QWERTY vs. Dvorak), but its specific regional
layout. Even standard QWERTY keyboards designed with the same language in mind don't
always have the same layout; for example, American English keyboards contain keys in different
spots than British English keyboards. Once you've identified the physical layout of your
keyboard, use localectl status to verify the layout that the system is using. If it's not correct, list
the available keymaps, identify the correct one, then set it on the system. You may also need to
adjust the system language to ensure one-to-one accuracy.
Certain devices, when connected to a serial port, will request a console interface with the Linux
operating system. Linux will typically assign the port an interface at /dev/ttyS# where # is the
number of the console (starting with 0). In some cases, you may need to ensure that the
connected device is configured to automatically use one of these consoles. Also, by default,
only the root user is granted access to these serial consoles. You may need to change the
permissions on the relevant serial console using chmod to ensure that other users can work
with it.
For these issues, consult the printer's help manual and/or the manufacturer's website.
In other cases, however, you may be able to troubleshoot issues from your Linux client or
server. As always, ensure your specific printer is supported by Linux-compatible drivers, and
that those drivers are loaded. If you're trying to connect to your printer over a network but
can't, use network diagnostic tools like ping to ensure that your printer is identifiable on the
network and that it can be reached.
If you're using Linux as a print server in an office environment, the printer may become sluggish
or unresponsive if multiple users are trying to print to it. Use lpq to check the status of print
jobs; if any jobs are too large, or there are too many in the queue, you can use the lprm
command to stop a job with the job number you provide. For example, lprm 4 will remove job
4 from the queue. This will help clear up the queue and lighten the load on the printer.
However, some memory issues indicate a fault in the physical RAM modules or the
motherboard that RAM is slotted into. Like other operating systems, Linux has ways of
detecting these faults during operation. For example, system logs that record a "Machine Check
Exception" error message usually indicate an issue with RAM. The mcelog command can
retrieve and print these error messages for easier analysis. If the messages contain error-
correcting code (ECC) errors, one of the memory modules has probably failed.
To confirm RAM module failure, you can use utilities like MemTest, MemTest86+, and
memtester to perform a stress test on all RAM modules for several hours, reporting any errors
that are encountered.
Some of these issues can be addressed by ensuring that monitors and other display devices are
properly connected and are compatible with the system and user software.
Like other commands and files that retrieve device information, you can use lshw to identify
whether or not a device is recognized by the kernel, as well as to review a device's capabilities
and characteristics.
SYNTAX
The syntax of the lshw command is lshw [options]
DEVICE CLASSES
The output of lshw groups devices into one of several classes. You can filter the total results by
specifying a class with the -c option. For example, issuing lshw -c network will only output
details about network-class devices. To see a list of classes currently in use on your system,
enter lshw -short | sort -k2 to generate a non-detailed list of devices, sorted by the class
column.
SYNTAX
The syntax of the dmidecode command is dmidecode [options]
ABRT UTILITIES
ABRT runs as the abrtd daemon and can be configured using abrt-cli or abrt-gui, depending on
your system (and your own preference). You can use both
utilities to list problem data, view details about problem data, analyze and report on problem
data, and remove unnecessary reports.
TCP/IP
The networking process is governed by protocols. Much like human conversation, computer
network communications are managed by rules. These rules control how much information is
communicated at any given time, what addresses are used to represent nodes, how nodes take
turns communicating on the network, what error checking may exist, etc. Many families or
suites of protocols have existed over the years, but the only protocol suite of note today is
Transmission Control Protocol/ Internet Protocol (TCP/IP). This is the default protocol of the
Internet and most internal private networks.
The OSI Model also serves as a standard point of reference when communicating with other
network professionals. For example, you may be instructed to purchase a "Layer 2 switch" or to
troubleshoot a "Layer 3" problem. It serves as a common reference point for devices, and a
guide for developers creating network applications.
An understanding of the TCP/IP suite can aid in troubleshooting and network configuration. For
example, IP address support occurs in the IP layer, while application support occurs at the
application layer.
Identifier Description
Each network interface card (NIC) has a unique identity coded into
it that identifies that NIC on network segment. That code is
MAC address 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 IP address.
The IP address uniquely identifies the NIC in the network
environment.
IP address
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 that helps people
better understand what device they are working with. This
Hostname identity is often configured during the installation of the operating
system and is sometimes called the "computer name." Hostnames
are limited to 255 characters.
Device/Component Description
This device acts as a concentrator, centralizing all network
connections for a segment to a single device. Switches can be
Switch 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.
This device acts as a control point for communications between
network segments. Administrators can configure the router to
Router 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 cable 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
Media
common type of network cable. Other cable types include coaxial
(coax) and fiber optic. Wireless networks forego cables and can
transmit data over the air.
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.
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.
The 4.3 billion IPv4 addresses are divided into the following five classes
Class Start Addr. End Addr. Networks Hosts per Network Default Subnet Mask
A 0.0.0.0 127.0.0.0 126 16,777,214 255.0.0.0 or /8
B 128.0.0.0 191.255.0.0 16,384 65,534 255.255.0.0 or /16
C 192.0.0.0 223.255.255.0 2,097,152 254 255.255.255.0 or /24
D 224.0.0.0 239.255.255.255 N/A N/A N/A
E 240.0.0.0 255.255.255.255 N/A N/A N/A
The logical divisions of the network are referred to as subnets and are identified by a network
ID. This network ID is part of the IP address each node is using. All nodes in that subnet will
have the same network ID in their IP address. Each node will have a unique host ID within that
subnet. Recall that the subnet mask shows which part is the network ID and which part is the
host ID.
PUTTY
Microsoft Windows operating systems do not commonly use SSH, though it can be added to
them. One of the most common Windows SSH clients is called PuTTY, and it is an excellent tool
for those working with both Linux and Windows systems.
Two protocols are primarily used with web services: Hypertext Transfer Protocol (HTTP) uses
TCP port 80 and Hypertext Transfer Protocol Secure (HTTPS) uses TCP port 443.
Linux systems may be configured as DHCP servers, providing IP address configurations to other
systems, or as a DHCP client, leasing an IP address configuration from a DHCP server. Typically,
systems playing the role of server will have a static IP configuration, whereas client computers
will have a dynamic IP configuration. The DHCP service uses UDP port 67 and 68.
Linux systems can be configured as proxy servers. Linux is often a good choice for this role
because it can be run in a very lightweight configuration and is considered to be relatively
secure. One common example of a proxy service for Linux is Squid. Squid has existed for a very
long time and is frequently included with many Linux distributions.
One of the key functions of these logging services is to centralize log files from many Linux
servers to one. This makes them easier to archive for service-level agreements (SLAs),
troubleshooting and diagnostics, and performance auditing. With centralization, the Linux
systems will forward their logs to a single server, which can then store all the log files. This long-
term storage may be in the form of an SQL database or other database technology.
File servers, like those that use the File Transfer Protocol (FTP), enable the centralization of user
data. Such centralization provides many advantages in a business network. These advantages
include easier and more efficient backups, more secure storage of information, greater fault
tolerance, and easier access to information. It is much easier to manage data on a single file
server than to manage information that may be distributed across many end-user workstations.
Centralized printing services also include greater efficiency and significant cost savings. Print
costs are measured on a price per page basis. A single large, very fast, very efficient network
print device will be much less expensive on a per page basis than individual print devices
provided to each end-user. It is also much easier to manage paper and toner supplies for a few
powerful print devices than for a great many individual print devices.
VPN services are especially important because home and hotel networks are untrusted, as is
the Internet. Content is encrypted within the VPN client computer before it is sent across the
untrusted networks, then decrypted in the VPN server at the other end of the connection. Any
data intercepted on the untrusted networks remains secure because of this encryption.
Virtualization is split into two general types: virtual machines and containers.
Virtual machines (VMs) rely on virtualization of the computer hardware. A hypervisor layer of
software resides over the physical hardware and manages the allocation of that physical
hardware to the virtual machines that are created. Operating systems, including Linux, can then
be installed into the virtual machine. A virtual machine can provide the same full functionality
of a traditional, physical server. VMs typically provide cost savings by more efficient use of the
hardware along with many additional fault tolerance and management advantages. Examples
of virtualization include Oracle® VM VirtualBox, VMware WorkstationTM, Microsoft Hyper-V®,
and Kernel-Based Virtual Machine (KVM).
Containers operate with a different structure. A single host operating system runs multiple
applications in isolation from each other, but all applications share the OS and its resources.
Containers also provide a great deal of efficiency and management advantages. One example of
a container service is Docker.
HOSTNAME CONFIGURATION
The systemd startup mechanism uses a command named hostnamectl set- hostname to
configure the hostname value for the system. As with other services, once the configuration
change is made, you must also restart the service. Here is an example of setting a new
hostname with the hostnamectl command:
The IP configurations required include an IP address, the related subnet mask, the location of
the default gateway (router), and typically the location of one or more name servers (DNS
servers).
SYNTAX
The syntax of the nmcli command is nmcli [options] [subcommand] [arguments]
Subcommand Used To
con edit {device ID} Enter interactive mode to configure the specified NIC.
The ifconfig command is officially deprecated in Linux, as noted in the man page; however, it is
still available in many current distributions.
SYNTAX
The syntax of the ifconfig command is ifconfig [options] [interface]
SYNTAX
The syntax of the ip command is ip [options] {object} [subcommand]
SYNTAX
The syntax of the iwconfig command is iwconfig [options] [interface]
Option Used To
retry {number} Set the maximum number of MAC retransmissions for the NIC.
SYNTAX
The syntax of the ethtool command is ethtool [options] {device name}
Option Used To
SYNTAX
The syntax of the brctl command is brctl [command]
NIC bonding can be configured in an active/passive setup. In this setup, one primary NIC is
active, and a secondary NIC is on standby (passive). If the active NIC fails, the system
automatically fails over to the secondary NIC to maintain availability. NIC bonding can also be
configured in a load balancing manner, where the combined bandwidth of each is used in a way
that one of the NICs is not overwhelmed. The NICs that are members of the bond are referred
to as "slaves."
NIC bonding is supported in Linux, but support must also be present in the network switch. This
support is called EtherChannel. It is a feature of most enterprise-class switches.
While it is possible to manually edit these files with a text editor like Vim or nano, the
NetworkManager utility is often a much better way of managing the interfaces. There is a
command-line, text interface, and graphical interface for NetworkManager.
NETPLAN
Netplan is a network configuration utility found on some distributions. It uses YAML description
files to configure network interfaces. These files are stored in the /etc/netplan/ directory. You
will use a text editor to create or modify interface configuration files. Netplan includes
subcommands to make configurations more reliable. For example, you can enter sudo netplan
to have the configuration file checked for syntax errors before attempting to implement it. The
sudo netplan apply command actually makes the configuration change.
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.
Considerations for dynamic configurations:
• IP address configuration may change over time.
• Reduces the risk of typographical errors during configuration.
• Administrative workload is decreased for configuration and reconfiguration.
DHCP servers are configured with a scope, or a range of available IP addresses, along with
additional options. The DHCP service must be installed on the server that will host the service
and allow client machines to lease configurations.
The lease typically includes the IP address for the client, the associated subnet mask, the IP
address of the default gateway (router), the IP address of one or more DNS servers, and the
length of time the lease is valid. There are additional options that may be configured as well.
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.
Name resolution is the process of relating these easy-to-remember names with difficult-to-
remember IP addresses. There are two general ways in which name resolution works. The first
is via static text files such as the /etc/hosts file. The second method is via a dynamic database
called Domain Name System (DNS).
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.
Model Description
SaaS provides applications to end-users. The applications are not
installed directly on the user workstation, although to the user it seems
Software as a
as though the application is local. Deployment, maintenance, upgrades,
Service (SaaS)
and security patches are off-loaded to the cloud service provider. This
area of cloud computing typically provides service to all end-users.
PaaS includes virtualization of the operating system layer of the
environment. The development or database platform is supported by the
Platform as a cloud service provider and given to the customer in a ready-to-use
Service (PaaS) manner. Support for the platform is off-loaded to the cloud service
provider. This area of cloud computing typically provides service to
developers and database administrators.
In IaaS, the physical devices (servers, switches, routers, etc.) are
virtualized and owned by the cloud service provider. Responsibility for
Infrastructure as a
the hardware lifecycle is off- loaded to the cloud service provider. This
Service (IaaS)
area of cloud computing typically provides service to systems
administrators.
Red Hat® Cloud Suite is another CSP. Red Hat's solution is a Linux-based, full-featured private
cloud.
Although AWS and Microsoft Azure are considered the industry leaders in cloud services, there
are a great many additional CSPs. Many provide specialized services for particular parts of the
cloud market. Here are a few additional CSPs for you to investigate:
• Google Cloud™: Supports a very wide variety of services, including compute, storage,
database, IoT, development tools, etc.
• Rackspace: Services include compute, database, business continuity, and data center
management.
• Heroku™: Provides PaaS options for application development.
• Digital Ocean™: A PaaS cloud provider that provides scalability and management.
This virtualization extends to every model: SaaS, PaaS, and IaaS. For example, an administrator
can easily build and later tear down an entire cluster of systems with a single action, or even
automate this process in response to changes in the environment. It would be much less
efficient if the administrator had to do all of this on physical systems, so virtualization is
essential.
Kernel-Based Virtual Machine (KVM) is a Linux-based virtualization solution that can be added
to most Linux distributions. It enables the management of virtual machines on Linux platforms
with attributes of both type 1 and type 2 virtualization.
Template Description
• Contains config files, packages, etc. for VMs and network
OVF devices.
• OVA is a single package for a network appliance.
• Easily interpreted by programming languages.
JSON • Easy for humans to write and read.
• Used in quick deployment/config of VMs.
• Stores config info used to deploy VMs.
YAML • Can install software/create user accounts on first boot.
• Consists of key–value pairs.
• Provides app isolation, different than VMs.
Container images • Used for testing apps.
• Images contain everything needed to run container.
Cloud-init is a cloud-based Linux mechanism to customize a virtual machine during its first
bootup. This customization might include security settings, software package installations, user
and group creation, etc. Cloud-init references YAML files to find the necessary settings. Cloud-
init is supported by many distributions, including Ubuntu® Server 18 and Red Hat® Enterprise
Linux® (RHEL) 7.
Many Linux distributions use the Anaconda installer to manage their deployments. This installer
can provide prompts to an administrator to configure the new Linux server, or it can reference
files to customize the installation. Linux uses Kickstart files to customize the installation,
providing an unattended install. All information about partitions, packages, user accounts,
software deployments, etc., are contained in the Kickstart file. The combination of Anaconda
and Kickstart enables rapid, consistent, and customized Linux installations.
Because virtual drives are just files, they may provide more opportunity for fault tolerance,
simpler rollback of a system's status, redundancy, and storage scalability as compared to a
traditional physical drive.
PERSISTENT VOLUMES
Some organizations will manage container virtualization with Kubernetes. Kubernetes
provides an orchestration solution for container management. As part of that
orchestration, persistent volumes are created. When used in conjunction with a Linux
cluster, they keep the storage configuration separate from the configurations of the
individual cluster nodes. This makes it easier for nodes to be replaced through their
lifecycle without impacting the storage.
Object storage may be more efficient than block storage, especially for larger files. It may also
be more flexible when storing data in multiple geographical regions.
Network configuration for virtual machines must be carefully managed, because VMs
frequently are configured as production servers to which end-users need access. Once network
connectivity is provided, it is essential to follow best practices for securing network-connected
nodes. The fact that the network node is a virtual machine does not prevent it from needing
protection from network threats.
Virtualization supports the use of multiple NICs in virtual machines as well. If the NICs
are connected to different network segments, the server is referred to as being "dual-
homed."
Blob and Block Storage
Subcommand Used To
help Get help with virsh command.
list Get list of recognized VMs.
shutdown {VM} Gracefully shut down VM.
start {VM} Start VM.
reboot {VM} Reboot VM.
create {XML file name} Create VM from XML file.
save {VM} {file name} Save the state of a VM with the given file name.
console {VM} Open console to VM.
GNOME VMM
The GNOME Virtual Machine Manager (VMM) utility can be used for managing
connectivity to virtual machines. It enables the deployment, management, and
removal of virtual machines using an intuitive graphical interface. Download and
install the virt-manager package to begin using VMM.
First, check the basics: Is the device powered on? Is the device plugged in? Are the cables
properly connected to the correct network devices (switches, routers, etc.) and the hosts
themselves? Also, remember that NICs can be in an "up" or a "down" state. Verify that they are
available. Next, verify that the network interfaces are configured correctly. They need to have
an appropriate IP address configuration, subnet mask, default gateway value, and name
resolution settings. Also check that the network interface is detected by Linux and use the
ethtool command to gather driver and other information about the device.
You can troubleshoot name resolution issues using several different techniques. The first is to
ping a destination by both hostname and then by IP address. If the hostname-based ping fails,
but the IP address-based ping succeeds, then the system is not properly resolving network
names. At that point, you can use tools like host and nslookup to further test name resolution.
The network itself may also be experiencing issues. These issues might include very high traffic,
causing latency and saturation issues at various points within the network. If a router is
misconfigured or down, then the optimal path may not be found between two systems, or no
path may be found at all. Network interface cards that are failing could cause data packets to be
dropped on the network, causing a loss in data, timeout messages, or reduced network
SYNTAX
The syntax of the ping command is ping [options] {destination}
The {destination} can be an IP address, such as 192.168.1.1, or it can be a hostname, such as
server01
SEQUENCE NUMBER
The ping command also provides a sequence number (icmp_seq) for each ping
attempt. The host sending the ping can use this number to match each request with
its response. Mismatched sequence numbers might indicate a dropped packet.
The tracepath command is a simplified version of traceroute that does not require
administrative privileges to run. It also contains fewer options.
SYNTAX
The syntax of the traceroute and tracepath commands is traceroute/ tracepath [options]
{destination}
ROUTING ISSUES
Many routing issues are the result of misconfigured routing tables. These issues can usually be
fixed by updating the routing tables. However, you must first identify what is causing the issue.
Commands like traceroute and tracepath can reveal routing issues like routing loops, in which
traffic is continuously routed back and forth between multiple nodes and never reaches its
destination. For example, node A uses node B as a path to node C; but node B uses node A as a
path to C. If traffic is bound for node C, nodes A and B will endlessly send the traffic between
them because they both think each other is the path to C.
Option Used To
The netstat command has been deprecated in favor of the ss command, but it may still be
installed with some Linux distributions.
SYNTAX
The syntax of the netstat command is netstat [options]
An example is as follows:
unix 2 [ ] STREAM CONNECTED 472 /run/dbus/system_bus_socket
SYNTAX
The syntax of the ss command is ss [options]
Option Used To
Command Description
• Check the IP address configuration: If the ip addr command reports back an address in the
link-local range, then the NIC is not configured with a legitimate IP address. The link-local
range is 169.254.#.#. If the system is a DHCP client, then verify connectivity to the DHCP
server.
• Check the status of the NIC: The ip command can be used to "up" or "down" a NIC (enable
or disable it). If the NIC shows as down, it is disabled and not functional.
• Check the usage statistics of a NIC: Using ip with the -s option enables you to view
connectivity statistics for the connection.
Command Used To
route View the current routing table on the system.
Configure a default gateway by its IP address. Packets
route add default gw {IP address} will be passed to this destination if there are no other
routes that match their network ID.
Filter traffic destined to the specified address, which
enables an administrator to control connections to a
route add –host {IP address} reject
particular host. Can also be configured for an entire
subnet.
SYNTAX
The syntax of the route command is route [options]
Some common options with tcpdump are provided in the following table.
Option Used To
SYNTAX
The syntax of the netcat command is netcat [options]
The following table provides some example use cases for the netcat command.
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
SYNTAX
The syntax of the iftop command is iftop [options] [-i {interface}]
SYNTAX
The syntax of the iperf command is iperf {-c|-s} [options]
The mtr command also takes note of lost packets, a symptom of a problem called packet drop
or packet loss. This occurs when one or more packets sent from a source are unable to reach
their intended destination. Packet loss can cause latency if the packets are queued for
retransmission, or the data may not be successfully transmitted at all. A large number of lost
packets are a strong indicator of a network issue along the path. By identifying that the issue
exists, as well as where in the path it exists, mtr enables an administrator to find potentially
failed networking components. The output of mtr identifies the percentage of packets along
the path that are dropped, and one or more nodes in that path experiencing a high percentage
of packet loss may be at fault.
SYNTAX
The syntax of the mtr command is mtr [options] [hostname]
Computers will cache recently resolved MAC and IP address combinations. If a computer has
cached incorrect or out-of-date information, connectivity may be lost to a particular node. The
ARP cache can be cleared as part of the troubleshooting process.
For example, you can run arp -d {IP address} to a clear entry for a particular IP address, and
then try to ping the host again. Use arp -a to view the cache.
SYNTAX
The syntax of the arp command is arp [options]
SYNTAX
The syntax of the whois command is whois [options] {domain name}
• Identify the most common package managers in Linux, including RPM and dpkg.
• Manage RPM packages with the YUM front-end.
• Manage Debian packages with the APT front-end.
• Configure package repositories.
• Acquire software through means other than package managers.
• Compile software packages that are in source code form.
• Troubleshoot issues with software dependencies.
PACKAGE MANAGERS
Linux distributions rely on two different methods of managing the software lifecycle. The first
method is package managers—programs that install, update, inventory, and uninstall packaged
software. The second method is compiling software manually from source code. The open
source nature of Linux means that compiling code is much more common for Linux
administrators than for Windows or macOS users.
Package managers govern the software lifecycle, making it much easier for Linux administrators
to control what software is installed, manage software versions, and to uninstall the software.
The term package refers to a collection of files needed for a particular program. This set of files
includes the pre-compiled application itself, any supporting files it might require, and
supporting documentation. Packages are easy to distribute, verify, and manage via package
managers.
An alternative to using package managers is to compile the software yourself. This is the
traditional method of managing software. It has advantages and disadvantages. Windows® and
macOS® users don't typically consider compiling software, because most of the software
available is closed source, and therefore is only available in a pre- compiled format. Because
Linux relies on open source software, access to the source code is much more common. Users
can make changes to the source code, enabling or disabling options, customizing installation
choices, and even expanding the functionality of the software before compiling the code on
their systems.
Manually compiling software requires more effort and more knowledge, but it can result in a
more useful piece of software.
There is a newer and more advanced package manager that is commonly used by Red Hat
derivatives. This package manager is called the Yellowdog Updater, Modified (YUM). It relies
on RPM and uses .rpm packages. It offers a more elegant set of commands and greater
flexibility for using software repositories and handling dependencies. Today, even Red Hat
prefers YUM to manage the software lifecycle.
Zypper is a package manager that supports repositories, dependency solving, and management
of the software lifecycle. Zypper is an openSUSE package manager that supports .rpm packages.
It is very efficient and does an excellent job of managing package dependencies.
DNF SYNTAX
The syntax to install a DNF package is dnf install {package name}
The syntax to uninstall a DNF package is dnf remove {package name}
ZYPPER SYNTAX
The syntax to install a Zypper package is zypper in {package name}
The syntax to uninstall a Zypper package is zypper rm {package name}
Option Used To
SYNTAX
The syntax of the rpm command is rpm [options] [package name]
Command Used To
rpm -qa List all installed software (typically a very large output).
rpm -qc {package name} List the configuration files for a particular package.
SYNTAX
The syntax of the yum command is yum [options] [subcommand] [package name]
THE -y OPTION
Use the -y option with the yum command to automatically answer yes to installing additional
software dependencies. If you do not, YUM will prompt you to answer yes or no to whether the
additional dependencies should be installed.
Subcommand Used To
install {package name} Install the package from any configured repository.
provides {file name} Report what package provides the specified files or libraries.
Option Used To
List information about the specified package; if none provided, list all
-l [package name]
installed packages.
Until recently, the common software management tools were implemented as a mix of the apt-
get and the apt-cache commands, along with several other variations on the apt-* format.
Many Debian-derived distributions now use the more streamlined package manager simply
named apt
SYNTAX
The syntax of the apt command is apt [options] [subcommand] [package name]
Most of the subcommands mentioned previously with apt have the same effect with the apt-
get command. You can use apt-cache show {package name} to display package information.
Subcommand Used To
install {package name} Install the package.
remove {package name} Uninstall the package, leaving behind its configuration files.
purge {package name} Uninstall the package and remove its configuration files.
show {package name} Report information about the package.
version {package name} Display version information about the package.
update Update APT database of available packages.
Upgrade the package, or upgrade all packages if none
upgrade [package name]
provided (time-consuming).
The apt update command updates the APT database of available packages, enabling APT to
become aware of new versions of software available in the repositories. This does not install
any software. The apt upgrade command upgrades all installed software based on newer
versions of the packages as seen by the APT database. This is a full upgrade of all software, and
as such can be time-consuming. The apt upgrade {package name} command upgrades the
specified package based on a newer version of the package as seen by the APT database.
It is important to run the apt update command first, and then run the apt upgrade command. If
the apt update command is not run first, the database will not be aware of newer packages.
REPOSITORIES
Repositories, or repos, are storage locations for available software packages. Repositories can
be checked by package managers like YUM and APT when installing or upgrading software.
There are three kinds of repositories:
• Local repositories: These repositories are stored on the system's local storage drive.
Installation is easy, but version control is difficult because of the decentralized nature of local
repositories. If you manage 20 Linux servers, each would have its own repository to be
maintained.
• Centralized internal repositories: These repositories are stored on one or more systems
within the internal LAN and managed by the Linux administrator. This centralized approach
makes version control much simpler. If you manage 20 Linux servers, one could host the
repository and the other 19 could download their packages from it.
• Vendor repositories: These repositories are maintained on the Internet, often by the
distribution vendor. Version control is very difficult because the vendor decides what
package versions are made available.
Subcommand Used To
repolist See all available repositories.
makecache Locally cache information about available repositories.
clean all Clear out-of-date cache information.
SYNTAX
The syntax of the reposync command is reposync [options]
The following example synchronizes the server-rpms repo to a local directory named packages:
reposync -p packages -r server-rpms
Be sure to let APT know about new repositories after editing the /etc/apt/sources.list file by
running the apt update command
DOWNLOAD SITES
Because of the open source nature of Linux software, it is very common to be able to freely
download applications directly from the application vendor. In addition, there are many
websites that centralize information about available software, as well as about Linux
distributions.
You can search the Internet for Linux software. Here are a few examples of Linux applications
that are available for download:
• Audacity®, a music production application.
• Atom, a powerful text editor.
• GIMP, a powerful image editor.
• Nmap, a very useful network mapping utility.
You can also search open source hosting sites like GitHub® for software.
The following is an example of using curl to download a file from the Nmap website:
curl -o nmap-7.70.tar.bz2 https://nmap.org/dist/nmap-7.70.tar.bz2
DIFFERENCES
While wget and curl 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, which only supports HTTP/S and FTP.
• wget is better suited for straightforward downloading of files from a web server, whereas
curl is better suited to building and managing more complex requests and responses from
web servers.
SYNTAX
The syntax of the wget and curl commands is wget/curl [options] {URL}
The following is an example of creating a tarball: tar -cvf tarball.tar file1 file2 file3
This bundles file1, file2, and file3 into a tarball named tarball.tar.
Option Used To
-t Test the tarball or see what files are included in the tarball.
Specify the name of the tarball in the next argument (must be used as
-f
the last option).
WHY COMPILE?
Software that is packaged as an .rpm or a .deb is pre-compiled by the vendor. Usually, this
packaged software is configured with generic settings and options. A Linux user may want to
modify the software, for example, to optimize it for their specific hardware. This may result in
maximum performance. Packaged software is most common in Linux, but compiling your own
software is a normal Linux task. The same is not true for Windows and macOS, where nearly all
software is pre-compiled (because you don't typically have access to the open source code).
The required libraries vary by the software being compiled. Typically, software developers will
provide a list of these necessary libraries with the application source code. These may be
header files (.h file extension) or library files (.a file extension).
Shared libraries are typically included with a Linux distribution and are placed in
the /usr/lib/ directory for general accessibility. Libraries that need to be accessed by essential
binaries are typically placed in the /lib/ directory. Libraries that aren't packaged with a distro
can also be included by the developer to ensure that the user can run their program.
SYNTAX
The syntax of the ldd command is ldd [options] {program binary}
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.
On the second line, gcc compiles the objects necessary for the program to run. On
the remaining lines, each object is associated with a C source code file, then compiled
using that source file. Using this approach, if you make changes to a single C source
file (e.g., mymain.c), the make command will be able to efficiently rebuild the
program based on the directives in the makefile.
DEPENDENCY TROUBLESHOOTING
Dependency troubleshooting involves discovering what package dependencies exist before
attempting a deployment and ensuring that the needed dependencies are stored in the
repositories. Troubleshooting repository issues usually starts by verifying network access to the
repositories, and then checking the repository configuration files. On a Red Hat-derivative
distribution, for example, these files will be located in the /etc/yum.repos.d/ directory.
When troubleshooting problems while compiling software, begin by verifying that the
appropriate compiler, compiler version, and supporting libraries are present.
CYBERSECURITY
Cybersecurity refers to the protection of computer systems and digital information resources
from unauthorized access, attack, theft, or data damage. As a business discipline, cybersecurity
is pivotal for essentially all modern organizations, no matter their size. It is also an essential
practice for individuals whose identities are inseparable from the digital space, especially in the
highly connected ecosystem that is the Internet.
As with any computer system, Linux systems must be subjected to sound cybersecurity
practices in order for them to function with minimal risk to the organization. While your
organization may employ security specialists, anyone who touches a computer system,
especially those with administrative access to sensitive assets, is responsible for security.
Principle Description
This is the fundamental principle of keeping information and communications private and
protected from unauthorized access. Confidential information includes trade secrets,
Confidentiality
personnel records, health records, tax records, and military secrets.
Confidentiality is typically controlled through encryption and access controls.
This is the fundamental principle of keeping organizational information accurate, free of
errors, and without unauthorized modifications. For example, if an attack on a school system's
server occurred and student test scores were modified, the integrity of the grade information
Integrity
would be compromised by unauthorized modification.
Integrity is typically controlled through hashing, digital signatures, certificates, and change
control.
This is the fundamental principle of ensuring that computer systems operate continuously and
that authorized persons can access the data that they need. Information available on a
computer system is useless unless the users can get to it. Consider what would happen if the
Availability
Federal Aviation Administration's air traffic control system failed. Radar images would be
captured but not distributed to those who need the information.
Availability is typically controlled through redundancy, fault tolerance, and patching.
In order for a system to be 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).
Although privilege escalation can be used for legitimate purposes, e.g., an administrator
assuming root privileges through sudo, you must be on the lookout for any behavior that
enables attackers to escalate their privileges. One pitfall that can enable such behavior is poorly
configured SUID and SGID permissions.
While changing the permissions of a file to use either SUID or SGID, consider the following:
• Use the lowest permissions needed to accomplish a task; i.e., adhere to the principle of least
privilege. It is recommended not to give a file the same SUID or SGID as the root user. A user
with fewer privileges is often enough to perform the task.
• Watch for back doors. If the user runs a program with the SUID set to root, then the user
retains root as the effective user ID when the user goes through the back door. For example,
some programs enable an attacker to shell out to a remote system.
SYNTAX
The syntax of the chroot command is chroot [options] {new root directory} [command]
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.
TYPES OF ENCRYPTION
Encryption can be applied to data in transit (passing through a network), data in use (accessed
in memory), and data at rest (stored on a device). There are several subtypes of data at rest
encryption, with two of the most prominent being:
• Full drive/disk encryption (FDE), which encrypts an entire storage drive, partition, or volume
using either hardware or software utilities.
• File encryption, which encrypts individual files and folders on a file system using software
utilities.
SYNTAX
The syntax of the cryptsetup command is cryptsetup [options] {action} [action arguments]
In most business environments, IAM is a crucial service for provisioning and managing access,
as well as bolstering the overall security of the IT infrastructure.
A more secure alternative, and one that is common in sensitive organizational environments, is
to use public-key cryptography. Using public-key cryptography, the user generates a key pair
one public key, one private key. The server they are trying to remote into has a copy of the
user's public key. The server presents the user with an encrypted challenge that can only be
decrypted by the user's private key. If the user can successfully answer the challenge, the server
can validate that they own the private key. This eliminates the risk of using a password
(assuming password authentication is turned off) because the private key is virtually impossible
to guess or brute force. However, because the key is a "something you have" factor, it must be
stored on a highly secure system, where the risk of it being stolen is low.
Command Used To
Setting Used To
PasswordAuthentication Enable/disable password authentication.
PubkeyAuthentication Enable/disable public key authentication.
HostKey Reference server's private keys.
UsePAM Enable/disable PAM support.
Port Change port SSH service binds to.
ListenAddress Change IP address SSH service listens on.
SyslogFacility Change logging level of SSH events.
ChrootDirectory Reference a chroot jail path for a user.
AllowUsers, AllowGroups Allow specified users/groups access over SSH.
DenyUsers, DenyGroups Deny specified users/groups access over SSH.
PermitRootLogin Enable/disable root login over SSH.
For example, to deny all hosts, add the following line to /etc/hosts.deny:
sshd : ALL
Then, to whitelist your desired hosts, add them to /etc/hosts.allow:
sshd : 192.168.1.0/24
sshd : [email protected]
The streamlining of authentication also benefits administrators, as PAM makes it easier for
them to configure authentication policies across all applications and services on the system, as
opposed to configuring policies in different formats depending on the service. Developers can
also write their own PAM modules in order to support specific authentication and authorization
functions within an app.
ACTIVE DIRECTORY
One popular implementation of LDAP is Microsoft's Active Directory® (AD). While AD is
primarily implemented in Windows® environments, Linux systems can leverage pass- through
authentication to forward AD credentials to PAM. For example, you can configure the System
Security Services Daemon (SSSD) to cache credentials provided by AD or other external
authentication mechanisms, which SSSD can then use with PAM to manage identities.
MODULE INTERFACES
There are four module interfaces:
• account —Checks to see if a user is allowed access to something.
• auth —Used to verify passwords and set credentials (e.g., Kerberos tickets).
• password —Used to change passwords.
• session —Used to perform tasks in a user session that are required for access, like mounting
home directories.
CONTROL FLAGS
There are four control flags:
• optional —Module result is ignored.
PASSWORD POLICIES
In addition to the prior dictionary test example, the following are some more
examples of PAM password policy directives.
In the following example, the module will require that the user enter a "quality"
(strong) password. Non-local users—those not found in /etc/passwd—are ignored:
password requisite pam_pwquality.so local_users_only
The next example enforces a password history so that users don't re-use old
passwords when changing theirs. Passwords are "remembered" for 90 days:
password requisite pam_pwhistory.so remember=90
Lastly, the following example hashes the user's password using the SHA-512
algorithm. The use_authtok argument essentially tells the module not to do any
password
checks, but to instead pull in the password that has already been checked by any
prior modules (like quality and history)—assuming that the password has actually
passed those checks:
password sufficient pam_unix.so sha512 use_authtok
USER LOCKOUTS
There are two PAM modules you can use to trigger a temporary user lockout if
multiple authentication attempts fail: pam_tally2 and pam_faillock. The
pam_faillock module is recommended, as it is a newer module that improves upon
pam_tally2 by supporting user lockout when authentication is done over a screen
saver.
You can place these user lockout directives in /etc/pam.d/password-auth and
/etc/pam.d/system-auth
To unlock a user and reset their failure count, you can issue pam_tally2 -r -u user
LDAP INTEGRATION
You can configure PAM to use LDAP by leveraging the pam_ldap module. Using this
module, you can specify other directives that restrict what users can log in and how
they can access resources. If they meet the criteria you set, the pam_ldap module
can then authenticate the user with the LDAP service. You can add these directives to
the /etc/pam.d/common- files.
The module interface password indicates that this directive pertains to changing passwords.
The required control flag means that the result of the module must be successful, or else the
authentication process will not continue. The pam_cracklib.so module contains functionality
that prompts a user for a password and will test that password to see if it can be easily cracked
in a dictionary attack. The retry=5 argument gives the user five chances to fail the dictionary
test.
PSEUDOTERMINALS
A pseudoterminal (PTY) is an emulation of a standard controlling terminal that is used by a
program. The pseudoterminal appears to other software as if it is a real terminal, but data is
being input and output to the program that is emulating the terminal. For example, when you
SSH into a server and enter a command, that command is sent to the pseudoterminal, which is
actually controlled by the SSH service. You can enable the root user to log in to a
pseudoterminal by adding a pts/# entry to the /etc/securetty file. However, this is a security
risk, as it will allow insecure or malicious programs to leverage root privileges.
The openssl command can be used interactively through one of several subcommands, or you
can provide these subcommands and any options non- interactively.
SYNTAX
The syntax of the openssl command is openssl [subcommand] [options]
StrongSwan
One popular utility for implementing IPSec tunnels for VPN clients is StrongSwan, available
from the strongswan package. With StrongSwan you can set up user name and password
authentication, and you can also generate digital certificates to use as a method of
authentication. The main configuration file for StrongSwan is located in
/etc/strongswan/ipsec.conf and user accounts are configurable in the
/etc/strongswan/ipsec.secrets file.
DTLS
The Datagram Transport Layer Security (DTLS) protocol essentially implements SSL/TLS over
datagrams (e.g., using UDP as the transport layer protocol). This means DTLS traffic is not
susceptible to the same delays that TCP-oriented traffic is, particularly when TCP packets are
encapsulated within a TCP connection, like in certain VPN configurations. DTLS is therefore used
as an alternative VPN tunneling protocol. OpenConnect is a popular cross-platform VPN that
supports DTLS tunneling.
If remote access still fails, try signing on with the account locally to see if it's a service issue or
some other networking issue. You can also test if it's a local issue by ensuring the account is
active and not expired and that the password is still valid. If the account has expired or its
password is otherwise invalid, you may need to reset the password using the passwd
command. In addition, you should verify that the account is a member of the correct group(s)
using the groups command.
If users are authenticating through an external service like a Kerberos or RADIUS/ TACACS+, you
should ensure the user identities are correctly configured in those services and that those
services are available over the network. VPNs and SSL/TLS
CONTEXT-BASED PERMISSIONS
Context-based permissions describe multiple types of information about processes and files
that are used in combination to make decisions related to access control. In other words, the
permission scheme defines various properties for a file or process, and uses those properties
together, rather than in isolation, to determine whether to grant or deny access. This makes
context-based permissions more advanced than the default scheme of granting a user or group
access to a file directly.
In Linux, there are two main context-based permission schemes available: SELinux and
AppArmor.
SELinux enforces 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.
MULTI-LEVEL SECURITY
Multi-level security (MLS) is an optional feature of SELinux that enables a fourth context, called
a level, to describe the sensitivity level and/or category of an object. This enables you to further
fine-tune and constrain access even when the main three contexts are fulfilled.
Mode Description
In this mode, SELinux is turned off. So, MAC will not be implemented and the
Disabled
default DAC method will be prevalent.
In this mode, all the SELinux security policies are enforced. Therefore,
Enforcing
processes cannot violate the security policies.
In this mode, SELinux is enabled, but the security policies are not enforced. So,
Permissive processes can bypass the security policies. However, when a security violation
occurs, it is logged and a warning message is sent to the user.
Each policy is categorized as either targeted or strict. According to a targeted policy, except the
targeted subjects and objects, all other subjects and objects will run in an unconfined
environment. The untargeted subjects and objects will operate on the DAC method and the
targeted ones will operate on the MAC method. A targeted policy is enabled by default.
A strict policy is the opposite of a targeted policy, where every subject and object of the system
is enforced to operate on the MAC method.
Command Used To
semanage Configure SELinux policies.
sestatus Get detailed status of SELinux.
getenforce Display mode SELinux is running in.
setenforce Change mode SELinux runs in.
getsebool Display on/off status of SELinux boolean values.
setsebool Change SELinux boolean values.
ls –Z List security contexts of files/directories.
ps –Z List security contexts of running processes.
chcon Change security context of files.
restorecon Restore default security context of files.
One way to diagnose and troubleshoot unexpected violations is by using the sealert command
with the -a option and the audit log provided as an argument. For example:
sealert -a /var/log/audit/audit.log
This will display all of the policy violations that have occurred, along with detailed information
about each violation, including the timestamp, log type, permission requested, names of the
process and the target it tried to access, security contexts of both, and more.
The output of sealert can be difficult to parse, so you can use the audit2why command to
translate an event into a more human-friendly format that explains why a violation occurred.
You can redirect the entire log to this command. If you only want to analyze one or a few
events, you can grep an identifier that is unique to an event, like its timestamp, and then pipe
that to the audit2why command.
Functionally, the main difference is that AppArmor works with file system 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.
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.
AppArmor MODES
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.
Command Used To
In addition, you can configure the firewall to log any of the previous actions. These logs
typically include information about the packet, like its source and destination, as well as
timestamps and other useful data.
SYNTAX
The syntax of the iptables command is iptables [options] [-t table] [commands] {chain/rule
specification}
DEFAULT TABLES
There are five default tables that may be active depending on how the kernel is configured:
• 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.
LOGGING
You can enable logging for iptables rules by including the LOG action. In the following
example, all dropped packets are being logged:
iptables -N LOGCHN
iptables -I INPUT -j LOGCHN
iptables -I LOGCHN -j LOG
iptables -I LOGCHN -j DROP
The first line creates a new chain called LOGCHN. The second line ensures all
incoming packets not already processed by any prior rules will "jump" to the LOGCHN
chain. The third line logs all packets that reach this chain, and the fourth line
performs the actual dropping of packets. You can also substitute ACCEPT for DROP if
you only want to log accepted packets.
Events for iptables are typically written to the /var/log/messages or
/var/log/kern.log files.
SYNTAX
The syntax of the ufw command is ufw [options] {action}
ADVANCED CONFIGURATION
If you want to use UFW to employ a more complex firewall configuration, you'll need to edit
text files rather than use the ufw command. The /etc/default/ufw file is used to configure
high-level settings like policy defaults and kernel module usage. More granular configuration
files are found in the /etc/ufw/ directory. You can edit these files to control when rules are
applied, when customizations are run with respect to the ufw command, and more.
Firewall zones are the rule sets that can apply to specific network resources, like a network
interface. You'd typically place resources in a zone to group them with resources that have
similar security requirements or similar levels of trust. There are various default zones, each
with different levels of trust. For example, the zone with the lowest level of trust is called drop
and it immediately drops all incoming connections. Firewall services are the rules that apply to
specific services that operate within a zone. For example, you can add a service like HTTP to the
dmz zone to allow incoming connections from untrusted networks like the Internet, while
denying outgoing access to the rest of the network.
SYNTAX
The syntax of the firewall-cmd command is firewall-cmd [options]
PERSISTENCE
Like iptables, firewalld does not persist its changes by default. This is called runtime mode. You
must commit a change with the --permanent option for it to persist upon restart of the
daemon.
The iptables tool is closely integrated with Netfilter. It is able to allow, drop, and perform other
firewall actions because it can interact with packets that are on Netfilter hooks. Both UFW and
firewalld call iptables in some capacity, so they likewise rely on Netfilter.
IP forwarding is often used in conjunction with iptables firewall configuration. For example, say
you have a Linux host acting as a router. It has one public, Internet-facing interface; and one
private, internal-facing interface. You also have a separate web server with only a private
interface. You want traffic from the Internet to pass through your router, and only be forwarded
on to the internal network if the traffic uses ports 80 or 443 (HTTP/S). You can do this by
configuring a FORWARD chain that will allow traffic on ports 80 and 443 to be forwarded on to
the private interface, while preventing any other kind of traffic from being forwarded.
In order to leverage IP forwarding, you must first enable it in the kernel. This is as simple as
altering a single value in the appropriate file:
echo 1 > /proc/sys/net/ipv4/ip_forward
Or, for IPv6 traffic:
echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
SYNTAX
The syntax of the ipset command is ipset [options] {command}
In this case, range_set is the name, hash is the storage method, and net is the data type. Then,
you can add the ranges to the set:
ipset add range_set 178.137.87.0/24 ipset add range_set 46.148.22.0/24
Then, you use iptables to configure a rule to drop traffic whose source matches the ranges in
this set:
iptables -I INPUT -m set --match-set range_set src -j DROP
Alternatively, to drop traffic whose destination matches the set:
iptables -I OUTPUT -m set --match-set range_set dst -j DROP
TROUBLESHOOTING
The ipset tool can also be used when troubleshooting the iptables firewall. For example, you
can use the test subcommand to test whether or not an entry exists:
ipset test range_set 178.137.87.5
If the firewall still isn't handling the IP address ranges as expected, you can list the rules that
are using the relevant set:
iptables -L | grep range_set
Even if the rules are using your set, keep in mind that the rules are processed in order; the
unexpected behavior may be due to how these rules flow in the table.
Linux keeps a database of services and their corresponding port numbers in the /etc/services
file. This file enables services to, by default, attempt to bind to their corresponding port when
activated. The format of each entry is:
service-name port/protocol [aliases] [# comment]
So, to map an application called my-app to port number 55111, you'd add the following line:
my-app 55111/tcp # My custom app
Whenever my-app is started, it will attempt to bind to port 55111 and start listening on that
port. So, you'd use a firewall service like iptables or firewalld to allow traffic bound for port
55111 on the network.
TRUSTED PORTS
Trusted ports, also called privileged ports, are ports in the well-known range (0– 1023). In
Cause Solution
Check your firewall's rule set to ensure that it is not overtly blocking a port that your
system needs in order to forward outgoing traffic. Likewise, your firewall is likely in
Blocked ports
default deny mode for incoming connections, so be sure to create an explicit rule that
allows traffic on the port you need.
Even though you may be correctly allowing a port, you may not have configured it for
the correct protocol. Ensure that you are opening up the port on either TCP, UDP, or
Blocked protocols both— depending on what transport protocol the connection requires. Also ensure
that, for application-layer firewalls, they are not configured to drop packets whose
contents match a specific application-layer protocol (e.g., HTTP, FTP, SSH).
The factors that an ACL uses to allow or deny traffic can be used in conjunction; for
example, you can configure an ACL to only block a specific source port if its source
matches a known IP address and if it is headed for a specific destination port. Granular
Restrictive ACLs filtering like this can be very useful, but it can also become complex and has a higher
potential for false positives. Configure your ACL rules to be as straightforward as your
needs allow and don't get carried away with trying to write a granular rule for every
possible scenario.
A firewall is like a security guard who lets guests into a building based on whether or not they
match predefined rules. An IPS is more akin to a second security guard inside a building. Even if
the outside guard (the firewall) lets someone in, the inside guard (the IPS) will watch that guest
for signs of suspicious behavior. If the guest exhibits a repeated pattern of suspicious behavior,
the inside guard will kick them out. In other words, an IPS is a second layer of defense that
monitors traffic that makes it past the firewall, looking for signs of anomalous behavior.
The other major difference is that IPSs are only concerned with managing incoming traffic,
whereas firewalls apply to both incoming and outgoing traffic.
CONFIGURATION
The primary configuration file for DenyHosts is the /etc/denyhosts.conf file. There are various
settings you can adjust in this file. Some examples include:
• ADMIN_EMAIL —Define what email address to send alerts to.
• BLOCK_SERVICE —Define what services will be blocked from access by unauthorized users.
• DENY_THRESHOLD_VALID —Defines how many times a user can attempt to log in to an
The primary configuration file for Fail2ban is the /etc/fail2ban/jail.conf file. However,
if you plan on configuring Fail2ban, it is best to copy this file to /etc/
fail2ban/jail.local or make a custom .conf file within the /etc/ fail2ban/jail.d/
directory. The following are some example settings:
• bantime —Defines how long a host is blocked from accessing a resource.
• maxretry —Defines the number of times a host can fail to authenticate before
being blocked.
• ignoreip —Defines a whitelist of accepted hosts.
SYSTEM LOGS
System logs are records of system activities and events that are tracked and maintained by the
syslogd daemon. System logs use the syslog standard, which facilitates a centralized logging
server that can receive and process syslog data from many systems across a network. This is
called remote logging. The syslog standard also supports local logging, where logs are stored on
the same system that generated them.
System logs are recorded in simple text files that you can examine and process like any other
text. Entries in a syslog system typically include the date and time of the event, the process
name and ID that sent the message, and the message itself. The syslog format may also
prioritize messages by facility and severity. Facility codes indicate what system was affected,
such as "kern" for kernel and "mail" for the mailing system. Severity codes indicate what level
of impact the event might have, from 0 (most critical) to 7 (least critical).
You install a syslog agent on the platform that doesn't normally support the standard, like
Windows. Which agent you install will depend on the platform, as well as the type of syslog
service you're targeting. For example, rsyslog and syslog-ng both require their own agent
software. Once the agent is installed, you'll be able to configure it to capture messages in a
syslog format and send those messages on to your centralized syslog server.
The journald service is often used in conjunction with a traditional syslog daemon such as
syslogd or rsyslogd. The settings for journald are configured in the /etc/systemd/journald.conf
file.
SYNTAX
The syntax of the journalctl command is journalctl [options] [matches]
Option Used To
SYNTAX
The syntax of the last command is last [options]
BACKUP TYPES
A backup is a copy of data that exists in another logical or physical location than the original
data. Backups facilitate the recovery process in case of data loss. The process of recovering data
from a backup varies depending on the backup types that were included in the original backup
plan.
There are three main types of backups: Full backup, Differential backup, and Incremental
backup
SYNTAX
The syntax of the tar command is tar [options] {file names}
To create a differential backup (diff1.bak), you can reference the full backup using the
-A option:
dar -R mydata -c diff1.bak -A full.bak
You can then create more differential backups as needed by referencing the full
backup with the -A option. However, to perform incremental backups instead, you
need to reference the previous incremental backup, like so:
dar -R mydata -c incr1.bak -A full.bak
dar -R mydata -c incr2.bak -A incr1.bak
SYNTAX
The syntax of the cpio command depends on its mode. In all modes, the command reads from
standard input. The following copy-out example archives all contents of a directory by piping ls
to cpio and sending the archive output to dir_arch:
ls | cpio -o > dir_arch
In copy-pass mode, you can pipe find to cpio to copy one directory tree to another:
find . -depth -print | cpio -p new_dir
Operand Used To
if={file name} Specify the file from which data will be read.
of={file name} Specify the file to which data will be written.
Specify the total block size to read and write, in bytes. Bytes can also be
bs={bytes} formatted in a more human-friendly way, such as 50M to specify 50
megabytes and 10G to specify 10 gigabytes.
Specify the number of blocks to be written to the output file from the input
count={blocks}
file.
Specify the level of information to print to standard error:
• none to suppress everything except error messages.
status={level}
• noxfer to suppress total transfer statistics.
• progress to display transfer statistics periodically.
SYNTAX
The syntax of the dd command is dd [options] [operands]
Using dd, you can also create an image of a drive and then clone a second drive with
it:
dd if=/dev/sda of=drive_image.iso
dd if=drive_image.iso of=/dev/sdb
SYNTAX
The syntax of the mirrorvg command is mirrorvg [options] {volume group}
There are several ways to copy data from the main site to the backup site. Rather than
physically move backup storage devices from one location to the other, it's usually more
convenient to connect both sites by a network, such as in a VPN, and transfer data over that
network.
Compression is commonly used to reduce the storage and transmission burden involved with
creating, maintaining, and recovering from backups. Rather than backing up data one-to-one,
you can compress that data and then store it.
SYNTAX
The syntax of the gzip command is gzip [options] [file names]
Option Used To
-d Decompress files.
Force compression or decompression of a file even if it has multiple links or if
-f
the file exists.
-q Suppress all warnings.
Display the name and percentage reduction of the compressed or
-v
decompressed file.
-t Perform an integrity check on the compressed file.
SYNTAX
The syntax of the xz command is xz [options] [file names]
SYNTAX
The syntax of the bzip2 command is bzip2 [options] {file names}
For example, to compress files file1 and file2: bzip2 file1 file2
Option Used To
-r Enable recursion.
SYNTAX
The syntax of the zip command is zip [options] [file names]
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.
There are several methods that 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.
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.
The Secure Hash Algorithm (SHA) algorithm 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.
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
SYNTAX
The syntax of the md5sum command is md5sum [options] [file name]
SYNTAX
The syntax of the sha#sum commands is sha#sum [options] [file name]
SHELL ENVIRONMENT
The shell environment is the mechanism by which Bash, or any other shell, maintains settings
and other behavioral details about the shell. The shell creates this environment when starting a
session and uses the environment's settings to determine how to interact with the user.
The process of creating a new session is called shell spawning. This new session is a copy, and
is called the child process. For example, the shell spawns a child process when the user enters a
command. This child process becomes the new process and can also create more processes,
which result in multiple generations of processes. Each process calls upon the shell
environment and passes its details onto the next generation.
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.
In order 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 a 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.
SYNTAX
The syntax of the export command is export [options] [NAME[=value]]
Usually, directories that contain executable files are assigned to the PATH variable. This enables
you to enter the name of an executable at the CLI without needing to specify its full directory
path. This is because the PATH variable searches its directories for the name of the executable.
SYNTAX
The syntax of the alias command is alias [alias name[='command with options']
By finding out how long it takes a command to run, you can get a better idea of how to
optimize frequent tasks. Some commands may complete the same task faster than other
commands.
SYNTAX
The syntax of the time command is time [options] {command}
BASH SCRIPTING
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.
Many programming languages, like C, require you to define the type of variable before you
assign it to a value. Examples of types include integers, floats, strings, and more. Essentially,
these types define exactly what kind of information the variable holds. However, you don't have
to declare variable types in Bash. Instead, all Bash variables are treated as strings.
Many languages find common ground when it comes to representing operators in code. For
example, in many languages, the == comparison operator evaluates whether or not the
operands have equal values. Therefore, the expression 1 == 2 outputs to false. Note that this
particular operator is distinct from a single equals (=), which is used in assigning values to
variables.
BASH OPERATIONS
The following is an example of an arithmetic operation in Bash. Note that expressions
are evaluated when wrapped in double parentheses: $((var1 + var2))
An example of a comparison operation in Bash. Note the use of square brackets and a
letter-based operator: [ $var1 -ge $var2 ]
An example of a logical operation (AND) in Bash: [ $var1 -ge $var2 ] && [ $var3 -le
$var4 ]
An example of a string operation (concatenation) in Bash: $var1$var2
For example, say you've defined the my_str variable mentioned previously. You then want to
substitute this variable into a larger string literal, like so:
echo "My variable is $my_str”
echo 'My variable is $my_str’
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 what
your intent is.
In Bash, the escape character is a single backlash (\). For example, let's say you want to print a
string to the command-line that actually contains a dollar sign. The dollar sign, as you know, has
a special meaning—it is used in variable substitution. You can handle this by using single
quotation marks, as so:
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.
BASH FUNCTIONS
In Bash, there are two ways of writing functions. Both involve placing the desired code in
between curly braces. The first method is:
function my_func {
code...
}
If you're familiar with object-oriented programming languages like C, you might be more
comfortable with the second method:
my_func() {
code...
}
However, note that the open and closed parentheses are just there for visual clarity. In Bash,
you don't pass in arguments to a function like you would with other programming languages.
Instead, you pass in arguments similar to how you would at the command-line.
BASH COMMENTS
The following is an example of a short script with comments:
# This script determines how many files are remaining to process in a directory.
#!/bin/bash
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.
Metacharacter Used In
> Output redirection.
>> Output redirection (append).
< Input redirection.
<< Input redirection (here documents).
| Piping.
" Defining weak string literals.
' Defining strong string literals.
` Breaking out of string literal to run command between backticks.
\ Escaping characters.
= Variable assignment.
Likewise, you can pipe to other commands from within a script. The following example reads a
text file of names (cat), pipes that text to search for a particular name (grep) , then pipes that
to a command that identifies the total count of that name (wc).
#!/bin/bash
cat name_list.txt | grep 'John' | wc -l
For the four expansions that happen at the same time, the expansion is done in left-to-right
order as each appears.
You can also use the format $(command) to perform command substitution, as in the
following:
echo "The current directory is $(pwd). "
The first example 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. The second example will only copy .txt files with a single character
as a name, like a.txt and b.txt, but not ab.txt. The third example will only copy files named
a.txt, b.txt, or c.txt.
You can also use the exec command without a 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.
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.
You can set these permissions using chmod just as you would with any other file.
Conditional statements are fundamental to most programs and scripts, as they help you control
the flow of executed code. For example, if a user enters some input, you might want to process
that input differently based on a number of factors. The user might supply one argument and
not another. Rather than executing the script as if all possible arguments were intended, you'd
only execute the script with the argument the user supplied.
Because 5 is greater than 1, the message will echo to the screen. If it were not true, then
nothing would happen.
SYNTAX
The basic syntax of an if statement is as follows:
if [ <condition to be evaluated> ]
then
<code to execute if condition is true>
fi
SYNTAX
The basic syntax of an if...else statement is as 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 is as 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
SYNTAX
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
case $var in
red)
echo "Your color is red.”
;;
green)
echo "Your color is green."
;;
blue)
echo "Your color is blue."
;;
*)
echo "Your color is neither red, green, nor blue."
;;
esac
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 test COMMAND
The test command is used to check conditional logic and perform comparisons. You can use the
test command in your shell scripts to validate the status of files and perform relevant tasks. It
evaluates a conditional expression or logical operation and displays an exit status. The exit
status is 0 if the expression is true and 1 if the expression is false.
For example:
var=/etc
if test -d $var;
then
echo "The $var directory exists!"
fi
This example uses the -d option to test if a directory exists. There are many such conditional
options you can use. Consult the man page for the test command to see them all.
SYNTAX
The basic syntax of a while loop is as follows:
while [ <condition to be evaluated> ]
do
<code to execute while condition is true>
done
SYNTAX
The basic syntax of a for loop is as follows:
for i in <variable to loop through>
do
<code to execute a specific number of times>
done
Then, the loop itself will execute three times—one for each value in the array. So, each person's
name will be echoed to the screen.
THE at COMMAND
The at command is used to run 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 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, 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.
SYNTAX
The syntax of the at command is at [options] {time}
TIME SPECIFICATIONS
The at command takes several possible arguments for specifying time. Examples include:
• noon to specify 12 P.M.
• teatime to specify 4 P.M.
• midnight to specify 12 A.M.
• now + 3 minutes to specify the time three minutes from now.
• now + 1 hour to specify the time one hour from now.
RELATED COMMANDS
The atq command can be used to view the current queue of tasks scheduled by the at
command. The atrm command can be used to delete a scheduled task.
The cron daemon checks its crontab configuration file each minute to discover whether there
are any tasks to be accomplished. If there are, it executes them. If there are not, it goes back to
sleep until the next minute.
Cron jobs can be used to specify tasks each minute, hour, day, month, and any day of the week.
This makes them extremely flexible.
SYNTAX
The syntax of the crontab command is crontab [options] [file/ user]
Option Used To
-e Edit the crontab file for the current user.
-l View the crontab file for the current user.
-r Delete the current crontab file.
-u Create a crontab file on behalf of the specified user.
The following are examples of lines in a crontab file that schedule tasks at certain times:
* 20 * * 1-5 /path/to/command —executes the command at 8 P.M., Monday through Friday.
15 2 * * * /path/to/command —executes the command at 2:15 A.M., daily.
30 4 1 * * /path/to/command —executes the command at 4:30 A.M. on the first day of each
month.
Regular users are not allowed to populate the /etc/cron directories, so each standard user can
schedule their own tasks in a personal directory located at /var/spool/cron. Any tasks listed
here will execute with the standard user's credentials.
The /etc/ directory also contains several default cron directories that administrators can use to
place scripts to be executed on a regular basis. These directories
are /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly,and /etc/cron.monthly. Link or copy a
script into these directories to use their schedule to run your commands.
Some Linux distributions pre-populate the /etc/crontab file with particular tasks. You may find
that logrotate, tmpwatch, rkhunter (Rootkit Hunter), etc., may already be present. The
installation of these kinds of services may also include the creation of /etc/crontab entries.
GIT
Git is a distributed version control system primarily used by developers who are collaborating
on projects. Git was developed by Linus Torvalds, the same person who created Linux. Git is the
standard version control program in the development world today. It is often integrated with
development editors.
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 premise, or to use an online solution like GitHub. A
centralized repository is not required, however.
To get started with Git, use an available package manager to install the git package.
SYNTAX
The syntax of the git command is git [options] {subcommand}
BRANCHING
Optionally, you can work with Git branches:
1. Create a branch of the master copy of the code:
git branch newbranch
2. Make changes, and then integrate (merge) those changes back into the master
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 in the master branch:
git merge newbranch
The *.git/ directory contains all the files Git uses to manage version control for your project. It
is a single location where Git stores all of its information. The directory resides in the project
directory and is created with the git init command.
ORCHESTRATION
Orchestration enables the automation of multiple related tasks—an entire workflow. One
example of orchestration might be the deployment of a web app. The deployment may include
the installation and configuration of the web server, the installation and configuration of a
MySQL™ database server, and the installation and configuration of an application server, as well
as all supporting software. Orchestration would manage each of the steps involved, even
though there may be different operating systems and configuration requirements involved.
Orchestration is used in both on-premise and cloud-based solutions.
SYSTEM REQUIREMENTS
It's important to think of system requirements as more than just what hardware components
are necessary to get a system up and running—they also specify what is necessary to keep that
system operational and able to perform its assigned function. So, you may be able to install
Linux on a computer just fine, but that doesn't mean it will perform optimally.
The system requirements for a Linux system will vary greatly based on a number of different
factors:
• The Linux distribution you're using. Different distros have different recommendations and
baseline requirements as far as CPU speed, RAM, storage space, and more. Some distros are
specifically designed to be lightweight; i.e., they consume much fewer resources than a
standard enterprise or consumer distro.
• Hardware compatibility. Even if a CPU, GPU, etc., is more than powerful enough to run a
Linux distro, that doesn't mean the distro (or the Linux kernel) supports it. You need to
choose hardware that has available, stable drivers
• The general category of the system. Is the system a server? A workstation? Something else?
Each category lends itself to different types of components. For example, CPUs like the Intel®
Xeon® are designed for servers, as they place emphasis on error correction and reliability, as
well as having many cores per processor. A desktop CPU, on the other hand—like an Intel®
Linux usually uses a dedicated partition for virtual memory storage (i.e., swap space). This
partition is unusable for any other kind of storage and has its own file system. It is important to
plan for the swap partition at the same time you plan for data storage partitions. A general
guideline is that the size of the swap partition should be two times the quantity of RAM,
though this number will vary.
So, before you install Linux, you should gather hardware information about your system. Much
of this information is available in your system documentation, whether it's the printed manual
that came with a component or it's documentation you can find on the manufacturer's website.
You can also gather hardware device data from a low- level interface like BIOS/UEFI. Failing
either of those options, you may need to open the hood and look inside. Many components
have vendor and model information printed on them.
• Booting from media installed on the local drive. For example, you can download an ISO of a
different distro of Linux onto your existing Linux system. You can then configure GRUB 2 to
boot from this ISO, as long as it is placed on a partition that doesn't currently contain a
bootable OS.
• Boot from media that is delivered over a network. You can use protocols like PXE and NFS to
service installation media to a client, who can use that media to boot into the installation
environment.