Appendix
The Bottom Line

Each of The Bottom Line sections in the chapters suggest exercises to deepen skills and understanding. Sometimes there is only one possible solution, but often you are encouraged to use your skills and creativity to create something that builds on what you know and lets you explore one of many possible solutions.

Chapter 1: Understanding the Basics

Chapter 2: Installing an Ubuntu Server

  • Review needed Ubuntu server hardware resources. Determining the hardware resources required for an Ubuntu installation on a physical or virtualized server helps to ensure a successful completion of the install. It also avoids wasting time.
    • Master It Imagine that you need to install the Ubuntu Server on a physical server that has a dual‐core 1 GHz CPU, a 200 GB hard drive, and 10 GB of RAM. Are the server's resources sufficient? Why or why not?
    • Solution The server's resources of a dual‐core 1 GHz CPU, a 200 GB hard drive, and 10 GB of RAM are sufficient to install the Ubuntu Server distribution. The minimum needed is a 1 GHz CPU, 2.5 GB of disk space, and 1 GB of memory. Thus, this physical server can properly handle the load of the Ubuntu Server distro.
  • Determine the requirements for a virtual Ubuntu system. Installing the Ubuntu Server distribution on as a VM on a host system has different requirements than a direct installation on a physical server. It is critical to evaluate the host system so that the installation is successful.
    • Master It Your project team is planning on installing two Ubuntu Server VMs on a host system that has a dual‐core 1 GHz CPU, a 200 GB hard drive, and 10 GB of RAM. Are the host system's resources sufficient? Why or why not?
    • Solution The host system does not meet the minimum CPU requirements for a single Ubuntu Server VM, which is a 2 GHz dual core processor. While there is sufficient disk space for two VMs, the RAM is potentially a little low, since 16 GB is recommended (but not required) for a single Ubuntu Server VM.
  • Obtain Ubuntu Server software. To install the Ubuntu Server Linux distribution, you must have the proper ISO image file. This is true whether you are installing it directly on hardware or as a VM. Besides getting the ISO file, you need to ensure that it is not corrupted so that the installation proceeds well.
    • Master It You've downloaded the Ubuntu Server ISO image file but are concerned that during the download process, file corruption occurred. What should you do to see whether the ISO image file is corrupt?
    • Solution Get a hash value by using a hashing algorithm program that uses the SHA256 algorithm on the downloaded Ubuntu Server ISO image file. After you get the hash value, compare it to the hash value listed on the Ubuntu Server website. If they match, your ISO image file is not corrupted. If they don't match, you'll need to download it again.
  • Conduct an installation of an Ubuntu Server. There are several steps to successfully install an Ubuntu Server, and it is critical that you complete all of them. Skipping a step can cause problems immediately, and problems later, if you can even get the system to boot.
    • Master It Your sysadmin team has correctly installed the Ubuntu Server software from the ISO image file and the system booted without any problems. What's the next step?
    • Solution After your sysadmin team has correctly installed the Ubuntu Server software from the ISO image file and the system booted without any problems, the team needs to update the software information via the sudo apt update command. After that is completed, they will need to update the software through the sudo apt dist‐upgrade command.
  • Audit the Ubuntu Server's installation. If you had some problems while booting the system, there are a few commands you can use to look at helpful boot messages. But even a successful installation still requires a few additional checks.
    • Master It At your company, you have completed the entire Ubuntu Server installation process on a new system without any problems for the development team. The team wants to know what version of the Linux kernel is used on this new system. How do you get that information?
    • Solution There are two ways to get the Linux kernel version information on the new system for the development team. You can log into the system and issue either the uname ‐r or the cat /proc/version command.

Chapter 3: Installing and Maintaining Software in Ubuntu

  • Explore different Linux software package management systems. Developers bundle the files required for an application into a package to make it easier to install. A package management system allows you to easily track, install, and remove application packages on your Linux system. There are two popular Linux package management systems: dpkg for Debian‐based systems, and rpm for Red Hat–based systems.
    • Master It The Debian Linux distribution maintains an official website that tracks all software packages as they're developed for the Debian environment. Go to the packages.debian.org website and determine what version of the systat application is available as a stable Debian package.
    • Solution After you go to the packages.debian.org website, enter sysstat in the search text box to search for that package name. In the Exact Hits section, notice that there are different versions of sysstat available in the different Debian distribution versions. At the time of this writing, the current stable version (called buster) only supports sysstat version 12.0.3‐2. However, the testing version (called bullseye) supports version 12.4.0‐1.
  • Use Debian software packages to install software. The Debian‐based Linux distributions use the dpkg utility to interface with the package management system from the command line, and they use the apt‐cache and apt‐get utilities to interface with a common repository to easily download and install new software. A front end to these utilities is apt. It provides simple command‐line options for working with software packages in the dpkg format.
    • Master It The C shell provides an alternative to the Bash Shell, handy for writing advanced shell scripts. For Ubuntu, the C shell is bundled as part of the csh package. What commands should you use to install the csh package from the standard Ubuntu software repository?
    • Solution To install the csh package, you would use the apt utility. Just enter the command sudo apt install csh at the command prompt. To test the new shell, enter the command csh at the command prompt. This opens an instance of the C shell, which uses the percent symbol (%) as the shell prompt. To return to your Bash Shell, type exit.
  • Install applications using Debian snap containers. Application containers are a relatively new player in software package management. An application container bundles all the files necessary for an application to run in one installable package. This means the application doesn't rely on any external dependencies such as library files, and the container bundle can be installed in any Linux distribution and run. Currently, the two most popular container packages are snap, common in the Ubuntu Linux distribution, and flatpak, used in Red Hat Linux environments.
    • Master It The PowerShell package provides a powerful scripting language similar to that found on Microsoft Windows servers. Ubuntu distributes the PowerShell package as a snap container. What command should you use to install PowerShell on your Ubuntu server?
    • Solution Since the PowerShell application uses an old container format, if you try to install it using the standard snap install powershell, you'll receive an error message warning you that it uses the old format and telling you to use the ‐‐classic option. So, to install the PowerShell snap package, you must enter the command sudo snap ‐‐classic install powershell.
  • Install software from source code. The chapter closed with a discussion on how to install software packages that are only distributed in source code tarballs. The tar command allows you to unpack the source code files from the tarball, and then the configure and make commands allow you to build the final executable program from the source code.
    • Master It There are lots of handy utilities created and shared by Linux developers. One such utility is the sysstat tool. The sysstat tool provides statistics for various features of your Linux system. You can find the sysstat tool on the developer's website, sebastien.godard.pagesperso-orange.fr. After downloading the package tarball, what commands would you need to use to compile the software and install it on your Linux server?
    • Solution The sysstat source code is provided using several different package types. The one that creates the smallest package size is the .xz version. At the time of this writing you should download the sysstat‐12.5.1.tar.xz package. Once you have that package downloaded, extract it using the command tar ‐Jxvf sysstat‐12.5.1.tar.xz. This creates the sysstat‐12.5.1 directory. Change to that directory using the command cd sysstat‐12.5.1. The next step is to run the configuration script using the command ./configure. This generates the Makefile file. The next step is to run the make command. After the software compiles, you can install it on your system using the command sudo make install.

