No description
AI Reading Assistant
Summary and highlights from this book's index; jump to passages in the text
Tags
Support Statistics
¥.00 ·
0times
Text Preview (First 20 pages)
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
(This page has no text content)
Page
2
Red Hat Enterprise Linux 9 Essentials Red Hat Enterprise Linux 9 Essentials ISBN-13: 978-1-951442-65-1 © 2023 Neil Smyth / Payload Media, Inc. All Rights Reserved. This book is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly prohibited. All rights reserved. The content of this book is provided for informational purposes only. Neither the publisher nor the author offers any warranties or representation, express or implied, with regard to the accuracy of information contained in this book, nor do they accept any liability for any loss or damage arising from any errors or omissions. This book contains trademarked terms that are used solely for editorial purposes and to the benefit of the respective trademark owner. The terms used within this book are not intended as infringement of any trademarks. Rev: 1.0
Page
3
Table of Contents 1. Introduction 1 1.1 Superuser Conventions 1 1.2 Opening a Terminal Window 2 1.3 Editing Files 3 1.4 Feedback 4 1.5 Errata 5 2. A Brief History of Red Hat Linux 7 2.1 What exactly is Linux? 7 2.2 UNIX Origins 7 2.3 Who Created Linux? 7 2.4 The Early Days of Red Hat 8 2.5 Red Hat Support 8 2.6 Open Source 9 2.7 The Fedora Project 9 2.8 CentOS Stream - The Free Alternative 9 2.9 Summary 9 3. Installing RHEL 9 on a Clean Disk Drive 11 3.1 Obtaining the RHEL 9 Installation Media 11 3.2 Writing the ISO Installation Image to a USB Drive 12 3.2.1 Linux 12 3.2.2 macOS 13 3.2.3 Windows/macOS 14 3.3 Installing Red Hat Enterprise Linux 9 15 3.4 Partitioning a Disk for RHEL 9 20 3.5 Disk Encryption 22 3.6 User Settings 23 3.7 Registering the System 23 3.8 The Physical Installation 24 3.9 Final Configuration Steps 24 3.10 Installing Updates 25 3.11 Displaying Boot Messages 26 3.12 Summary 26
Page
4
4. Dual Booting RHEL 9 with Windows 29 4.1 Partition Resizing 29 4.2 Changing the Default Boot Option 31 4.3 Accessing the Windows Partition from RHEL 9 32 4.4 Summary 33 5. Allocating Windows Disk Partitions to RHEL 9 35 5.1 Unmounting the Windows Partition 35 5.2 Deleting the Windows Partitions from the Disk 35 5.3 Formatting the Unallocated Disk Partition 38 5.4 Mounting the New Partition 38 5.5 Summary 39 6. A Guided Tour of the GNOME 40 Desktop 41 6.1 Installing the GNOME Desktop 41 6.2 An Overview of the GNOME 40 Desktop 41 6.3 Activity Overview 42 6.4 Managing Windows 44 6.5 Using Workspaces 45 6.6 Calendar and Notifications 46 6.7 GNOME Desktop Settings 47 6.8 Beyond Basic Customization 48 6.9 Summary 48 7. An Overview of the Cockpit Web Interface 49 7.1 An Overview of Cockpit 49 7.2 Installing and Enabling Cockpit 50 7.3 Accessing Cockpit 50 7.4 Overview 51 7.5 Logs 52 7.6 Storage 53 7.7 Networking 54 7.8 Accounts 54 7.9 Services 54 7.10 Applications 55 7.11 Virtual Machines 55 7.12 Software Updates 56
Page
5
7.13 Terminal 56 7.14 Connecting to Multiple Servers 57 7.15 Enabling Stored Metrics 58 7.16 Summary 59 8. Using the Bash Shell on RHEL 9 61 8.1 What is a Shell? 61 8.2 Gaining Access to the Shell 61 8.3 Entering Commands at the Prompt 62 8.4 Getting Information about a Command 62 8.5 Bash Command-line Editing 62 8.6 Working with the Shell History 63 8.7 Filename Shorthand 64 8.8 Filename and Path Completion 64 8.9 Input and Output Redirection 64 8.10 Working with Pipes in the Bash Shell 65 8.11 Configuring Aliases 65 8.12 Environment Variables 66 8.13 Writing Shell Scripts 67 8.14 Summary 68 9. Managing RHEL 9 Users and Groups 69 9.1 User Management from the Command-line 69 9.2 User Management with Cockpit 71 9.3 User Management using the Settings App 73 9.4 Summary 75 10. Understanding RHEL 9 Software Installation and Management 77 10.1 Repositories 77 10.2 The BaseOS Repository 78 10.3 The AppStream Repository 79 10.4 Summary 82 11. Managing RHEL 9 systemd Units 83 11.1 Understanding RHEL 9 systemd Targets 83 11.2 Understanding RHEL 9 systemd Services 83 11.3 RHEL 9 systemd Target Descriptions 83
Page
6
11.4 Identifying and Configuring the Default Target 85 11.5 Understanding systemd Units and Unit Types 86 11.6 Dynamically Changing the Current Target 87 11.7 Enabling, Disabling, and Masking systemd Units 87 11.8 Working with systemd Units in Cockpit 89 11.9 Summary 90 12. RHEL 9 Network Management 91 12.1 An Introduction to NetworkManager 91 12.2 Installing and Enabling NetworkManager 92 12.3 Basic nmcli Commands 92 12.4 Working with Connection Profiles 96 12.5 Interactive Editing 98 12.6 Configuring NetworkManager Permissions 99 12.7 Summary 100 13. RHEL 9 Firewall Basics 101 13.1 Understanding Ports and Services 101 13.2 Securing Ports and Services 101 13.3 RHEL 9 Services and iptables Rules 102 13.4 Well-Known Ports and Services 103 13.5 Summary 106 14. RHEL 9 Firewall Configuration with firewalld 107 14.1 An Introduction to firewalld 107 14.1.1 Zones 107 14.1.2 Interfaces 109 14.1.3 Services 109 14.1.4 Ports 109 14.2 Checking firewalld Status 109 14.3 Configuring Firewall Rules with firewall-cmd 110 14.3.1 Identifying and Changing the Default Zone 110 14.3.2 Displaying Zone Information 110 14.3.3 Adding and Removing Zone Services 111 14.3.4 Working with Port-based Rules 112 14.3.5 Creating a New Zone 112 14.3.6 Changing Zone/Interface Assignments 112 14.3.7 Masquerading 112
Page
7
14.3.8 Adding ICMP Rules 113 14.3.9 Implementing Port Forwarding 113 14.4 Managing firewalld from the Cockpit Interface 114 14.5 Managing firewalld using firewall-config 115 14.6 Summary 116 15. Configuring SSH Key-based Authentication on RHEL 9 117 15.1 An Overview of Secure Shell (SSH) 117 15.2 SSH Key-based Authentication 117 15.3 Setting Up Key-based Authentication 118 15.4 Installing and Starting the SSH Service 118 15.5 SSH Key-based Authentication from Linux and macOS Clients 118 15.6 Managing Multiple Keys 120 15.7 SSH Key-based Authentication from Windows Clients 121 15.8 SSH Key-based Authentication using PuTTY 123 15.9 Generating a Private Key with PuTTYgen 124 15.10 Summary 125 16. RHEL 9 Remote Desktop Access with VNC 127 16.1 Secure and Insecure Remote Desktop Access 127 16.2 Installing the GNOME Desktop Environment 127 16.3 Installing VNC on RHEL 9 129 16.4 Configuring the VNC Server 129 16.5 Connecting to a VNC Server 131 16.6 Establishing a Secure Remote Desktop Session 131 16.7 Establishing a Secure Tunnel on Windows using PuTTY 133 16.8 Shutting Down a Desktop Session 134 16.9 Troubleshooting a VNC Connection 134 16.10 Summary 135 17. Displaying RHEL 9 Applications Remotely (X11 Forwarding) 137 17.1 Requirements for Remotely Displaying RHEL 9 Applications 137
Page
8
17.2 Displaying a RHEL 9 Application Remotely 138 17.3 Trusted X11 Forwarding 138 17.4 Compressed X11 Forwarding 138 17.5 Displaying Remote RHEL 9 Apps on Windows 138 17.6 Summary 141 18. Using NFS on RHEL 9 to Share Files with Remote Systems 143 18.1 Ensuring NFS Services are running on RHEL 9 143 18.2 Configuring the RHEL 9 Firewall to Allow NFS Traffic 144 18.3 Specifying the Folders to be Shared 144 18.4 Accessing Shared Folders 145 18.5 Mounting an NFS Filesystem on System Startup 145 18.6 Unmounting an NFS Mount Point 145 18.7 Accessing NFS Filesystems in Cockpit 146 18.8 Summary 147 19. Sharing Files between RHEL 9 and Windows Systems with Samba 149 19.1 Accessing Windows Resources from the GNOME Desktop 149 19.2 Samba and Samba Client 150 19.3 Installing Samba on RHEL 9 150 19.4 Configuring the RHEL 9 Firewall to Enable Samba 150 19.5 Configuring the smb.conf File 151 19.5.1 Configuring the [global] Section 151 19.5.2 Configuring a Shared Resource 151 19.5.3 Removing Unnecessary Shares 152 19.6 Configuring SELinux for Samba 152 19.7 Creating a Samba User 154 19.8 Testing the smb.conf File 154 19.9 Starting the Samba and NetBIOS Name Services 155 19.10 Accessing Samba Shares 156 19.11 Accessing Windows Shares from RHEL 9 158 19.12 Summary 159
Page
9
20. An Overview of Virtualization Techniques 161 20.1 Guest Operating System Virtualization 161 20.2 Hypervisor Virtualization 162 20.2.1 Paravirtualization 163 20.2.2 Full Virtualization 164 20.2.3 Hardware Virtualization 164 20.3 Virtual Machine Networking 165 20.4 Summary 165 21. Installing KVM Virtualization on RHEL 9 167 21.1 An Overview of KVM 167 21.2 KVM Hardware Requirements 167 21.3 Preparing RHEL 9 for KVM Virtualization 168 21.4 Verifying the KVM Installation 168 21.5 Summary 170 22. Creating KVM Virtual Machines on RHEL 9 using Cockpit 171 22.1 Installing the Cockpit Virtual Machines Module 171 22.2 Creating a Virtual Machine in Cockpit 171 22.3 Starting the Installation 174 22.4 Working with Storage Volumes and Storage Pools 176 22.5 Summary 178 23. Creating KVM Virtual Machines on RHEL 9 using virt-manager 179 23.1 Starting the Virtual Machine Manager 179 23.2 Configuring the KVM Virtual System 180 23.3 Starting the KVM Virtual Machine 184 23.4 Summary 185 24. Creating KVM Virtual Machines with virt-install and virsh 187 24.1 Running virt-install to build a KVM Guest System 187 24.2 An Example RHEL 9 virt-install Command 187 24.3 Starting and Stopping a Virtual Machine from the
Page
10
Command-Line 188 24.4 Creating a Virtual Machine from a Configuration File 189 24.5 Summary 189 25. Creating a RHEL 9 KVM Networked Bridge Interface 191 25.1 Getting the Current Network Manager Settings 191 25.2 Creating a Network Manager Bridge from the Command-Line 193 25.3 Declaring the KVM Bridged Network 194 25.4 Using a Bridge Network in a Virtual Machine 195 25.5 Creating a Bridge Network using nm-connection- editor 197 25.6 Summary 200 26. Managing KVM using the virsh Command-Line Tool 201 26.1 The virsh Shell and Command-Line 201 26.2 Listing Guest System Status 202 26.3 Starting a Guest System 203 26.4 Shutting Down a Guest System 203 26.5 Suspending and Resuming a Guest System 203 26.6 Saving and Restoring Guest Systems 203 26.7 Rebooting a Guest System 204 26.8 Configuring the Memory Assigned to a Guest OS 204 26.9 Summary 204 27. An Introduction to Linux Containers 205 27.1 Linux Containers and Kernel Sharing 205 27.2 Container Uses and Advantages 206 27.3 RHEL 9 Container Tools 207 27.4 Container Catalogs, Repositories, and Registries 207 27.5 Container Networking 208 27.6 Summary 208 28. Working with Containers on RHEL 9 209 28.1 Installing the Container Tools 209
Page
11
28.2 Logging in to the Red Hat Container Registry 209 28.3 Pulling a Container Image 209 28.4 Running the Image in a Container 211 28.5 Managing a Container 213 28.6 Saving a Container to an Image 213 28.7 Removing an Image from Local Storage 214 28.8 Removing Containers 214 28.9 Building a Container with Buildah 214 28.10 Building a Container from Scratch 214 28.11 Container Bridge Networking 215 28.12 Managing Containers in Cockpit 218 28.13 Summary 221 29. Setting Up a RHEL 9 Web Server 223 29.1 Requirements for Configuring a RHEL 9 Web Server 223 29.2 Installing the Apache Web Server Packages 223 29.3 Configuring the Firewall 224 29.4 Port Forwarding 224 29.5 Starting the Apache Web Server 224 29.6 Testing the Web Server 224 29.7 Configuring the Apache Web Server for Your Domain 225 29.8 The Basics of a Secure Website 226 29.9 Configuring Apache for HTTPS 227 29.10 Obtaining an SSL Certificate 227 29.11 Summary 229 30. Configuring a RHEL 9 Postfix Email Server 231 30.1 The Structure of the Email System 231 30.1.1 Mail User Agent 231 30.1.2 Mail Transfer Agent 231 30.1.3 Mail Delivery Agent 231 30.1.4 SMTP 232 30.1.5 SMTP Relay 232 30.2 Configuring a RHEL 9 Email Server 232 30.3 Postfix Pre-Installation Steps 232
Page
12
30.4 Firewall/Router Configuration 233 30.5 Installing Postfix on RHEL 9 233 30.6 Configuring Postfix 233 30.7 Configuring DNS MX Records 235 30.8 Starting Postfix on a RHEL 9 System 235 30.9 Testing Postfix 235 30.10 Sending Mail via an SMTP Relay Server 236 30.11 Summary 237 31. Adding a New Disk Drive to a RHEL 9 System 239 31.1 Mounted File Systems or Logical Volumes 239 31.2 Finding the New Hard Drive 239 31.3 Creating Linux Partitions 240 31.4 Creating a File System on a RHEL 9 Disk Partition 241 31.5 An Overview of Journaled File Systems 242 31.6 Mounting a File System 242 31.7 Configuring RHEL 9 to Mount a File System Automatically 243 31.8 Adding a Disk Using Cockpit 243 31.9 Summary 245 32. Adding a New Disk to a RHEL 9 Volume Group and Logical Volume 247 32.1 An Overview of Logical Volume Management (LVM) 247 32.1.1 Volume Group (VG) 247 32.1.2 Physical Volume (PV) 247 32.1.3 Logical Volume (LV) 248 32.1.4 Physical Extent (PE) 248 32.1.5 Logical Extent (LE) 248 32.2 Getting Information about Logical Volumes 248 32.3 Adding Additional Space to a Volume Group from the Command-Line 251 32.4 Adding Additional Space to a Volume Group Using Cockpit 253 32.5 Summary 255
Page
13
33. Adding and Managing RHEL 9 Swap Space 257 33.1 What is Swap Space? 257 33.2 Recommended Swap Space for RHEL 9 257 33.3 Identifying Current Swap Space Usage 257 33.4 Adding a Swap File to a RHEL 9 System 258 33.5 Adding Swap as a Partition 259 33.6 Adding Space to a RHEL 9 LVM Swap Volume 259 33.7 Adding Swap Space to the Volume Group 260 33.8 Summary 262 34. RHEL 9 System and Process Monitoring 263 34.1 Managing Processes 263 34.2 Real-time System Monitoring with top 267 34.3 Command-Line Disk and Swap Space Monitoring 268 34.4 Summary 269 Index 271
Page
14
1. Introduction Arguably one of the most highly regarded and widely used enterprise level operating systems available today is the Red Hat Enterprise Linux (typically shortened to RHEL and pronounced rell) distribution. Not only is it considered to be among the most stable and reliable operating systems, it is also backed by the considerable resources and technical skills of Red Hat, Inc. Red Hat Enterprise Linux 9 Essentials is designed to provide detailed information on the installation, use and administration of the Red Hat Enterprise Linux 9 distribution. For beginners, the book covers topics such as operating system installation, the basics of the GNOME desktop environment, configuring email and web servers and installing packages and system updates using App Streams. Additional installation topics such as dual booting with Microsoft Windows are also covered, together with all important security topics such as configuring a firewall and user and group administration. For the experienced user, topics such as remote desktop access, the Cockpit web interface, logical volume management (LVM), disk partitioning, swap management, KVM virtualization, Secure Shell (SSH), Linux Containers and file sharing using both Samba and NFS are covered in detail to provide a thorough overview of this enterprise class operating system. 1.1 Superuser Conventions RHEL 9, in common with Linux in general, has two types of user account, one being a standard user account with restricted access to many of the administrative files and features of the operating system, and the other a superuser (root) account with elevated privileges. Typically, a user can gain root access either by logging in as the root user, or using the su - command and entering the root password. In the following example, a user is gaining root access via
Page
15
the su - command: [neil@demo-server ~]$ su - Password: [root@demo-server ~]# Note that the command prompt for a regular user ends with a $ sign while the root user has a # character. When working with the command-line, this is a useful indication as to whether or not you are currently issuing commands as the root user. If the su - command fails, the root account on the system has most likely been disabled for security reasons. In this case, the sudo command can be used instead as outlined below. Using sudo, a single command requiring root privileges may be executed by a non-root user. Consider the following attempt to update the operating system with the latest patches and packages: [neil@demo-server ~]$ dnf update Not root, Subscription Management repositories not updated Error: This command has to be run under the root user. Optionally, user accounts may be configured so that they have access to root level privileges. Instead of using the su - command to first gain root access, user accounts with administration privileges are able to run otherwise restricted commands using sudo: [neil@demo-server]$ sudo dnf update We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. [sudo] password for neil: Updating Subscription Management repositories. . .
Page
16
To perform multiple commands without repeatedly using the sudo command, a command prompt with persistent super-user privileges may be accessed as follows: [neil@demo-server]$ sudo su - [neil@demo-server]# The reason for raising this issue so early in the book is that many of the command-line examples outlined in this book will require root privileges. Rather than repetitively preface every command-line example with directions to run the command as root, the command prompt at the start of the line will be used to indicate whether or not the command needs to be performed as root. If the command can be run as a regular user, the command will be prefixed with a $ command prompt as follows: $ date If, on the other hand, the command requires root privileges, the command will be preceded by a # command prompt: # dnf install openssh 1.2 Opening a Terminal Window If you are using the GNOME desktop and need to access a command prompt you will need to open a Terminal window. To do this, either press the keyboard Windows key or click on the Activities button in the top left-hand corner of the screen, then select the Terminal from the dash as shown in Figure 1-1: Figure 1-1 1.3 Editing Files Configuring a Linux system typically involves editing files. For those new to Linux it can be unclear which editor to
Page
17
use. If you are running a terminal session and do not already have a preferred editor we recommend using the nano editor. To launch nano in a terminal window simply enter the following command: # nano <file> Where <file> is replaced by the path to the file you wish to edit. For example: # nano /etc/passwd Once loaded, nano will appear as illustrated in Figure 1-2: Figure 1-2 To create a new file simply run nano as follows: # nano When you have finished editing the file, type Ctrl-S to save the file followed by Ctrl-X to exit. To open an existing file, use the Ctrl-R keyboard shortcut. If you prefer to use a graphical editor within the GNOME desktop environment gedit is a useful starting point for basic editing tasks. To launch gedit from the desktop press Alt-F2 to display the Enter a Command window as shown in Figure 1-3:
Page
18
Figure 1-3 Enter gedit into the text field and press the Enter key. After a short delay, gedit will load ready to open, create and edit files: Figure 1-4 Alternatively, launch gedit from a terminal window either with or without the path to the file to open: # gedit # gedit /etc/passwd 1.4 Feedback We want you to be satisfied with your purchase of this book. If you find any errors in the book, or have any comments, questions or concerns please contact us at feedback@ebookfrenzy.com.
Page
19
1.5 Errata While we make every effort to ensure the accuracy of the content of this book, it is inevitable that a book covering a subject area of this size and complexity may include some errors and oversights. Any known issues with the book will be outlined, together with solutions, at the following URL: https://www.ebookfrenzy.com/errata/rhel9.html In the event that you find an error not listed in the errata, please let us know by emailing our support team at feedback@ebookfrenzy.com.
Page
20
2. A Brief History of Red Hat Linux Red Hat Enterprise Linux is one of a number of variants (also referred to as distributions) of the Linux operating system and is the product of a U.S. company named Red Hat, Inc., based in Raleigh, North Carolina. The company was founded in the mid-1990s through the merger of two companies owned at the time by Marc Ewing and Bob Young. The origins of Linux, however, go back even further. This chapter will outline the history of both the Linux operating system and Red Hat, Inc. 2.1 What exactly is Linux? Linux is an operating system in much the same way that Windows is an operating system (and there any similarities between Linux and Windows end). The term operating system is used to describe the software that acts as a layer between the hardware in a computer and the applications that we all run on a daily basis. When programmers write applications, they interface with the operating system to perform such tasks as writing files to the hard disk drive and displaying information on the screen. Without an operating system, every programmer would have to write code to directly access the hardware of the system. In addition, the programmer would have to be able to support every single piece of hardware ever created to be sure the application would work on every possible hardware configuration. Because the operating system handles all of this hardware complexity, application development becomes a much easier task. Linux is just one of a number of different operating systems available today. 2.2 UNIX Origins To understand the history of Linux, we first have to go back
Loading comments...
Reply to Comment
Edit Comment