Digital Library

Practical Linux System Administration A Guide to Installation, Configuration, and Management (Kenneth Hess) (z-library.sk, 1lib.sk, z-lib.sk)

Kenneth Hess

Practical Linux System Administration A Guide to Installation, Configuration, and Management (Kenneth Hess) (z-library.sk, 1lib.sk, z-lib.sk)

Author Kenneth Hess

Linux

This essential guide covers all aspects of Linux system administration, from user maintenance, backups, filesystem housekeeping, storage management, and network setup to hardware and software troubleshooting and some application management. It's both a practical daily reference manual for sysadmins and IT pros and a handy study guide for those taking Linux certification exams. You'll turn to it frequently, not only because of the sheer volume of valuable information it provides but because of the real-world examples within and the clear, useful way the information is presented. With this book at your side, you'll be able to: • Install Linux and perform initial setup duties, such as connecting to a network • Navigate the Linux filesystem via the command line • Install software from repositories and source and satisfy dependencies • Set permissions on files and directories • Create, modify, and remove user accounts • Set up networking • Format and mount filesystems • Perform basic troubleshooting on hardware and software • Create and manage logical volumes • Work with SELinux • Manage a firewall and iptables • Shut down, reboot, and recover a system • Perform backups and restores

Format PDF
Size 4.8 MB
11
Views
0
Downloads
0.00
Total Donations

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
H ess Practical Linux System Administration A Guide to Installation, Configuration, and Management Kenneth Hess
Page 2
SYSTEM ADMINISTR ATION Practical Linux System Administration Twitter: @oreillymedia linkedin.com/company/oreilly-media youtube.com/oreillymedia This essential guide covers all aspects of Linux system administration, from user maintenance, backups, filesystem housekeeping, storage management, and network setup to hardware and software troubleshooting and some application management. It’s both a practical daily reference manual for sysadmins and IT pros and a handy study guide for those taking Linux certification exams. You’ll turn to it frequently, not only because of the sheer volume of valuable information it provides but also because of the real-world examples within and the clear, useful way the information is presented. With this book at your side, you’ll be able to: • Install Linux and perform initial setup duties, such as connecting to a network • Navigate the Linux filesystem via the command line • Install software from repositories and source and satisfy dependencies • Set permissions on files and directories • Create, modify, and remove user accounts • Set up networking • Format and mount filesystems • Perform basic troubleshooting on hardware and software • Create and manage logical volumes • Work with SELinux • Manage a firewall and iptables • Shut down, reboot, and recover a system • Perform backups and restores Kenneth Hess has been a Linux system administrator for more than 25 years and a technology writer and journalist for the past 20 years. Ken has written hundreds of articles covering desktop Linux, virtualization, databases, and the general topic of system administration. US $79.99 CAN $99.99 ISBN: 978-1-098-10903-5 H ess
Page 3
Kenneth Hess Practical Linux System Administration A Guide to Installation, Configuration, and Management Boston Farnham Sebastopol TokyoBeijing
Page 4
978-1-098-10903-5 [LSI] Practical Linux System Administration by Kenneth Hess Copyright © 2023 Hess Media and Consulting, LLC. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (https://oreilly.com). For more information, contact our corporate/institu‐ tional sales department: 800-998-9938 or corporate@oreilly.com. Acquisitions Editor: John Devins Development Editor: Jeff Bleiel Production Editor: Gregory Hyman Copyeditor: Justin Billing Proofreader: Tim Stewart Indexer: Ellen Troutman-Zaig Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Kate Dullea April 2023: First Edition Revision History for the First Edition 2023-04-18: First Release See https://oreilly.com/catalog/errata.csp?isbn=9781098109035 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Practical Linux System Administration, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the author, and do not represent the publisher’s views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
Page 5
Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix 1. Getting Started with Linux. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Installing Linux 1 Preparing Your System for Linux 1 Downloading and Installing Linux 2 Getting to Know Your New Linux System 4 Learning the CLI 6 pwd 7 cd 7 ls 8 Starting, Rebooting, and Shutting Down a Linux System 9 Starting a System 9 Restarting a System 10 Shutting Down a System 10 Summary 10 2. Working with Permissions and Privileged Accounts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Working as a Regular User 11 Working as the Root User 12 Logging in as Root 12 Using the su Command 12 Using the sudo Command 14 Creating a Sudoer 14 Reading and Modifying Permissions 15 Read, Write, and Execute 15 Numerical Permission Values 16 Group Permissions 16 iii
Page 6
Bringing Permissions into Focus 16 Changing File Permissions 18 Symbolic Mode 18 Numeric Mode 21 Default Permissions Explained: umask 22 Summary 23 3. Customizing the User Experience. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Altering Home Directory Options 25 Login Versus Nonlogin Shells 26 /etc/bashrc 27 /etc/profile 27 .bashrc 28 .bash_profile 29 .bash_logout 29 The /etc/skel Directory 29 Customizing the Shell Prompt 30 Summary 32 4. Managing Users. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 User and Group ID Numbering Conventions 34 Creating User Accounts 34 Adding Users with useradd 34 Adding Users with adduser 36 Modifying User Accounts 36 Adding a Supplementary Group 37 Changing the User Comments Field 38 Setting an Expiration (Expiry) Date on an Account 38 Changing a User’s Login Shell 38 Removing User Accounts 39 Forcing Password Changes 40 Handling Service Accounts 41 Managing Groups Rather Than Users 42 Summary 44 5. Connecting to a Network. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Plugging into a Network 45 Static IP Addressing 46 Dynamic IP Addressing 47 Networking and Security 48 Preparing a System for Network Connectivity 49 Pruning Your Systems 49 iv | Table of Contents
Page 7
Securing Network Daemons 50 The Secure Shell Daemon 50 Summary 55 6. Installing and Uninstalling Software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Updating Your System 58 Applying Red Hat Enterprise Linux–Based System Updates 58 Applying Debian-Based System Updates 59 Installing Software from Repositories 60 Installing an Application 60 Uninstalling an Application 62 Installing and Uninstalling Individual Software Packages 64 Installing an Individual Software Package Manually 64 Uninstalling Individual Software Packages 67 Finding Package Dependencies 68 Installing Software from Source Code 70 Satisfying Prerequisites: Building a Development Environment 70 Download, Extract, Compile, and Install Your Software 72 Uninstalling a Source-Installed Software Package 74 Summary 75 7. Managing Storage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Administering Linux Storage 77 Disks 78 Filesystems 78 Mounting and Mount Points 78 Physical and Logical Volumes 79 Checking Space 80 Swap Space 81 RAM-Based Temporary Space (ramfs and tmpfs) 81 Adding a New Disk to a System 82 Installing the Disk 83 Prepping the Disk for Use 83 Implementing Logical Volumes 86 Decommissioning and Disk Disposal 92 Notification 92 Scream Test 93 Power Down 93 Disk Wiping 93 Unracking and Palletizing 93 Disposal 94 Summary 94 Table of Contents | v
Page 8
8. Maintaining System Health. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Keeping Your System Clutter-Free 95 Cleaning the /tmp Directory 95 Making /home a Livable Space for Everyone 97 Decluttering Shared Directories 101 Deduplicating Files with fdupes 101 Tackling /home File Sprawl with Quotas 103 Patching Your Way to a Healthy System 105 Patching a Red Hat Enterprise Linux–Based System 105 Patching a Debian-Based Linux System 107 Securing Your Systems 108 Maintaining User and Group Accounts 109 Setting Up a Naming Convention 110 Creating Account Retention Policies 111 Retiring Group Accounts 113 Monitoring System Health 114 Gathering System Activity Reports 116 Formatting System Activity Reports 118 Summary 119 9. Monitoring Your System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Maintaining Vigilance on CPU, Memory, and Disk Performance and Capacity 121 Tracking CPU Usage 122 Exploring sysstat Monitoring 128 Reporting System Activity 128 Displaying System Activity Data in Multiple Formats 130 Monitoring System I/O Device Loading with iostat 130 Kicking It Old-School with the tapestat Utility 132 Collecting Processor Statistics 132 Monitoring Linux Tasks with pidstat 133 Watching Windows-Compatible Filesystem Statistics with cifsiostat 134 Summary 135 10. Scripting and Automation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Answering the Question: Why Automate? 137 Automating Yourself Out of a Job 138 Creating Scripts 139 Outlining Your Scripts 139 Writing a Script from an Outline 140 Scheduling Tasks 141 vi | Table of Contents
Page 9
Using cron to Schedule Tasks 141 Preventing Time Drift with the Network Time Protocol 142 Summary 144 11. Deploying Samba for Windows Compatibility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 Planning Your Samba Environment 146 Installing Samba and Its Dependencies 148 Adding Samba Users to Your System 149 Managing Samba Users as a Group 149 Providing Services to Mac and Windows Clients 150 Serving Network Storage to Desktop Clients 150 Configuring a Shared Directory 152 Browsing for Shared Directories 153 Mounting Windows System’s Shares 155 Summary 156 12. Troubleshooting Linux. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Reviving the Operating System 157 De-escalating a Kernel Panic 158 Scraping System Logs 159 Unraveling Software Problems 161 Inspecting System Logs 161 Checking Application Logs 161 Leveraging Internal Application Checks 162 Managing Firewalls and Their Rules 163 Removing and Reinstalling Software 163 Rebooting Your System 164 Dealing with Hardware Failures 164 Preemptively Troubleshooting Hardware 165 Gathering System Hardware Information 166 Creating Automated Security Checks 170 Summary 172 13. Securing Your System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Protecting the Root Account 173 Finding the Balance Between Security and Usability 174 Minimizing Your System’s Attack Surface 174 Creating and Securing User Accounts 177 Implementing Advanced Security Measures 183 Applying STIG Security Controls 184 Installing and Using Security Tools 184 Responding to Security Incidents 192 Table of Contents | vii
Page 10
Creating a Written Security Policy 193 Confirming the Breach 193 Identifying the Malicious Actor(s) 194 Taking Corrective Actions 194 Summary 194 14. Continuing Your Education. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 Training Internally 195 Seeking Certification 196 Preparing for a Certification Exam 196 Taking the Exam 197 Educating Yourself 197 Formalizing Your Education 198 Using Your Job as Education 199 Summary 200 15. Making Career Moves. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 Starting Your Own Business 202 Facing Self-Employment Realities 202 Managing Employees 202 Hiring Contractors 203 Moving into Corporate Management 203 Challenging Yourself 204 Managing Your New Role 204 Changing with the Job Market 205 Searching Online Job Boards 205 Working Remotely 208 Learning How to Communicate 209 Leaving Your Current Position 212 Writing the Resignation Letter 212 Leaving Your Job 214 Summary 215 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 viii | Table of Contents
Page 11
Preface I love to teach. Some of my earliest memories are of teaching other kids to do something—play chess, paint, or build forts for action figures. I taught other students in high school and college. Teaching is something I do naturally. When I write articles, whitepapers, or books, I adopt the role of a teacher. I place the reader in a classroom and teach them tasks or concepts, such as changing permissions on a file or adding a new user to a system. This is how my mind works. This book, like almost everything I write, is a manifestation of that almost innate desire to teach, pass on some knowledge, and plant a seed of curiosity that grows, blossoms, and spreads to others. I hope you find inspiration in this book that leads you to do the same. Who Should Read This Book This book is for anyone who wants to explore Linux for the first time as a system administrator or for someone who wants to transition to such a role for work or as a serious hobby. It’s also meant for those preparing to take certification exams requiring some Linux knowledge. Why I Wrote This Book I wrote this book to fill existing knowledge gaps for system administrators. I would have purchased this book for myself early in my career and kept it at my desk for ref‐ erence. Sure, there’s plenty of technical information in the book, as you might expect, but there’s also career guidance and some coverage of the nontechnical aspects of being a system administrator. ix
Page 12
Navigating This Book This book is organized as follows: • Chapter 1 introduces you to Linux via installation and initial setup. • Chapter 2 explores the command-line interface, essential to working with Linux as a system administrator. • Chapter 3 demonstrates how to customize the user experience and introduces you to the global system configuration files. • Chapter 4 focuses on user management. • Chapter 5 is an overview of Linux networking. • Chapter 6 is a how-to for software management. • Chapter 7 deals with storage concepts. • Chapter 8 is a discussion of maintaining system health. • Chapter 9 provides you with some tools for monitoring your system. • Chapter 10 explores scripting and automation. • Chapter 11 covers Windows interoperability using the Samba suite. • Chapter 12 teaches some practical troubleshooting techniques. • Chapter 13 helps you secure your system. • Chapter 14 summarizes educational opportunities you should explore to keep yourself up-to-date and sharpen your skills. • Chapter 15 is advice to help you keep your career moving forward. Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width italic Shows text that should be replaced with user-supplied values or by values deter‐ mined by context. x | Preface
Page 13
This element signifies a tip or suggestion. This element signifies a general note. This element indicates a warning or caution. Using Code Examples Supplemental material (code examples, exercises, etc.) is available for download at https://oreil.ly/practical-linux-system-admin-code. If you have a technical question or a problem using the code examples, please send email to bookquestions@oreilly.com. This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Practical Linux System Administration by Kenneth Hess (O’Reilly). Copyright 2023 Hess Media and Consult‐ ing, LLC, 978-1-098-10903-5.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com. Preface | xi
Page 14
O’Reilly Online Learning For more than 40 years, O’Reilly Media has provided technol‐ ogy and business training, knowledge, and insight to help companies succeed. Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, visit https://oreilly.com. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at https://oreil.ly/practical-linux-system-admin. Email bookquestions@oreilly.com to comment or ask technical questions about this book. For news and information about our books and courses, visit https://oreilly.com. Find us on LinkedIn: https://linkedin.com/company/oreilly-media Follow us on Twitter: https://twitter.com/oreillymedia Watch us on YouTube: https://www.youtube.com/oreillymedia xii | Preface
Page 15
Acknowledgments Being a Linux system administrator requires sacrifices from you and your family. I’ve often stated that a sysadmin’s whole family works for a company. This might be true for any job you have, but it seems especially relevant for system administrators. Linux system administration is a great career choice, but take time for yourself, your spouse, and your children. Remember that you don’t live to work; you work to live. You can’t get missed moments back—the milestones, events, and celebrations that create an existence that will be remembered fondly. Thank you to my wife, Melissa, who always supports my creative pursuits. I’d also like to thank the following people who helped make this book possible: • John Devins, O’Reilly acquisitions editor • Jeff Bleiel, O’Reilly development editor • Gregory Hyman, O’Reilly production editor • Technical reviewers Daniel Barrett and Adam McPartlan Preface | xiii
Page 16
(This page has no text content)
Page 17
CHAPTER 1 Getting Started with Linux Linux system administration means different things to different people. Administra‐ tion, for this book, means the daily actions that a Linux system administrator (sysad‐ min) must take to manage and support users, maintain system health, implement best practices for security, install software, and perform housekeeping tasks. This chapter covers Linux installation, initial setup, and system exploration using simple shell commands. You’ll spend a significant portion of your time at the command line, also known as the command-line interface (CLI). Linux system administrators rarely install or use GUIs on their supported server systems. This chapter introduces you to the CLI and some simple commands to navigate the filesystem, locate important files, and familiarize yourself with the Linux CLI. Installing Linux One of the first things every Linux system administrator learns is how to install Linux. There’s no single correct way to install Linux, but a few guidelines and sugges‐ tions will make your life easier as your users’ needs change. While this section won’t go into detailed step-by-step instructions on installing Linux, the basic steps are outlined here. For most junior-level sysadmins, system installation generally occurs via automated means such as Kickstart or another enterprise-level delivery system. Preparing Your System for Linux If this is your first time installing Linux, I suggest that you install it into a virtual machine (VM). That way, you don’t have to dedicate an entire piece of hardware to a learning system and you won’t potentially render your system inoperable by 1
Page 18
attempting to install Linux in parallel to your current system, creating a multiboot computer. (Setting up multibooting is a more advanced concept and is beyond the scope of this book.) If you don’t already have it installed, a good place to start with virtualization is to download and install the latest version of VirtualBox. VirtualBox is an application that allows your current computer to act as a VM host system where you may install virtual guests, such as Linux, into a separate, functioning computer system. VirtualBox runs on various host operating systems (OSs) and supports various guest operating systems, including Linux. The host OS and guest OS can be different from one another. Your computer (host OS) can be a Windows, Mac, or Linux-based system but have guest Linux systems installed on it as VirtualBox VMs. Downloading and Installing Linux Next, you’ll need to select a Linux distribution (distro) to install so that you can practice issuing commands, changing configurations, rebooting, installing software, creating users, and so on. I suggest you select a Linux distro based on the one your current employer uses. If your company doesn’t use Linux yet or you’re not employed in a system administrator role, then select from one of the following popular distributions: Debian Debian is a top-level distribution from which many other distributions are derived. Debian is community-supported, open source, and free. OpenSUSE OpenSUSE is a community-supported, top-level distribution with many faithful followers worldwide. Its commercial version, SUSE Linux Enterprise, has wide‐ spread adoption. Red Hat Enterprise Linux Red Hat is a commercially supported Linux distro that enjoys worldwide enter‐ prise adoption and is now owned by IBM. Ubuntu Ubuntu is very popular and has both (Debian-derived) community and commer‐ cially supported distributions. Ubuntu also offers ready-made VirtualBox (and other) VMs to help you get a quick start. The downloaded ISO file is a bootable Linux image. You don’t have to do anything to it if you use it to create a VM. A VM will boot from the ISO image and begin the installation process. After configuring your VM in VirtualBox, select Settings from the Oracle VM VirtualBox Manager, as shown in Figure 1-1. 2 | Chapter 1: Getting Started with Linux
Page 19
Figure 1-1. The Oracle VM VirtualBox Manager application and a configured virtual machine Then, select Storage, as shown in Figure 1-2. Figure 1-2. Virtual machine settings with Storage settings selected Installing Linux | 3
Page 20
Select the empty optical disk drive under the IDE controller in the Storage Devices pane and then select the optical disk icon in the Attributes pane to browse for your ISO image file. Figure 1-3 shows several ISO files available in this menu. Figure 1-3. Select the ISO image from the list Once you’ve selected your ISO image, click OK to proceed. When you start your VM, it will boot from this ISO image to begin installation onto your VM’s virtual disk. When your system boots, you can accept the default settings. If you have experience installing Linux, you can change the default settings to suit your needs. Create a user account when prompted to do so. If your distribution prompts you to give the root account a password, do so. You must remember this password because, without it, you’ll have to reinstall your Linux VM or try to recover it. Installing Linux can take several minutes, and a reboot is required at the end of the installation process. Getting to Know Your New Linux System After installation, the first thing you need to do is log in using the username and password that you created during installation. You’re placed into your home directory inside a shell (or operating environment) upon login. Your home directory (/home) is a subdirectory of the / directory. The Linux filesystem is a hierarchical filesystem, similar to Microsoft Windows. At the top level, there is the root directory, which is represented by the / symbol. Windows uses a drive letter, such as C:, for the root directory. On Windows, you can have many drive letters with their own root levels, such as C:, D:, E:, and so on. In Linux, there is only one root directory, /. All 4 | Chapter 1: Getting Started with Linux
The above is a preview of the first 20 pages. Register to read the complete e-book.

Support Author

0.00
Total Amount (¥)
0
Donation Count
Please enter an amount Minimum ¥1

You will be redirected to Alipay to complete payment, then return here.

Recommended for You

Loading recommended books...
Failed to load, please try again later
Back to List