Chapter 4: Installing a Red Hat Server

  • Review needed CentOS hardware resources. Determining the hardware resources required for a CentOS installation on a physical or virtualized server helps to ensure a successful completion of the install. It also avoids important project delays due to under‐resourced systems.
    • Master It Imagine that you need to install the CentOS distribution on a physical server that has a dual‐core 2 GHz CPU, 200 GB hard drive, and 2 GB of RAM. Are the server's resources at the recommended level? Why or why not?
    • Solution The server's resources of a dual‐core 2 GHz CPU, 200 GB hard drive, and 2 GB of RAM are sufficient to install the CentOS distribution. The minimum needed is a 1.8 GHz CPU, 10 GB of disk space, and 2 GB of memory. However, they do not meet the recommended level. Because the recommendation requires 2 GB of RAM per logical CPU and this system has a dual‐core CPU, 4 GB RAM is recommended. Thus, this physical server needs more RAM to meet the recommended resource levels.
  • Determine the requirements for a virtual CentOS system. Installing the CentOS distribution as a VM on a host system has different requirements than a direct installation on a physical server. It is critical to evaluate the host system so that the installation is successful.
    • Master It Your project team is planning on installing two CentOS VMs on a host system that has a quad‐core 2.8 GHz CPU, 200 GB of free disk space, and 32 GB of RAM. Are the host system resources sufficient? Why or why not?
    • Solution The host system does have enough resources for two CentOS VMs. The recommendations for a single CentOS VM are a 2 or more GHz dual‐core processor, 16 or more GB of memory, and 30 or more GB of free disk space. However, the host system's OS needs should also be considered before declaring the resources sufficient.
  • Obtain CentOS software. To install the CentOS Linux distribution, you must have the proper ISO image file. This is true whether you are installing it directly on hardware or as a VM. Besides getting the ISO file, you need to ensure that it is not corrupted so that the installation proceeds well.
    • Master It You've downloaded the CentOS ISO image file, but you are concerned that during the download process, file corruption occurred. What should you do to see whether the ISO image file is corrupt?
    • Solution Get a hash value by using a hashing algorithm program that uses the SHA256 algorithm on the downloaded CentOS ISO image file. After you get the hash value, compare it to the hash value listed on the website from which you downloaded the ISO image file. If they match, your ISO image file is not corrupted. If they don't match, you'll need to download the ISO image file again.
  • Conduct an installation of a CentOS distribution. There are several steps to successfully install a CentOS distribution, and it is critical to make sure you complete all of them. Skipping a step can cause problems immediately as well as problems later, if you can even get the system to boot.
    • Master It Your sysadmin team has correctly installed the CentOS software from the ISO image file, and the system booted without any problems. What's the next step?
    • Solution After your sysadmin team has correctly installed the CentOS software from the ISO image file and the system booted without any problems, the team needs to install the update stream via the dnf install ‐y centos‐release‐stream command, using super user privileges. After that is completed, they will need to update the software using super user privileges through the dnf update command.
  • Audit the CentOS distribution's installation. If you had some problems while booting the system, there are a few commands you can use to look at helpful boot messages. But even a successful installation still requires a few additional checks.
    • Master It At your company, you have completed the entire CentOS distro installation process on a new system without any problems, but you then ran into issues the last time the server was rebooted. You need to review the boot messages to track down the problem(s). What log file can you use to view these messages?
    • Solution There are three ways on a CentOS system to look at boot messages. If the system was recently booted, you can use the dmesg command. The journalctl command will also contain boot messages. However, the log file that contains boot messages on a CentOS system is /var/log/boot.log, and it is best to use the less command to view it for finding boot problems.

