Dear Reader,Thank you for choosing CompTIA Linux+ Complete Study Guide (Exams LX0-101 andLX0-102). This book is part of a family of premium-quality Sybex books, all of which arewritten by outstanding authors who combine practical experience with a gift for teaching.Sybex was founded in 1976. More than thirty years later, we’re still committed to producingconsistently exceptional books. With each of our titles we’re working hard to set a new stan-dard for the industry. From the paper we print on, to the authors we work with, our goal isto bring you the best books available.I hope you see all that reflected in these pages. I’d be very interested to hear your commentsand get your feedback on how we’re doing. Feel free to let me know what you think aboutthis or any other Sybex book by sending me an email at email@example.com, or if you thinkyou’ve found a technical error in this book, please visit http://sybex.custhelp.com. Cus-tomer feedback is critical to our efforts at Sybex. Best regards, Neil Edde Vice President and Publisher Sybex, an Imprint of Wiley
From one writer to another: Lola, keep writing your stories!
AcknowledgmentsAlthough this book bears my name as author, many other people contributed to its creation.Without their help, this book wouldn’t exist, or at best would exist in a lesser form. JeffKellum was the Acquisitions Editor, and so helped get the book started. Pete Gaughan, theDevelopment Editor, and Liz Britten, the Production Editor, oversaw the book as it progressedthrough all its stages. Emmett Dulaney was the Technical Editor, who checked the text fortechnical errors and omissions—but any mistakes that remain are my own. Tiffany Taylor,the copy editor, helped keep the text grammatical and understandable. The proofreader,Publications Services, Inc., checked the text for typos. I’d also like to thank Neil Salkind andothers at Studio B, who helped connect me with Wiley to write this book.About the AuthorRoderick W. Smith is a Linux consultant and author. He has written over a dozenbooks on Linux, FreeBSD, and computer networking, including the LPIC-1 StudyGuide and Linux Administrator Street Smarts (both from Sybex). He can be reachedat firstname.lastname@example.org.
Contents at a GlanceIntroduction xxiAssessment Test xlviiPart I The CompTIA Linux+ LX0-101 Exam 1Chapter 1 Exploring Linux Command-Line Tools 3Chapter 2 Managing Software 45Chapter 3 Configuring Hardware 105Chapter 4 Managing Files 177Chapter 5 Booting Linux and Editing Files 225Part II The CompTIA Linux+ LX0-102 Exam 265Chapter 6 Configuring the X Window System, Localization, and Printing 267Chapter 7 Administering the System 329Chapter 8 Configuring Basic Networking 383Chapter 9 Writing Scripts, Configuring E-Mail, and Using Databases 427Chapter 10 Securing Your System 475Appendix About the Companion CD 519Glossary 523Index 551
ContentsIntroduction xxiAssessment Test xlviiPart I The CompTIA Linux+ LX0-101 Exam 1Chapter 1 Exploring Linux Command-Line Tools 3 Understanding Command-Line Basics 4 Exploring Your Linux Shell Options 4 Using a Shell 5 Exploring Shell Configuration 11 Using Environment Variables 12 Getting Help 13 Using Streams, Redirection, and Pipes 14 Exploring Types of Streams 14 Redirecting Input and Output 15 Piping Data Between Programs 16 Generating Command Lines 17 Processing Text Using Filters 18 File-Combining Commands 18 File-Transforming Commands 20 File-Formatting Commands 24 File-Viewing Commands 27 File-Summarizing Commands 29 Using Regular Expressions 31 Understanding Regular Expressions 31 Using grep 32 Using sed 34 Summary 36 Exam Essentials 37 Review Questions 38 Answers to Review Questions 42Chapter 2 Managing Software 45 Package Concepts 46 Using RPM 48 RPM Distributions and Conventions 48 The rpm Command Set 50 Extracting Data from RPMs 54 Using Yum 55 RPM and Yum Configuration Files 59 RPM Compared to Other Package Formats 60
xii Contents Using Debian Packages 61 Debian Distributions and Conventions 61 The dpkg Command Set 62 Using apt-cache 65 Using apt-get 65 Using dselect, aptitude, and Synaptic 69 Reconfiguring Packages 71 Debian Packages Compared to Other Package Formats 71 Configuring Debian Package Tools 72 Converting Between Package Formats 73 Package Dependencies and Conflicts 74 Real and Imagined Package Dependency Problems 75 Workarounds to Package Dependency Problems 76 Startup Script Problems 78 Managing Shared Libraries 78 Library Principles 79 Locating Library Files 80 Library Management Commands 83 Managing Processes 85 Understanding the Kernel: The First Process 85 Examining Process Lists 85 Understanding Foreground and Background Processes 91 Managing Process Priorities 92 Killing Processes 93 Summary 94 Exam Essentials 95 Review Questions 97 Answers to Review Questions 101Chapter 3 Configuring Hardware 105 Configuring the BIOS and Core Hardware 106 Understanding the Role of the BIOS 107 IRQs 109 I/O Addresses 112 DMA Addresses 113 Boot Disks and Geometry Settings 113 Coldplug and Hotplug Devices 115 Configuring Expansion Cards 117 Configuring PCI Cards 117 Learning about Kernel Modules 119 Loading Kernel Modules 120 Removing Kernel Modules 122
Contents xiii Configuring USB Devices 123 USB Basics 123 Linux USB Drivers 124 USB Manager Applications 125 Configuring Hard Disks 126 Configuring PATA Disks 126 Configuring SATA Disks 127 Configuring SCSI Disks 128 Configuring External Disks 129 Designing a Hard Disk Layout 130 Why Partition? 130 Understanding Partitioning Systems 131 An Alternative to Partitions: LVM 134 Mount Points 134 Common Partitions and Filesystem Layouts 135 Creating Partitions and Filesystems 136 Partitioning a Disk 137 Preparing a Partition for Use 141 Maintaining Filesystem Health 147 Tuning Filesystems 148 Maintaining a Journal 152 Checking Filesystems 153 Monitoring Disk Use 155 Mounting and Unmounting Filesystems 158 Temporarily Mounting or Unmounting Filesystems 158 Permanently Mounting Filesystems 164 Summary 167 Exam Essentials 167 Review Questions 169 Answers to Review Questions 173Chapter 4 Managing Files 177 Managing Files 178 File Naming and Wildcard Expansion Rules 178 File Commands 180 File Archiving Commands 185 Managing Links 191 Directory Commands 192 Managing File Ownership 193 Assessing File Ownership 194 Changing a File’s Owner 194 Changing a File’s Group 195
xiv Contents Controlling Access to Files 195 Understanding Permissions 195 Changing a File’s Mode 200 Setting the Default Mode and Group 203 Changing File Attributes 205 Managing Disk Quotas 206 Enabling Quota Support 206 Setting Quotas for Users 207 Locating Files 208 The FHS 208 Tools for Locating Files 212 Summary 216 Exam Essentials 216 Review Questions 218 Answers to Review Questions 222Chapter 5 Booting Linux and Editing Files 225 Installing Boot Loaders 226 Boot Loader Principles 227 Using LILO as the Boot Loader 228 Using GRUB as the Boot Loader 233 Understanding the Boot Process 238 Extracting Information about the Boot Process 238 Locating and Interpreting Boot Messages 239 The Boot Process 240 Dealing with Runlevels and the Initialization Process 241 Runlevel Functions 241 Identifying the Services in a Runlevel 243 Managing Runlevel Services 245 Checking Your Runlevel 247 Changing Runlevels on a Running System 247 Editing Files with Vi 250 Understanding Vi Modes 251 Exploring Basic Text-Editing Procedures 251 Saving Changes 254 Summary 255 Exam Essentials 255 Review Questions 257 Answers to Review Questions 261
Contents xvPART II The CompTIA Linux+ LX0-102 Exam 265Chapter 6 Configuring the X Window System, Localization, and Printing 267 Configuring Basic X Features 268 X Server Options for Linux 268 Methods of Configuring X 269 X Configuration Options 273 Obtaining X Display Information 281 Configuring X Fonts 282 Font Technologies and Formats 282 Configuring X Core Fonts 283 Configuring a Font Server 285 Configuring Xft Fonts 286 Managing GUI Logins 287 The X GUI Login System 288 Running an XDMCP Server 289 Configuring an XDMCP Server 290 Using X for Remote Access 291 X Client/Server Principles 292 Using Remote X Clients 292 X Accessibility 295 Keyboard and Mouse Accessibility Issues 295 Screen Display Settings 297 Using Additional Assistive Technologies 299 Configuring Localization and Internationalization 299 Setting Your Time Zone 300 Querying and Setting Your Locale 301 Configuring Printing 305 Conceptualizing the Linux Printing Architecture 305 Understanding PostScript and Ghostscript 306 Running a Printing System 308 Configuring CUPS 309 Monitoring and Controlling the Print Queue 315 Summary 318 Exam Essentials 318 Review Questions 320 Answers to Review Questions 325
xvi ContentsChapter 7 Administering the System 329 Managing Users and Groups 330 Understanding Users and Groups 330 Configuring User Accounts 333 Configuring Groups 344 Tuning User and System Environments 348 Using System Log Files 349 Understanding syslogd 349 Setting Logging Options 350 Manually Logging Data 352 Rotating Log Files 353 Reviewing Log File Contents 356 Maintaining the System Time 358 Linux Time Concepts 358 Manually Setting the Time 359 Using NTP 360 Running Jobs in the Future 366 Understanding the Role of cron 366 Creating System cron Jobs 367 Creating User cron Jobs 368 Using at 372 Summary 374 Exam Essentials 374 Review Questions 376 Answers to Review Questions 380Chapter 8 Configuring Basic Networking 383 Understanding TCP/IP Networking 384 Knowing the Basic Functions of Network Hardware 384 Investigating Types of Network Hardware 385 Understanding Network Packets 387 Understanding Network Protocol Stacks 387 Knowing TCP/IP Protocol Types 389 Understanding Network Addressing 390 Using Network Addresses 391 Resolving Hostnames 397 Network Ports 399 Configuring Linux for a Local Network 402 Network Hardware Configuration 402 Configuring with DHCP 402 Configuring with a Static IP Address 404
Contents xvii Configuring Routing 406 Using GUI Configuration Tools 408 Using the ifup and ifdown Commands 408 Configuring Hostnames 409 Diagnosing Network Connections 412 Testing Basic Connectivity 412 Tracing a Route 412 Checking Network Status 414 Examining Raw Network Traffic 414 Using Additional Tools 416 Summary 418 Exam Essentials 418 Review Questions 420 Answers to Review Questions 424Chapter 9 Writing Scripts, Configuring E-mail, and Using Databases 427 Managing the Shell Environment 428 Reviewing Environment Variables 428 Understanding Common Environment Variables 429 Using Aliases 433 Modifying Shell Configuration Files 433 Writing Scripts 435 Beginning a Shell Script 436 Using Commands 436 Using Variables 438 Using Conditional Expressions 441 Using Loops 443 Using Functions 444 Managing E-mail 446 Understanding E-mail 446 Choosing E-mail Software 448 Managing E-mail 450 Securing Your E-mail Server 454 Managing Data with SQL 455 Picking a SQL Package 455 Understanding SQL Basics 456 Using MySQL 457 Summary 465 Exam Essentials 466 Review Questions 468 Answers to Review Questions 472
xviii ContentsChapter 10 Securing Your System 475 Administering Network Security 476 Using Super Server Restrictions 477 Disabling Unused Servers 483 Administering Local Security 490 Securing Passwords 490 Limiting root Access 494 Setting Login, Process, and Memory Limits 495 Locating SUID/SGID Files 497 Configuring SSH 499 SSH Basics 499 Setting SSH Options for Your System 500 SSH Security Considerations 507 Using GPG 507 Generating and Importing Keys 508 Encrypting and Decrypting Data 509 Signing Messages and Verifying Signatures 510 Summary 510 Exam Essentials 511 Review Questions 512 Answers to Review Questions 516Appendix About the Companion CD 519 What You’ll Find on the CD 520 Sybex Test Engine 520 Electronic Flashcards 520 PDF of the Book 520 Adobe Reader 520 System Requirements 521 Windows 521 Linux 521 Using the CD 521 Troubleshooting 522 Customer Care 522Glossary 523 Index 551
IntroductionWhy should you learn about Linux? It’s a fast-growing operating system, and it is inexpen-sive and flexible. Linux is also a major player in the small and mid-sized server field, and it’san increasingly viable platform for workstation and desktop use as well. By understandingLinux, you’ll increase your standing in the job market. Even if you already know Windowsor Mac OS and your employer uses these systems exclusively, understanding Linux will giveyou an edge when you’re looking for a new job or if you’re looking for a promotion. Forinstance, this knowledge will help you to make an informed decision about if and when youshould deploy Linux. The Computing Technology Industry Association (CompTIA) promotes the Linux+exam as an introductory certification for people who want to enter careers involving Linux.The exam is meant to certify that an individual has the skills necessary to install, operate,and troubleshoot a Linux system and is familiar with Linux-specific concepts and basichardware. The purpose of this book is to help you pass the 2010 version of the Linux+ exams(LX0-101 and LX0-102). Because these exams cover basic Linux installation, configura-tion, maintenance, applications, networking, and security, those are the topics that areemphasized in this book. You’ll learn enough to get a Linux system up and running andhow to configure it for many common tasks. Even after you’ve taken and passed the Linux+exam, this book should remain a useful reference. In 2010, CompTIA announced a partnership with Linux Professional Institute, the organization behind the popular LPI Certification (LPIC) program . With this partnership, CompTIA will be offering the LPIC Level 1 exams under the Linux+ umbrella . The exams and the exam objectives are identical for the two programs . However, Linux+ candidates have the option of receiving their LPIC-1 as well as the Novell Certified Linux Administrator certification by passing the CompTIA Linux+ exams . This book has undergone its own testing and certification by ProCert Labs (http://www.procertcom.com), and has achieved the CompTIA Authorized Quality Curriculum (CACQ)status. This means that you can rest assured that the book covers the Linux+ objectives.What Is Linux?Linux is a clone of the Unix operating system (OS) that has been popular in academia andmany business environments for years. Formerly used exclusively on large mainframes, Unixand Linux can now run on small computers—which are actually far more powerful than themainframes of just a few years ago. Because of its mainframe heritage, Unix (and hence alsoLinux) scales well to perform today’s demanding scientific, engineering, and network servertasks.
xxii Introduction Linux consists of a kernel, which is the core control software, and many libraries andutilities that rely on the kernel to provide features with which users interact. The OS isavailable in many different distributions, which are collections of a specific kernel with spe-cific support programs.Why Become Linux+ Certified?There are several good reasons to get your Linux+ certification:Provides proof of professional achievement Certifications are quickly becoming statussymbols in the computer service industry. Organizations, including members of the computerservice industry, are recognizing the benefits of certification, such as Linux+. Organizationsare pushing for their members to become certified. Every day, more people are putting theCompTIA official certification logo on their business cards.Increases your marketability Linux+ certification makes individuals more marketable topotential employers. Also, Linux+ certified employees might receive a higher salary basebecause employers won’t have to spend as much money on vendor-specific training.Provides an opportunity for advancement Most raises and advancements are based onperformance. Linux+ certified employees work faster and more efficiently. The more pro-ductive employees are, the more money they will make for their company; and, of course,the more money they make for the company, the more valuable they will be to the company.So, if employees are Linux+ certified, their chances of getting promoted will be greater.Fulfills training requirements Each year, more and more major computer hardware vendors,including (but not limited to) IBM, Hewlett-Packard, and Novell, are recognizing CompTIA’scertifications as prerequisites in their own respective certification programs. The use of out-side certifications like Linux+ has the side benefit of reducing training costs for employers.Because more and more small companies are deploying the flexible and inexpensive OS wecall Linux, the demand for experienced users is growing. CompTIA anticipates that theLinux+ certification, like the A+ certification, will find itself integrated into various certifi-cation programs as well.Raises customer confidence As the IT community, users, small business owners, and thelike become more familiar with the Linux+ certified professional moniker, more of themwill realize that the Linux+ professional is more qualified to work in their Linux environ-ment than is a noncertified individual.How to Become Linux+ CertifiedThe Linux+ certification is available to anyone who passes the two required exams: LX0-101and LX0-102. You don’t have to work for a particular company. It’s not a secret society. The exam is administered by Thomson Prometric and Pearson VUE. The exam can betaken at any Thomson Prometric or Pearson VUE testing center. If you pass, you will get acertificate in the mail from CompTIA saying that you have passed, and you will also receive
Introduction xxiiia lapel pin and business cards. To fi nd the Thomson Prometric testing center nearest you,call (800) 755-EXAM (755-3926). Contact (877) 551-PLUS (551-7587) for Pearson VUEinformation. To register for the exam with Thomson Prometric, call (800) 776-MICRO (776-4276),or register online at http://securereg3.prometric.com. To register with Pearson VUE,call (877) 551-PLUS (551-7587), or register online at http://www.vue.com/comptia. How-ever you do it, you’ll be asked for your name, mailing address, phone number, employer,when and where you want to take the test (i.e., which testing center), and your credit cardnumber (arrangement for payment must be made at the time of registration). As noted above, if you pass the CompTIA Linux+ exams, you do have the option of also obtaining your LPIC-1 certification from LPI, as well as your Novell Certified Linux Administrator (CLA) certification at the same time . All that is required is authorization to submit your information to LPI . You are given this option at the testing site .Who Should Buy This BookAnybody who wants to pass the Linux+ exams may benefit from this book. If you’re newto Linux, this book covers the material you will need to learn the OS from the beginning,and it continues to provide the knowledge you need up to a proficiency level sufficient topass the LX0-101 and LX0-102 exams. You can pick up this book and learn from it even ifyou’ve never used Linux before, although you’ll fi nd it an easier read if you’ve at least casu-ally used Linux for a few days. If you’re already familiar with Linux, this book can serve asa review and as a refresher course for information with which you might not be completelyfamiliar. In either case, reading this book will help you to pass the Linux+ exams. This book is written with the assumption that you know at least a little bit about Linux(what it is, and possibly a few Linux commands). I also assume that you know some basicsabout computers in general, such as how to use a keyboard, how to insert a disc into a CD-ROM drive, and so on. Chances are, you have used computers in a substantial way in thepast—perhaps even Linux, as an ordinary user, or maybe you have used Windows or MacOS. I do not assume that you have extensive knowledge of Linux system administration,but if you’ve done some system administration, you can still use this book to fi ll in gaps inyour knowledge. As a practical matter, you’ll need a Linux system with which to practice and learn in a hands-on way . Neither the exams nor this book covers actually install- ing Linux