Chapter 5: Installing and Maintaining Software in Red Hat

  • Recognize Red Hat packages. Developers bundle the files required for an application into a package to make it easier to install. A package management system allows you to easily track what software packages are installed on your Linux system, as well as install, update, and remove them. Red Hat–based Linux distributions use the Red Hat Package Management (RPM) system for managing application software. The rpm command‐line tool provides access to the package management database, allowing you to quickly determine the status of installed packages.
    • Master It The curl software package allows you to easily transfer data using a multitude of protocols (such as FTP, HTTP, and SCP) from the command line. What command would you use to determine whether curl is installed on your Linux system? If the package is installed, what command would you use to view the version and a description of the package?
    • Solution To query the package management database, use the rpm ‐q command. At the command prompt, type rpm ‐q curl. If the package is installed, you will see it listed in the output. To obtain additional information on the installed package, type the command rpm ‐qi curl.
  • Use automated Red Hat package managers. Most Red Hat–based Linux distributions are based on the rpm utility but use different front‐end tools at the command line. Red Hat, CentOS, and Fedora use dnf for installing and managing software packages. The dnf tool automatically installs any software packages required by the package you install.
    • Master It The perf utility allows you to monitor the performance of a Linux system. What command would you use to check whether the perf software is available as an rpm package for your Linux system, and what command would you use to install it? What command would you use to remove it?
    • Solution You would use the dnf command to check whether the perf software package is available, install it, and remove it when necessary. Enter the command dnf list perf to see if the package is available for installation. Then, to install the package, type the command dnf install perf. After you've installed the perf package, remove it using the command dnf remove perf. Remember, you will need to have root privileges to install the package.
  • Manually install Red Hat packages. Not all Linux systems are connected to the Internet, allowing the automated package management tools to connect to a repository. In those situations, you'll need to manually find and download RPM software packages and then use the rpm command to manually install the package. The most common options used to install software are the ‐Uvh options, which will update the package if it's already installed and provide verbose information on the installation progress.
    • Master It What steps would you need to take to install the perf utility if your Linux system is not connected to the Internet?
    • Solution First you would need to download the perf rpm package file. You can do this from another Linux system connected to the Internet by typing the command yumdownloader perf (you don't need root privileges to do this). At the time of this writing, the download file is perf‐4.18.0‐240.1.1.el8_3.x86_64.rpm. Once you have the RPM file transferred to your Linux system, you can manually install it by typing the command rpm ‐Uvh perf‐4.18.0‐240.1.1.el8_3.x86_64.rpm. You will need root privileges to install the software.
  • Install flatpak application containers. Application containers are relatively new in software package management. Containers bundle all of the software required for an application to run, including all files the application is dependent on. This makes containers portable and easily moved between systems. Red Hat Linux–based distributions use the flatpak container format.
    • Master It Cointop is a terminal‐based application for tracking cryptocurrencies. What command would you use to check if there's a flatpak container for it, and what command would you use to install it?
    • Solution To check whether the cointop application container exists in the current repository, enter the command flatpak search cointop. The output indicates that the package exists and displays the software version. To install the container, enter the command flatpak install cointop. Remember that you must have root privileges to install the software.

Chapter 6: Working with the Shell

  • Decode the shell prompt and the manual pages. The prompt is where you enter shell commands. It provides access to the utilities needed to manage a system. In addition, the shell prompt often gives additional information that can help you at the CLI.
    • Master It Imagine that you recently successfully logged in to a Linux system. This particular system uses the CentOS Linux distribution. What sort of items might you see in the shell prompt?
    • Solution Typically, you'll see the dollar sign ($) character in your prompt, as long as you have not logged into the root account. In addition, your username and the system's host name are often also displayed in the prompt within a set of brackets for a CentOS distro. (You may also see a ~, which is a special character that represents your home directory.)
  • Decode the shell prompt and the manual pages. The man pages are an online manual that provide information on various shell utilities, special files, system administrator commands, and so on. They are a source of quick help and can be searched to determine the information you need.
    • Master It You are attempting to become proficient at using the man pages. However, the pager utility it employs is causing you some frustration, so you attempt to learn more about it without leaving the CLI. How can you accomplish learning more about the pager utility used for the man pages?
    • Solution The less utility is the pager used for the man pages. Type man less and press Enter at the shell prompt to view the information on this command from the online manual.
  • Enter, recall, and redirect shell commands. To function efficiently and effectively at the CLI, recalling shell commands is a critical task. A system admin must be proficient at quickly retrieving, potentially modifying, and using previously issued commands.
    • Master It Your main production app on the server is experiencing some performance problems, and you are working as fast as possible to determine and correct the issue(s). You need to recall and reenact a command you used previously. You can see from this history list that it is command 42. What's the fastest way to recall and reuse this command?
    • Solution The fastest way to recall and reuse the command that is numbered 42 in the history list is to type !42 and press the Enter key. These four simple keystrokes will display the command and then reenact it at the CLI.
  • Enter, recall, and redirect shell commands. Being efficient and effective at the command line is more than just being fast. It also requires smart habits. One of these is using command redirection to manage STDIN, STDOUT, and STDERR.
    • Master It You created a nice pipeline of commands to filter and format some needed text file information. You want to view the information but keep a copy of it at the same time. How can you accomplish this?
    • Solution To view produced information as well as keep a copy of it, you'll need to use the tee command within your pipeline. The tee command will allow you to save the information to a designated file, but in addition, it sends the data to STDOUT for viewing (or further processing).
  • Set and use environment variables. Variables help to define your CLI environment. In addition, they allow you to store data in memory that can be easily accessed by any program. Defining a variable, removing a definition, and globalizing a variable are all important management activities.
    • Master It You are creating a user‐defined environment variable for an application. Because of the nature of the application, this variable must be available in subshells. What needs to be done to ensure this happens?
    • Solution When, or immediately after, you define the environment variable, use the export command on the variable. By using export, the variable definition is available to the current parent shell as well as any subshells.

Chapter 7: Exploring Linux File Management

  • Describe how Linux handles files and directories. File management is an important part of the Linux system, and it helps to know the basics of how to manage files from the CLI. This chapter first showed you how to use both absolute and relative filepaths in commands to reference files and directories. Next, it showed the standard Linux file naming conventions used by Linux distributions, along with how Linux uses inodes to handle files.
    • Master It Your boss has given you a list of files he saw being used on the server and wants you to find out what type of files they are. The files are as follows:
      • /usr/bin/grep
      • /usr/bin/zcat
      • /etc/hosts
      • ~/.bashrc
      What command should you use to determine those file types?
    • Solution To determine the file type of a Linux file, you use the file command. From the command prompt, enter these commands:
      • file /usr/bin/grep
      • file /usr/bin/zcat
      • file /etc/hosts
      • file ~/.bashrc
  • Explain the different options available to list files and directories. The ls command is how to list the contents of directories from the command prompt. While there are lots of parameters associated with the ls command, you'll soon find yourself using just a handful of them to view the information that you need.
    • Master It A user on your Linux server has an important project and needs access to the file /share/HR/employees.txt. However, the user doesn't know who owns the file to ask for permission to access the file. What command and parameters should you use to determine the owner of the file?
    • Solution The ‐l parameter of the ls command produces a long‐format listing of the files in a directory. Part of that output shows the owner of the files. Use the command ls ‐l /share to view the file properties and determine the file owner.
  • Submit commands to manage files and directories. The chapter showed you how to use the Linux CLI to create, move, and remove both directories and files. The chapter also went through how to use globbing to specify file and directory ranges instead of single files in the commands, as well as how to use quoting to work with file and directory names that incorporate spaces.
    • Master It You have been assigned the task of creating a new directory for the Engineering team on the Linux server. Under that directory they'd also like to have separate directories for the automotive project group and the truck project group. What commands should you enter to create these directories?
    • Solution To create new directories, you'll use the mkdir command. From the CLI prompt, enter the command mkdir /Engineering (you must have root permissions to create a directory under the root directory). Then to create the project directories, first enter the command mkdir /Engineering/automotive and then the command mkdir /Engineering/truck.
  • Use Linux commands to find files and directories. There are a few common Linux commands used to help find files on the Linux system. The which, locate, and whereis commands can be useful for general searches, but the find command allows you to customize your search by specifying specific file or directory properties to look for.
    • Master It You have been tasked to find all files on your filesystem that are larger than 10 MB in size. What command would you use to easily find those files?
    • Solution The find command allows you to search for files based on file size by using the ‐size parameter. To explore all directories on the server, you'll need to run the command with root privileges: find / ‐size +10MG ‐print.
  • Use Linux commands to compress and archive files and directories. There are many different utilities available for compressing and archiving files in Linux. For archiving files, the gzip family of commands is a popular option. For archiving multiple files into a single file, the tar command is common. You can also compress a tar archive file to facilitate moving it to off‐site storage.
    • Master It What commands should you use to create a backup archive file of the new /Engineering directory and compress it?
    • Solution To archive all the files and subdirectories in the /Engineering directory, enter the command tar ‐cvf engineering.tar /Engineering. Since this directory is at the root level, you'll need to have root permissions to do this. Then to compress the file using the gzip utility, enter the command gzip engineering.tar.

Chapter 8: Working with Text Files

  • Use the vim editor's basic features. The vim editor is one of the most popular text editors in use. Though it can be tricky to use, modifying text files using vim is worth the time to learn. Grasping the basics of the vim editor is all that is needed for a system admin.
    • Master It Imagine that you just opened up a configuration file in the vim editor. You only want to quickly add a paragraph of comments to the top of the file. What editor commands can you employ to accomplish this task quickly?
    • Solution The fastest way to accomplish this task, from what you have learned in this chapter, is to enter into Insert mode by pressing the I key. Once you are in Insert mode, type in the needed paragraph of comments. After the comments are properly entered, leave Insert mode by pressing the Esc key. Now you have three choices to save the needed text modifications and leave the editor: type ZZ, :x, or :wq.
  • Employ the nano editor for everyday text file editing. The nano text editor is a simple and quick editor to use in your daily work. You can quickly get into a file, make any needed modifications, save your work, and go on with other tasks. It's a favorite editor of system administrators because of its simplicity.
    • Master It You need to quickly edit a text file by copying two lines of text from the top of the file to the bottom of the text file. Assuming you are already in the nano editor with this file in the buffer, what editor commands covered in this chapter can you use to accomplish this task quickly?
    • Solution The fastest way to accomplish this task, from what you have learned in this chapter, is to use the Ctrl+K key combination two times to cut the first two lines of the text file. Use the Ctrl+U key combination one time to paste those two lines back into place. To quickly reach the file's bottom, use the Ctrl+V key combination to move one page down, until you reach the bottom. Now press Ctrl+U again to paste the two lines from the editing buffer to current lines. To save your modifications and leave the nano editor, press Ctrl+O one time, and then press Enter to select the filename displayed. Press Ctrl+X to leave the nano text editor and return to a shell prompt.
  • Find data in a text file, and reduce its size. To quickly find files that contain certain data, the grep command is a utility to learn. With its ability to conduct simple or complex searches, locating the information or the files you need is a snap.
    • Master It You need to find all the files in the /etc directory (but not its subdirectories) that contain the word host. The search must be case‐insensitive, and you don't want to see any error messages concerning directory files. Assuming you need to use the sudo command along with your grep command, what will your command look like to conduct this search?
    • Solution Assuming you need to use the sudo command along with your grep command to conduct a case‐insensitive search through all the files in the /etc directory, find the ones that contain the word host, and not display any error messages concerning directory files, the command is as follows: sudo grep ‐d skip ‐i host /etc/*.
  • Back up and organize text file data. The tar utility has been around for a long time. It provides useful options to create archive files. While tar has the ability to compress files on the fly, you can also use the gzip, bzip2, and xz compression utilities to compress tar archive files as well as other files.
    • Master It You created a tar archive file, myArchive.tar, but did not compress it with a tar option, because you needed to verify each file as it was processed with the ‐W option. Now that the archive file was successfully created and verified, what command will you use to compress it to the highest level, and what will the resulting file's name be?
    • Solution The command to compress the tar archive file, myArchive.tar, to the highest level will use the xz compression utility. The command is xz myArchive.tar, and the resulting file's name will be myArchive.tar.xz.

Chapter 9: Managing Hardware

  • Use Linux device driver modules. Similar to other operating systems, Linux uses device drivers to communicate with hardware devices connected to the system. The Linux kernel supports device modules, which allow you to dynamically insert or remove device driver software in the kernel as needed.
    • Master It What command should you use to determine what hardware modules are currently installed on your Linux server?
    • Solution From the command prompt, type lsmod to list all the device driver modules currently installed on the Linux server.
  • Find device information for the system. Besides the physical interfaces, Linux also uses files to communicate with devices. When you connect a device to the system, Linux automatically creates a file in the /dev directory that's used for applications to send data to and receive data from the devices. The kernel uses the /proc directory to create virtual files that contain information about the devices and system status. The /sys directory is also used by the kernel to create files useful for troubleshooting device issues.
    • Master It Your boss just sent you an email asking what CPU and memory are installed in the Linux server. You know that you can find the information in the /proc/cpuinfo and /proc/meminfo files, but what command(s) should you use to obtain that information?
    • Solution The /proc directory files are text‐based, so you can use any text editor to view them, or use the cat command to display the contents on the monitor. Use the command cat /proc/cpuinfo to see information about the CPU, and the command cat /proc/meminfo to see information about the system memory.
  • Work with PCI and USB devices. Linux provides a handful of command‐line tools that are useful when you're trying to troubleshoot device problems. The lsdev command allows you to view the status and settings for all devices on the system. The lsblk command provides information about block devices, such as hard drives and network cards, that are connected. The dmesg command lets you peek at the kernel ring buffer to view kernel event messages as it detects and works with devices. The lspci and lsusb commands allow you to view the PCI and USB devices that are connected to the Linux system.
    • Master It You've just plugged in a USB storage device, but the server doesn't recognize it. What command should you use to determine if the correct device module loaded or if there's some other problem?
    • Solution From the command prompt, type the command dmesg. Look toward the bottom of the output to view the most recent kernel event messages. You should see messages related to the USB device, and what (if any) kernel modules the Linux system tried to load.

Chapter 10: Booting Linux

  • Diagnose the Linux boot process. The process of booting a Linux server is typically free of problems. The firmware performs a POST, the bootloader finds and loads the Linux kernel, and systemd starts the desired services. Each part is critical in getting a system ready to offer services.
    • Master It Imagine that you booted your Linux system, and as you were watching the boot messages, it seemed that several error messages were generated. However, the messages went by so fast, you did not have time to analyze them. The system is now up and running, but you'd like to review those messages to see if they were indeed errors. How can you do that?
    • Solution Though some systems keep boot log files that you can view, since the system just booted, you can use the dmesg utility. This utility displays the kernel ring buffer, which holds kernel messages, and most Linux distributions copy the boot kernel messages into it. If, for some reason, you cannot locate the messages within the kernel ring buffer with dmesg, look to see if your distro keeps boot log files in the /var/log directory, such as boot, bootstrap.log, or boot.log.
  • Configure a bootloader. The GRUB2 bootloader is the most typical and popular bootloader on Linux systems. It provides flexibility and supports advanced features. Often there is little need to make changes to its configuration.
    • Master It After installing Linux on your new server, you notice that the GRUB2 bootloader menu does not display when the system boots. You'd like to modify this behavior. What setting(s) should you look to potentially change and in what configuration file?
    • Solution The settings, called keys, you should look to potentially change are in the /etc/default/grub file. You can directly edit this file with super user privileges. Look for the GRUB_TIMEOUT key and make sure it is not set to 0. If it is, the boot menu will not display, and you'll need to set it to the number of seconds you want the menu to show at boot time. The other key to look at is the GRUB_TIMEOUT_STYLE. If it is set to hidden, the boot menu will not display; you'll need to either comment it out with a hash mark (#) or set it to menu. When you make a change in this GRUB2 configuration file, you'll need to rebuild the grub.cfg file using the appropriate privileges and utility.
  • Interact with a bootloader. At boot time, if configured to do so, the GRUB2 boot menu will display. This allows you to pick different Linux kernels to boot as well as modify parameters set in the menu entries, which is often helpful when troubleshooting problems that adversely affect the system's boot.
    • Master It Your Linux system is currently not booted, and due to some troubleshooting, you need to select the multi‐user.target for the next boot. How can you accomplish this?
    • Solution Assuming the GRUB2 menu is configured to display or is accessible at boot time, you can edit the boot menu choice that typically boots your system. When you see the boot menu, move your cursor to the menu option and press the E key to edit it. Using your arrow keys, scroll down and find the line that starts with the linux16 or linux command. Press the End key or use the arrow key to reach that line's end. Once your cursor is there, press the spacebar and type systemd.unit=multi‐user.target. Then press the B key to boot the system using the new service target.
  • Stop and start services after boot. The systemd daemon and its systemctl utility help in managing system services. They allow you to control what services are started at boot time, start and stop services, and analyze service issues and troubleshoot problems.
    • Master It By accident, the ntpd service was not enabled to start at boot time, and you need to immediately get this service up and running. Assuming you have super user privileges, how can you use systemd to start the service and check that it is indeed started?
    • Solution To start the service, you'll need to use the systemctl command and access super user privileges through either using the sudo command or logging into the root account, depending on your Linux distribution's configuration. The full command to enter at the command line (without the potentially needed sudo) is systemctl start ntpd. Once you have issued that command, you can check on the service's status by typing systemctl status ntpd at the command line and pressing Enter. Look for Active: active (running) in the command's output.
  • Analyze service startup times. The systemd daemon has some special utilities that can assist in tracking down the sources of various problems. One of those utilities is systemd‐analyze, which has several commands you can use in troubleshooting situations.
    • Master It Imagine that you've installed several new services on your Linux server, but they are not starting at boot time. The services are enabled, but something seems to be going wrong with their unit file configurations. What can you do to quickly narrow down the problem?
    • Solution Use the systemd‐analyze verify command on the newly installed service unit files to scan the files and locate any errors. This will assist in quickly determining the problem(s).

Chapter 11: Working with Storage Devices

  • Create Linux partitions on storage devices. Once you connect a drive to the Linux system, you'll need to create partitions on the drive. For MBR disks, you can use the fdisk or parted command‐line tool. For GPT disks, you can use the gdisk tool. When you partition a drive, you must assign it a size and a filesystem type.
    • Master It Your company has just purchased a new external USB 5TB drive that you need to connect to your Linux server to store customer data. How would you create a partition on the drive to be used in the Linux system?
    • Solution After connecting the external drive, determine the device name by using the command dmesg | tail. Next, use either the fdisk or gdisk tool, depending on your server's firmware. For systems using the BIOS firmware, type sudo fdisk /dev/ xxx , where xxx is the device name. Type d at the first prompt to delete the existing partition, and then type n to create a new partition. Press Enter to select the default starting and ending blocks. Type w to save the new partition and exit the fdisk utility.
  • Format partitions with a Linux filesystem and mount them in the virtual directory. After you partition the storage device, you must format it using a filesystem that Linux recognizes. The mkfs program is a front‐end utility that can format drives using most of the filesystems that Linux supports. The ext4 filesystem is currently the most popular Linux filesystem. It supports journaling and provides good performance. Linux also supports more advanced filesystems, such as btrfs, xfs, zfs, and, of course, the Windows vfat and ntfs filesystems. After creating a filesystem on the partition, you'll need to mount the filesystem into the Linux virtual directory using a mount point and the mount command. The data contained in the partition's filesystem appears under the mount point folder within the virtual directory. To automatically mount partitions at boot time, make an entry for each partition in the /etc/fstab file.
    • Master It Format the new external USB storage device you just partitioned so that it can be used by your Linux server, and then mount the new partition in the /data directory on your server.
    • Solution To format the new partition, type the command sudo mkfs ‐t ext4 /dev/ xxx 1, where xxx is the device name you used to create the new partition. After Linux completes the partition formatting, you can manually mount the partition to test it. First, create a mount point by typing the command sudo mkdir /data. Then, you can mount the new partition by typing the command sudo mount /dev/ xxx 1 /data, where xxx is the device name of the partition. After copying and deleting a few test files in the new partition, modify the /etc/fstab text file to automatically mount the new partition by opening it in an editor and adding the following line:

      /dev/ xxx 1 /data ext4 defaults 1 2

      where xxx is the device name of the storage device.

  • Examine storage devices using Linux tools. There are a host of tools available to help you manage and maintain filesystems. The df and du command‐line commands are useful for checking disk space for partitions and the virtual directory, respectively. The fsck utility is a vital tool for repairing corrupt partitions, and it's run automatically at boot time against all partitions automatically mounted in the virtual directory.
    • Master It In your daily system administration checks, you determined that the partition that contains the /home directory has become full. How can you tell which storage device the /home directory is located on and what user account is using up the most space?
    • Solution To determine the partition that contains the /home directory, type the command df ‐h. This displays the currently mounted storage devices, along with their capacities and how much space is currently being used. This allows you to determine if the /home directory is on its own partition or under the root (/) partition. To determine what user account has the most data stored, type the command du /home. This displays the disk space used by each user's Home directory.

Chapter 12: Configuring Network Settings

  • Find and examine the network configuration files for your server. Linux stores network connection information in configuration files. The installer program that runs when you install the Linux software typically asks you for the network configuration information and creates these files automatically. However, it's a good idea to find where these files are located on your Linux system in case anything goes wrong or you need to change anything. Ubuntu servers store the configuration files in the /etc/netplan directory. Red Hat servers store the configuration files in the /etc/sysconfig/network‐scripts directory. Files in those directories define the network settings for each interface.
    • Master It You've been asked to help a colleague solve a network problem on an Ubuntu Linux server. What file would you look at to determine the current network configuration settings?
    • Solution From the command line, change to the netplan directory by typing the command cd /etc/netplan. List the files in that directory by typing the command ls ‐l. View the current network configuration by using the cat command on each of the configuration files in that directory. For example, you can view the configuration defined in the 00‐installer‐comnfig.yaml file by typing the command cat 00‐installer‐config.yaml. Note the interfaces listed, along with the IP addresses assigned.
  • View and change network configuration settings using command‐line tools. If you must configure your network settings from the command line, there are a few different tools you'll need to use. For both wireless and wired connections, you need to use the ifconfig or ip command to set the IP address and netmask values for the interface. You may also need to use the route command to define the default router for the local network. For wireless connections, you'll need to use the iwconfig command to set the wireless access point and SSID key.
    • Master It Customers can't connect to your Red Hat Linux server, but the server is running, and the network cable is plugged in. What commands should you run to view the status of the network interface and make it active if it's down?
    • Solution To view the current status of a network interface, type the command ip address show. If the status of the interface enp0s3 shows DOWN, you can make it active also using the ip command. Type ip link set enp0s3 up at the command prompt to make the interface active. Then type ip address show at the command prompt and note the status of the network interface to ensure it's active.
  • Troubleshoot common network problems. Once your network configuration is complete, you may have to do some additional troubleshooting for network problems. The ping and ping6 commands allow you to send ICMP packets to remote hosts to test basic connectivity. If you suspect issues with hostnames, you can use the host and dig commands to query the DNS server for hostnames.

    For more advanced network troubleshooting, you can use the netstat and ss commands to display what applications are using which network ports on the system.

    • Master It The web administrator for your company called you to say none of the customers can connect to the company's website running on an Ubuntu server. What commands should you use to see first if the Ubuntu server can communicate with remote hosts and then that the web server software is listening for HTTPS connections?
    • Solution To first check for network connectivity from the Ubuntu server, type the command ping www.linux.org . You should get a response from the remote server, indicating that your server is communicating. Next, to check for the web server, type ss ‐anpt from the command line to view all open TCP sockets on the server. You should see a line with the local address/port of 0.0.0.0:443, indicating that a web server is listening on TCP port 443 for HTTPS connections. If not, it may be time for the web administrator to restart the web server software!

Chapter 13: Managing Users and Groups

  • Change a file's owner. A file or directory owner setting allows certain control over that file or directory. Some control is dictated by the permissions set at the owner level, but also only certain commands can be used on a file or directory by its owner. For example, you cannot change the group on a file if you do not own it (or don't have super user privileges).
    • Master It Imagine you are either logged into the root account or have access to super user privileges, and you have a copied a file projectData.txt to the lradford home directory. This user will need access to the file, which includes being able to change its group. What command syntax should you employ to accomplish this task?
    • Solution To change the owner of the projectData.txt file to the lradford user, you'll need to use the chown command. The exact syntax to accomplish the task, if you are logged into the root account, is chown lradford projectData.txt. If you are using super user privileges to accomplish this task, the syntax is sudo chown lradford projectData.txt. It's a good idea to double‐check that the change of ownership was successful by issuing the command ls ‐l projectData.txt when you are done with the chown command.
  • Create user accounts. The useradd command is a command at the basic system level that allows you to create new accounts on the system. The needed various options are often determined by settings in the /etc/login.defs and the /etc/default/useradd files.
    • Master It You need to create a new account for a newly hired project manager, Takoda Puddle, who needs access to the Bash shell on your server. In your system's /etc/login.defs, you find that CREATE_HOME is defined as no, and UID_MIN is set to 1000. Within the /etc/default/useradd file, SHELL is defined as /bin/bash, and SKEL is set to the /etc/skel directory. The user's home directory should end up being /home/tpuddle. Assuming you are either logged into the root account or have access to super user privileges, what is the command syntax to create an account for the new project manager?
    • Solution To create an account, you'll need to use the useradd command. With the current system configuration settings, and if you are logged into the root account, the command is useradd ‐md /home/tpuddle tpuddle. If you are using super user privileges to accomplish this task, the syntax is sudo useradd ‐md /home/tpuddle tpuddle. You don't necessarily have to add a comment field through the use of the ‐c option. It is wise to double‐check that the account addition was successful by issuing the command getent passwd tpuddle when you are done with the useradd command. However, don't forget that you also need to create a password for this new account using the command passwd tpuddle or sudo passwd tpuddle !
  • Modify a user's password. The passwd command along with the correct privileges allows you to create an account's password. However, besides just creating a password, you can change an account's password, delete its password, force a user to change their password at the next login, and so on. In addition, without any extra privileges, you can modify your own account's password through the passwd command.
    • Master It You are the system administration for several Linux servers at your company. An HR representative and your boss have come to your office to let you know that a fellow employee, Jay Snow, is being fired from the company. They have asked you to lock the jsnow account while they wait. What command do you enter to lock this account?
    • Solution The passwd command will allow you to lock accounts if you are logged into the root account or have super user privileges. The syntax needed if you are logged into the root account is either passwd ‐l jsnow or passwd ‐‐lock jsnow. If you are using super user privileges, use the same syntax but with sudo before the rest of the command. Keep in mind that if the user jsnow is already logged into the system, this command will not remove the user jsnow. It only prevents the user from logging in again to the system after logging out.
  • Find an environment file. Environment files on your system consist of both global files and local user files. Which environment files reside on a system depends on the Linux distribution being used. Global files reside in the /etc/ directory, and local user files reside in each user's home directory after being copied from the /etc/skel/ directory, if your system is configured to do so.
    • Master It You are the system admin for a development system. A programmer recently asked how a particular environment variable can be redefined, not only when they log into the system, but also when they run various Bash shell scripts on the system. What should you do or suggest?
    • Solution Because a noninteractive shell (also called a non‐login shell) is started when a user runs a Bash script, the best place to redefine this particular environment variable is in the user's .bashrc file. However, you should determine if other developers on the system need the same thing, and if they do, put the variable in a global environment file instead.
  • Delete a user group. Managing groups of users on a Linux system is an important task. Several groups are permanent once created, but other groups, such as those related to special work projects, may come and go. You need to know how to create, modify, and even remove a user group.
    • Master It A small development project, abc123, on the system you administer has come to an end. The project files are no longer needed by the former team, and you've been asked to change the group on these project files to the manager group. Once you've completed that task, you'll need to remove the old abc123 project group. What is the command to accomplish this removal task?
    • Solution Use the groupdel abc123 command on the system to remove the abc123 user group. You'll need to be logged into the root account or have access to super user privileges to successfully complete this task.

Chapter 14: Working with Processes and Jobs

  • Monitor programs running on the server. You can view the running applications and the resources they consume by using the ps command. There are many different ways to view process information using the ps command, allowing you to customize the display exactly how you like. For real‐time monitoring of applications, use the top command. With the top command, you can view a real‐time display of applications, their system state, and the resources they consume; plus it allows you to sort the display based on many different features.
    • Master It Your server users are complaining that the server seems slow today. How can you tell what programs are using the most resources on the server?
    • Solution From the command line, type top to start the interactive display of processes. By default, top sorts the display based on CPU usage. Note the two or three processes using the most CPU resources.
  • Manage programs running on the server. The nice command allows you to start an application at a different priority level than the applications that are already running. This allows users to run applications in the background at a lower priority or allows the system administrator to start applications with a higher priority. With the renice command, you can change the priority of an application that's already running. If an application causes problems and needs to be stopped, you can use the kill command, but you need to know the PID assigned to the application by the system. The pkill command is customized for stopping applications by their name instead of the PID.
    • Master It A software developer has contacted you to tell you that she made a coding error in her program named inventory, and now it's stuck running in an endless loop on the system. What command(s) should you run to find and safely stop the runaway program?
    • Solution First try to send a HUP signal to the runaway program so it can gently stop by typing the command sudo pkill ‐‐signal HUP inventory. Check if the program has stopped by typing the command ps ‐ef and looking for the program. If the program continues to run, you must send a KILL signal to stop it. Type the command sudo pkill ‐‐signal KILL inventory.
  • Schedule programs to run in the future. Linux provides a couple of different ways for you to schedule programs to start at a future time or even a different date. The at command lets you schedule in individual program to run at a specific time/date. If you need to schedule a program to start on a regular schedule, use the crontab command to add the program to the system cron table. You must specify the schedule format to tell Linux when to start the program.
    • Master It The software developer has worked out all of the bugs in her inventory program and would like for it to run automatically every month on the first of the month at 1 AM. The program is stored in the /applications directory. What command should she use to make that happen?
    • Solution To schedule a recurring program, add it to your user cron table using the crontab command. To edit your user cron table, type crontab ‐e. In the editor, go to input mode by typing i and then enter the schedule and command to run. To run the inventory program at 1 a.m. on the first of every month, type the following:

      00 1 1 * * /applications/inventory

      Save the entry by typing :qw!.

Chapter 15: Managing Log Files

  • View journal entries. The journalctl program is needed to view journal file entries, because unlike some logging utilities, systemd‐journald doesn't store events in text files. Instead, it uses its own binary file format that works similar to a database. Thus, you cannot use the typical programs used to view text files, such as cat, head, or tail, to view journal file entries.
    • Master It You're an administrator on a rather under‐resourced server with problems concerning two different apps that run on it. The problems are sporadic, but seem to start occurring during the app's peak use time. You decide to keep an eye on the error messages being logged to the journal during that time. What's the most efficient journalctl command(s) to use in this scenario?
    • Solution To keep an eye on the error messages being logged to the journal during the problematic apps' peak usage time, it is the most efficient to set a watch on the journal file. The journalctl command that allows you to see the entries as they are being logged to the journal is journalctl ‐f or journalctl ‐‐follow. This is similar to using the tail ‐f command on a text‐based log file to watch as messages are added to it.
  • Maintain the journal file's size. The systemd‐journald journal file(s) can get rather large. Because the various services on the system are sending messages to this file, if multiple events are occurring on a regular basis, disk space can quickly become consumed. It's important to make some decisions on journal file size limits prior to lack of disk space becoming a critical emergency issue.
    • Master It Imagine you are administering a new server and are currently accessing the persistent systemd‐journald journal files. After running the journalctl ‐‐disk‐usage program, you've made some decisions on journal file size limits and determine a rotation schedule, which includes an archival process for the old files. Which directives should you consider modifying in the /etc/systemd/journald.conf file to match your decisions concerning this and prevent a critical emergency issue with disk space due to journal files?
    • Solution Within the /etc/systemd/journald.conf file, the three directives related to persistent journal file size are SystemKeepFree, SystemMaxFileSize, and SystemMaxUse. Reviewing these particular directives and modifying them to meet your decisions will work. The other directives related to journal file size are for volatile journal files and do not apply in this case. You also will want to turn off the MaxFileSec directive by setting it to 0, because this setting is not needed when size limitations are in place.
  • Make a journal file continuous. On some distributions, the journal file entries are stored in the /run/log/journal directory. The /run/ directory and its contents are deleted when a system is shut down, so any journal entries are lost at that time. It is typical to change this behavior by modifying a directive in the /etc/systemd/journald.conf file to force systemd‐journald to keep entries in a journal that is not removed when the system is shut down or reboots. The /var/log/journal directory is used in these cases to store the journal file(s).
    • Master It Currently, the servers you administer have temporary journal files, which are lost when these systems are shut down or reboot. You'd like to make these journal files continuous and manage their size through rotation and archival settings in the systemd‐journald configuration file. What directive should you change in the configuration files on these servers, and what should you set it to?
    • Solution To force systemd‐journald to keep entries in a journal that is not removed when the system is shut down or reboots, you'll need to modify the Storage directive in these servers' journald.conf file in their /etc/systemd/ directory. If the /var/log/journal directory already exists (or you plan on creating it), you can set the Storage directive to auto. Otherwise, you'll want to set it to persistent to create the /var/log/journal directory, if it is not there already.
  • Modify a logging level. The legacy rsyslog application uses the syslog protocol. It uses either a single configuration file, /etc/rsyslogd.conf, or a combination of that configuration file and additional configuration files within the /etc/rsyslog.d/ directory. Modifying the rsyslog application's configuration is fairly straightforward with the facility . priority action syntax in its configuration rules.
    • Master It You are the system admin for a server that uses the legacy rsyslog application for its event logging. You'd like to direct the rsyslogd program to send the following severity level of events for all systems to everyone: crit, alert, and emerg. What do you need to do?
    • Solution First, you'll need to find the proper configuration file in which to set the configuration for that rule. Check to see if the rules that define how the program handles syslog events received from the system, kernel, or applications are set in the /etc/rsyslogd.conf file. If not, check for them in the files within the /etc/rsyslog.d/ directory. Once you find the correct configuration file, look for a rule similar to the following:
      # Everybody gets emergency messages
      *.emerg                 :omusrmsg:*
      

      If you find this rule, you'll only need to change emerg to crit, because rsyslogd will log all events with the crit severity or higher (alert and emerg). If you don't find this rule, add a similar line, changing emerg to crit.

Chapter 16: Managing Printers

  • Install and configure the CUPS software. Most Linux distributions provide the Common Unix Printing System (CUPS) to make it easy to connect, use, and even share printers with your Linux system. Both Ubuntu and CentOS provide the CUPS software in their default software repositories, so you can install CUPS using apt in Ubuntu, or dnf in CentOS. Once you install the software, you'll need to make a few configuration changes to allow remote clients to use CUPS, especially if your server doesn't provide a graphical desktop. You'll also need to ensure your administrator user account has access to the CUPS administrator features by adding it to the appropriate user group.
    • Master It Your boss wants to allow all of the clients on your local network to be able to use the CUPS web interface to manage their own print jobs, but wants to restrict access to the CUPS administrator privileges to just your workstation, which has the static IP address of 192.168.1.100. What do you need to change in the cupsd.conf configuration file to accommodate that configuration?
    • Solution In the cupsd.conf configuration file, you'll first need to set the root location to allow connection from any client on the local network by adding the line ALLOW @LOCAL to the <Location /> block. However, in the <Location /admin> block, add the line ALLOW from 192.168.1.100 to only allow your workstation to connect to the administrative features in CUPS.
  • Create printers on your Linux server. The CUPS web interface provides an administration section that allows you to create new printers for the Linux server. Clicking the Add Printer button starts a wizard that walks through the process of defining and creating the printer. CUPS has the ability to automatically detect both local and network printers and can aid you in setting them up on the system.
    • Master It The network team has installed a new printer on the network, but customers are complaining that their print output keeps getting mixed up with others. How can you assist in separating each print job sent to the printer using CUPS?
    • Solution From the CUPS web interface, select the Administration tab, and then click the Add Printer button to define a new printer. Select the network printer, and then select the appropriate drivers. On the Default Options page, click the Banners tab, and select the option to print a banner at the start of each print job.
  • Manage printers and print jobs submitted by clients on your local network. The CUPS web interface allows you to manage both printer settings as well as print jobs submitted to the printer. Click the Printer tab from the main CUPS web page, and then select the printer you want to manage. On the Printer page, you can select from several different printer administration functions, such as modify the printer settings, delete the printer, pause print jobs, and cancel print jobs. Under the printer settings is also a list of jobs currently assigned to the printer. From here, you can select a job to either cancel it or move it to another printer.
    • Master It Customers are complaining that someone sent a large print job to the printer yesterday that's not printing, and blocking any other print job from processing. What process do you need to perform to solve the problem?
    • Solution From the CUPS web interface, select the Printers tab, and then click the name of the printer the job was sent to. On the Printer page, you will see a list of the jobs currently assigned to the printer for processing. The offending print job will be listed first and possibly show the error that's causing the issue. Click the Cancel job button to remove the job from the printer queue so other jobs can process.

Chapter 17: Exploring Ubuntu Security

  • Safely escalate privileges to accomplish tasks. Ubuntu implements privilege escalation through the sudo command. This method allows administrators to log into their standard Linux user account and run programs with higher‐level administrator privileges, as needed.
    • Master It You're an administrator on an Ubuntu Linux system. There is a new member on your team who will be performing the same administrator duties that you do. This team member will need to use sudo to safely escalate privileges when needed. The record in the /etc/sudoers configuration file that provides your account with privilege escalation is the following: %sudo ALL=(ALL:ALL) ALL. What do you need to do to set up this new team member to use the sudo command?
    • Solution To set up this new team member to use the sudo command and have the ability to perform the same administrator duties that you do, you'll need to add the team member's account to the sudo group. To do this, you'll need to use the usermod ‐aG command covered in Chapter 13, “Managing Users and Groups.”
  • Use OpenSSH to connect to remote systems. OpenSSH provides an encrypted means for communication when you connect over a network to a remote server. Ubuntu Linux typically has OpenSSH installed by default, but you may need to perform additional configuration steps to customize it for your secure communication requirements.
    • Master It Imagine you are administering an Ubuntu server that already uses OpenSSH. Connections are set to use key pairs instead of passwords for command‐line access. While you currently have rsa keys, the decision was made to switch to ecdsa key pairs, which don't exist at this time on the system. What steps do you need to take in order to implement this functionality for your accounts on the systems?
    • Solution To implement OpenSSH connections to use ecdsa key pairs, the first step is to log into a client system and generate ecdsa keys via the ssh‐keygen ‐t ecdsa ‐f ~/.ssh/id_ecdsa command. After that, copy the new public key to the server system's ~/.ssh/authorized_keys filesystem using the ssh‐copy‐id utility. Be aware you will need to do these steps for each client system.
  • Manage Ubuntu MAC protection software. AppArmor is the MAC protection system used on Ubuntu. This software controls the files and network ports each application accesses through access lists, which are text‐based files called profiles. These files reside in the /etc/apparmor.d/ directory and are typically installed for a particular application, when it is installed.
    • Master It You're an administrator on an Ubuntu Linux system that uses AppArmor as its MAC system. All of the AppArmor utility and profile packages are installed. The primary application on this system is run only on Tuesday through Sunday of every week. The development team would like to test a large app modification on Monday. What should you do to the firewall to log potential firewall violation issues with the modification, but not stop the application from accomplishing its test tasks?
    • Solution To log potential MAC violation issues with the modification, but not stop the application from accomplishing its test tasks, use the aa‐complain command on the application's profile. You will also need to do this on any applications' profiles that this modified application uses on the system. By putting the various profiles into complain mode, any violations of the profile are logged, but not blocked. In addition, check all the profiles for deny rules, which will block violations whether or not the profile is in complain mode.
  • Configure the Ubuntu firewall. Ubuntu's software application firewall is host‐based and works at the Network layer. It uses an ACL to identify which network packets are allowed in or out of the system. Ubuntu's UFW uses netfilter's services and is configured with the ufw command‐line utility.
    • Master It You are the system admin for several Ubuntu servers that reside in server rooms spread across the world. To access these servers remotely and securely, you use OpenSSH. However, you've decided not to use the default port 22 for this service. Instead, you are going to use a different and available port number. What do you need to do to the firewall on all the Ubuntu servers to make this work?
    • Solution You'll need to open traffic in the firewall for the chosen OpenSSH port. Just as an example, say you'll use port 1138, instead of 22, for OpenSSH services. To open the port, type in sudo ufw allow 1138/tcp at the servers' command line. It is wise to only allow traffic to this port from any of the client systems, so also consider adding the from source , where source is either a set of IP addresses or subnets of the client systems from where you are logging in. If UFW firewalls are implemented on the client systems, you'll need to perform similar commands on them.

Chapter 18: Exploring Red Hat Security

  • Control access from the root user account. The Red Hat server distribution enables the root user account by default, which could cause security issues if not managed correctly. You should always check for uses of the root user account by using the aulast command to view the logins on the server. Depending on your environment, you may also want to restrict the root user account from accessing the server from a remote device. You can do that using the /etc/ssh/sshd_config configuration file in OpenSSH. Finally, if you do allow root user access on your system, it's a good idea to restrict the idle time at the command prompt. You do that using the TMOUT environment variable.
    • Master It Your boss came into your office saying that someone deleted his user account on the server and wants to know how he can find out who did it. He thinks it happened yesterday afternoon. What command should you use to see who logged in with the root user account on the system during that time period?
    • Solution From the command prompt as root, type sudo aulast | grep root. This displays the times the root user account logged into the system and, if from a remote device, the IP address of the device.
  • Manage the SELinux environment. While standard Linux file and directory permissions can help with locking down files and directories, they can't provide mandatory access controls required for some environments. The SELinux package allows you to write policy rules that control access to not only files and directories but also applications and network ports. This helps provide MAC‐level of security on the Linux server.
    • Master It After you enabled SELinux on the Red Hat server, the web administrator notified you that his web application can't connect to the MySQL database anymore. What commands should you use to troubleshoot and fix the problem?
    • Solution First, you'll need to find out if there's a security policy that manages the database connection from the web server. From the command prompt, type sudo getsebool | grep httpd. From this list, you see the policy httpd_can_network_connect_db is turned off. To enable it, from the command prompt, type sudo setsebool ‐P httpd_can_network_connect_db 1.
  • Control network access using firewalld. In today's world, managing access to the Linux server is a must, especially if your Linux server has some type of connection to the Internet. Red Hat servers utilize the firewalld program to block unwanted network connections and allow approved connections on the network. The firewalld program defines connections as rules and applies those rules to specific zones. You can then assign network interfaces to the zone that supports the network connections needed.
    • Master It The database administrator contacted you to complain she just installed MySQL on the Red Hat server, but none of the remote clients can connect to it. She indicated that MySQL uses TCP port 3306 for communications by default and just assumed it would be open on the server. What commands should you use to troubleshoot and fix the problem?
    • Solution First, determine the zone the network interface card is assigned to. Open the command prompt and type sudo firewall‐cmd ‐‐list‐all. This displays the active zones on the server and what network interface is in each one. Look for the zone the active network interface is assigned to, and enable TCP port 3306 for it by typing sudo firewall‐cmd ‐‐zone=public ‐‐permanent ‐‐add‐port=3306/tcp. Then reload the configuration by typing sudo firewall‐cmd ‐‐reload.

Chapter 19: Writing Scripts

  • Create basic scripts to automatically run commands. Basic Bash shell scripts require a few, but important, items. For example, on the first line of a shell script file, you use special syntax that indicates to the current shell which shell to use for running the script. You also need to include the commands you want to run within the script. In addition, it's helpful for the script users, even if it is only you, to have the script produce messages so that the script user knows what is happening within the script.
    • Master It You have written a basic Bash shell script that assists in viewing who is logged onto the system currently as well as looking at log files that indicate who logged in previously to the system. For some reason, the script is not functioning properly. You are getting error messages as if the Dash shell is running the script, but you want the Bash shell to run the script and are even using the bash command to run it. What is most likely the problem?
    • Solution If you are getting error messages as if the Dash shell is running the script, the most likely cause is incorrect code on the first line of your shell script. If the first line uses #!/bin/sh, your script will be run by whatever shell the /bin/sh file points to. On some systems, this file points to the Dash shell. Modify the script to use #!/bin/bash in its first line.
  • Use variables in shell scripts. You can integrate data into your shell script commands to process information using variables. Variables allow you to temporarily store information within the shell script for use with other commands in the script. Variables can be environment variables, user‐defined variables, or even data passed to the script through the use of parameters.
    • Master It Imagine you are writing a shell script to assist in the deletion of individual user accounts. This script will be used by an admin intern from the local college, so it needs to include the username of the account to delete in a variable. How will you accomplish this?
    • Solution To create a shell script to assist in the deletion of individual user accounts, which requires the username of the account to delete it, you can use the $1 variable in the script. This will allow the intern who is running the program to run the script and include the username as a parameter to the shell script. However, you may want to include some additional safeguards in your script to avoid typographical errors on the username and prevent the intern from entering valid but incorrect usernames into the script.
  • Provide compound conditions to guide scripts. Compound conditions are ones in which two or more conditions need checking so that the script can decide which commands to execute or the course of action to take. You can handle compound conditions through multiple if‐then statements or, if there are only two conditions to check, through the use of Boolean logic to combine the tests.
    • Master It You are writing a script that needs to check a compound condition. In this case, the machine0087.log file's existence needs to be checked. In addition, a counter variable, logCount, must be examined as well. If the file exists and the counter has reached 100, the script should exit. What if‐then statement(s) should you write to make this test as consolidated as possible?
    • Solution To exit the script if the machine0087.log file exists and the logCount counter has reached 100, you'll need to use Boolean logic in your if‐then test statement as follows:
      if [ -f machine0087.log ] && [ $logCount -eq 100 ]
      then
          exit
      fi
      

      You could also use the ‐e test on the machine0087.log file, and it would be best to use the file's absolute directory reference, instead of a relative one.

  • Determine the best loops to use in a script, when needed. There are times in a shell script that you need to repeat a set of commands until a specific condition has been met. This need occurs when processing all the files in a directory, all the users on a system, or all the lines in a text file. The loop types available for Bash shell scripts include for, while, and until.
    • Master It You are writing a shell script that needs to process lines in a text file. One particular line toward the bottom of the file contains only the text stop here. You are reading in the text file lines one at a time, keeping only the line's text, and putting it into the variable fileLine. What type of loop should you use in your script, and what is the syntax of that loop's first line?
    • Solution While you could use any type of loop in your script, most likely the easiest one to write for this particular set of conditions is an until loop. The format of the loop's first line would look like this:
      until [ $fileLine = "stop here" ].
      
  • Create and use functions in shell scripts. User‐defined functions are blocks of script code that you assign a name to and reuse anywhere in your shell script. When you need your script to execute that block of code, you call the function using the name you assigned to it. This provides scripts with the ability to keep blocks of code within a single location, so any changes that the code needs are done in only one place in the script.
    • Master It As you are creating a shell script, you recognize that you are writing these four lines of code over and over again:
      echo "Error in processing file, $1."
      echo "Check that the $1 file exists and contains +data."
      echo "This script will now exit…"
      exit
      
      Properly write a function named errorMessage that will allow you to turn these four lines of code into a single line (except for the function declaration) throughout the script.
    • Solution A function named errorMessage that will allow you to turn the four lines of code into a single line (except for the function declaration) throughout the script would look like this:
      function errorMessage {
      echo "Error in processing file, $1."
      echo "Check that the $1 file exists and contains data."
      echo "This script will now exit…"
      exit
      }
      

      or this:

      errorMessage () {
      echo "Error in processing file, $1."
      echo "Check that the $1 file exists and contains data."
      echo "This script will now exit…"
      exit
      }
      

      and then would be called by simply using errorMessage in place of those four lines of code throughout the script.

Chapter 20: Managing Web Servers

  • Determine the right web server for your environment. Web servers are the heart of the Internet, and Linux is the main server platform used for supporting them. There are many different web server software packages available for Linux, but the two most popular are Apache and nginx. The Apache web server is the oldest and most popular web server package. It is highly customizable and has defined many of the features expected from web servers. The nginx web server is relatively new to the web server game but is a powerful player. It can support larger client bases on the same physical hardware than Apache, making it ideal for high‐traffic environments. It also has made a name for itself in the reverse web proxy world. A reverse web proxy sits in front of multiple back‐end application servers and provides load balancing for clients.
    • Master It Your company wants to implement load balancing using several web servers to host your corporate website. The website uses PHP to retrieve data stored in a database to produce the website content. Describe a good web server solution to meet these requirements.
    • Solution The nginx web server is good at providing reverse proxy services and handling multiple clients, while the Apache web server is good at processing PHP code and communicating with a database. A good solution would be to use an nginx web server as the main server and to use several Apache web servers in a load balancing configuration behind the nginx web server.
  • Install and configure the Apache web server. The Apache web server is available for installation from the standard Ubuntu and Red Hat repositories. Adding features to the Apache web server often requires installing additional packages. Customizing the Apache web server is as easy as changing configuration settings. You use the UserDir directive to allow users to create their own websites on the server, separate from each other. You use the VirtualHost directives to host web pages for multiple domains on the same physical server. You can also implement client authentication on your website, requiring clients to log in to access content. The Apache server also provides for secure transactions by using HTTPS and encrypting network traffic between the client and the server.
    • Master It You've received a frantic phone call from the company web administrator informing you that after changing the configuration file she can't start the Apache web server, it keeps failing. What command should you use to see why the Apache server won't start?
    • Solution From an Ubuntu server command line, type sudo apache2ctl configtest, or from a Red Hat server command line, type sudo apachectl configtest. The configtest option parses the Apache configuration file and displays any errors that would prevent the Apache web server from starting.
  • Install and configure the nginx web server. With the growing popularity of the nginx web server, both the Ubuntu and Red Hat server repositories include it. After installing nginx, you can customize it by changing the nginx.conf configuration file. Many of the configuration directives for nginx are similar to the Apache, so migrating from one to the other is a fairly simple process.
    • Master It Customers are complaining that they can't connect to your corporate website running on the nginx web server. What commands can you use to check the status of the server and restart it if necessary?
    • Solution To check the status of the nginx web server, you'll need to use the systemctl command. From a command‐line prompt, type sudo systemctl status nginx. If the status shows that the server is stopped, start it by typing the command sudo systemctl start nginx.

Chapter 21: Managing Database Servers

  • Understand basic DBMS components. A database management system typically consists of a database engine, the data files for the database, and a query‐language interface, which typically uses standard SQL or something relatively compliant with standard SQL. These components assist in fulfilling the need to manage complex connections between individual data items.
    • Master It You have installed an RDBMS on your Linux system. The various applications that access this database reside on different servers across your local network. However, these servers are in different buildings on your company's campus. Recently, the power was cut to the campus due to a mistake by the power utility supply company. You did not have any backup power systems in place, and all your servers went down. Now that the power has been restored and your systems are back up and running again, none of the applications can access the database. The system on which your RDBMS resides is running (the primary database server), and there are no network firewall problems. What should you investigate next to resolve this issue?
    • Solution The database engine typically runs in the background as a daemon on Linux and provides access to the database data to local and, if configured, remote applications. The next item to investigate is whether the RDBMS daemon is currently running. If it is not, use super user privileges and the systemctl command to start the service; then enable the service so that the next time the database server reboots, the RDBMS daemon is started automatically.
  • Create user accounts within MariaDB. Managing and querying data within a MariaDB server is accomplished through database user accounts. Typically, an account is created for every user account on the Linux system that needs to manage and/or query data in the database. It is also considered a good practice to limit user access to only those databases associated with applications the user can access.
    • Master It Imagine you are the system administrator on a new Linux server. You have completed the installation of MariaDB and need to create a database for the application that will be using MariaDB as its RDMS. What are the next few steps to take, after starting the MariaDB service and enabling it to start at system boot?
    • Solution Your next major step is to create a database administrator account for yourself so that you do not have to use super user privileges or the root account to create the database. To do this, you will need to escalate your privileges to super user and issue the mysql command to enter into the SQL interface. After that, your next step is to issue the appropriate CREATE USER command along with the username of the account, the hostname of the system (optional), and a password to access the SQL interface of MariaDB. After you have completed creating this account, you should log out of the mysql interface and log back in using the new credentials. Now that this is accomplished, you can move forward with creating the database.
  • Use SQL to query a MariaDB database. MariaDB uses several standard SQL commands, plus a few more, to manage databases, create tables, populate them with data, and query that data. The times that may cause you a little heartburn are when you need to use SQL commands that fall outside of the standards. However, that is fairly rare when interacting with the MariaDB SQL interface.
    • Master It You have recently created a table named ArtificialFlowers within the Florist database. The artificial flower records listed in this table have only a few fields: ProductID (which is the primary key), FlowerName, FlowerColor, and StemColor. The store manager of the florist shop wants to check the data you've entered into this table. What steps should you take after you have logged into the MariaDB server's command line where this data exists?
    • Solution The first step is to log into the MariaDB's SQL interface, using your database server username and password. Next, in the SQL interface, connect to the database using the USE Florist; command. After that, you can display the data to the screen, using the SQL command SELECT * FROM ArtificialFlowers ;. Keep in mind that if there is a lot of data in this table, it will scroll off the screen. The store manager may prefer a report from which they can view the data as opposed to looking at it on your computer screen.
  • Install PostgreSQL on Linux. The PostgreSQL (also called Postgres) RDBMS has some features that make it popular in segments of the Linux community. For instance, it has data reliability structures and generally supports standard SQL, with a few exceptions. Installing PostgreSQL can be a little tricky, as its installation process is slightly different depending on the Linux distribution you are using.
    • Master It You are a system administrator for a Linux system whose customers want to use the PostgreSQL RDBMS on the system. This particular system is a Red Hat Linux distribution. What steps do you need to take to accomplish this task?
    • Solution The package name for PostgreSQL on a Red Hat or Red Hat–based system is postgresql‐server. So, to install it, you'll need to escalate your privileges to super user status and issue a command similar to dnf install postgresql‐server. After the installation, to finish this task, you will need to again escalate your account's privileges and run a PostgreSQL database initialization by issuing the following command with super user privileges: /usr/bin/postgresql‐setup ‐‐initdb. When this is completed, be sure to enable PostgreSQL to start at boot, and start the daemon.
  • Set up roles within PostgreSQL. Roles are used to access and manage data within a PostgreSQL server. It is considered a good practice to determine what privileges a user needs for using a PostgreSQL database and then create a role with the appropriate privileges. This structure provides protection for the data and appropriate security tracking of database users.
    • Master It You are the database administrator of the PostgreSQL database on your Linux system. Your database user role is named admin. This role has super user privileges in the database as well as the ability to create roles and databases. What, if any, changes should be made to your account to improve the security levels of administering this database?
    • Solution Providing permissions of CREATEROLE and SUPER USER to other database roles besides postgres is considered risky. It would be best to remove the CREATEROLE and SUPER USER from the admin role, and only use the postgres account for those functions. While it is troublesome to have to log in to the postgres account to add roles to the database, it does provide an extra layer of security around the data.

Chapter 22: Exploring the Virtualization Environment

  • Understand basic hypervisor components. Hypervisors are used to create and manage VMs and are generally categorized as Type 1, Type 2, or hybrid. There are pros and cons associated with each category. For example, when creating a VM using a Type 2 hypervisor, host machine resources need auditing to determine if the VM's requirements can be met. While a Type 1 hypervisor eliminates the need for the physical host's OS, it still can consume significant resources to run VMs. Creating a VM using hypervisor software is done using many different methods, such as P2V, cloning, using templates, or employing OVF files.
    • Master It You need to create and deploy several VMs that contain the same brand new application and need the same environment. After reviewing the various options, which method would you choose to create these VMs and why?
    • Solution Almost any method will work to create multiple VMs that contain the same application and need the same environment. However, using a P2V method is not possible, since the application is new and not already deployed on a system. Cloning is most likely the most time‐saving method, as long as you properly handle issues, such as the NIC MAC address and machine IDs. A template is also a logical choice that will allow you to quickly create the needed VMs. Creating OVF files (or compressing them into a single OVA file, if needed) is also a reasonable option for this type of need. Since the same environment is needed for this single brand new app, you may want to consider exploring using containers, instead of VMs managed by a hypervisor.
  • Generate a container with a Bash shell. Containers each have their own set of binaries and needed libraries to support their app, application stack, or environment, but they share the physical host's operating system. Starting and stopping containers, instead of performing software upgrades within them, is one reason why they are so popular for development and operations (DevOps). Docker is one such container engine that is extremely popular. It uses a daemon on the Linux system to listen for requests from the individual containers as well as from a Docker command‐line interface that allows you to control the container environment.
    • Master It Imagine you are a system administrator for an Ubuntu Linux system, and the development team is considering Docker containers to use in their production of applications. To let them try this environment, you need to install Docker to create and manage containers. Your Ubuntu system is specifically a server distro, so you want to manage the containers from the command line. What steps can you take to quickly install the Docker engine and generate a test CentOS container with access to the Bash shell for the software developers to try?
    • Solution To quickly get Docker on an Ubuntu server distribution, you should install the docker snap package using the command sudo snap install docker. The Snap framework comes pre‐installed on Ubuntu, so there is no need to install it. Once you have the docker snap package successfully installed, you can start a Docker CentOS container with access to the Bash shell for the software developers to test using the command sudo docker run ‐it centos bash.
  • Manage the Snap universal package system. The Snap universal package system employs the snap command to install and manage snap packages. The snapd daemon updates these packages on a regular basis through the appropriate Snap channel. When run, snaps operate in an isolated sandbox, protecting other data and applications on a Linux system, including other running snaps.
    • Master It You have recently visited the snap store and found a wonderful snap application that will assist in your orchestration management of containers, Multipass. After installing it and running it through several tests, you decide to use it in your production environment. However, you'd like to also keep up‐to‐date with the new developments in this special snap package. Besides reading about up‐and‐coming Multipass features, how can you stay informed using a snap package?
    • Solution You can try new features before they've reached production quality by installing the Multipass snap package from the latest/edge channel. You can run this snap package alongside your production Multipass snap (which you should have installed from the latest/stable channel). This way, you'll gain hands‐on access and can try newfangled features before they hit the latest/stable channel and your production Multipass snap.
  • Install the Flatpak framework. Software packages, flatpaks, in the Flatpak universal package system focus on a single software application and are a single self‐contained compressed package file that holds all the binaries and dependencies needed for the app to work. Though Flatpak is similar to Snap, flatpaks are currently available only for Desktop applications on Linux systems.
    • Master It You are a system administrator for a CentOS Desktop Linux system used by developers for creating the company's main software product. The developers are interested in a different text editor that will allow them to efficiently operate as they update the company's software app. Because there is a consideration to move development from the current Linux distro to another one that also uses Flatpak, you decide to install this text editor's flatpak package that is available in flathub. What steps should you take to get this framework and text editor installed for the developers on this current system?
    • Solution First you need to install the Flatpak framework. Using super user privileges, install it by issuing the dnf install flatpak command. After that step is successfully completed, connect to the flathub repository by using super user privileges and typing in flatpak remote‐add flathub https://flathub.org/repo/flathub.flatpakrepo at the command line. Once the Flatpak framework is installed and your system is connected to the repository, install the desired text editor flatpak by using super user privileges and entering the command flatpak install package , where package is the name of the flatpak package.