Linux System Administration Table of Contents Linux System Administration, Second Edition...............................................................................1 Foreword............................................................................................................................................3 Acknowledgments....................................................................................................................3 Introduction........................................................................................................................................4 The Benefits of Linux...............................................................................................................4 Who Should Buy This Book.....................................................................................................5 About the Second Edition........................................................................................................5 How This Book Is Organized...................................................................................................6 Chapter 1: The Basics of System Administration...............................................................6 Chapter 2: Installing Linux..................................................................................................6 Chapter 3: Startup and Shutdown......................................................................................6 Chapter 4: Tools of the Trade............................................................................................7 Chapter 5: Creating and Maintaining User Accounts.........................................................7 Chapter 6: Filesystems and Disk Management.................................................................7 Chapter 7: Linux Files and Processes...............................................................................7 Chapter 8: Software Administration...................................................................................7 Chapter 9: Backup and Restore.........................................................................................7 Chapter 10: Printers and the Spooling Subsystem............................................................7 Chapter 11: Serial Communications, Terminals, and Modems..........................................7 Chapter 12: TCP/IP Linux Networking...............................................................................8 Chapter 13: The X Window System...................................................................................8 Chapter 14: Setting Up Your Mail Server...........................................................................8 Chapter 15: Security..........................................................................................................8 Chapter 16: Performance Tuning.......................................................................................8 Chapter 17: Making Your Job Easier with Scripts..............................................................8 Chapter 18: Troubleshooting Your Linux System..............................................................8 Conventions Used in This Book...............................................................................................9 Help Us Help You..................................................................................................................10 Part I: The Basics.............................................................................................................................11 Chapter List............................................................................................................................11 Featuring................................................................................................................................11 Chapter 1: The Basics of System Administration........................................................................12 Overview................................................................................................................................12 Your Role as a System Administrator....................................................................................12 Tasks of a System Administrator...........................................................................................13 Configuring Hardware......................................................................................................13 Installing the Operating System.......................................................................................14 Installing Application Software.........................................................................................14 System Security...............................................................................................................14 Configuring the Kernel.....................................................................................................14 Creating Users and Groups.............................................................................................15 Software Updates.............................................................................................................15 Performance Tuning.........................................................................................................15 Disaster Recovery............................................................................................................15 Capacity Planning............................................................................................................16 Network Administration....................................................................................................16 i Table of Contents Chapter 1: The Basics of System Administration "When You Have a Minute..."...........................................................................................16 Tools of the Linux Administrator............................................................................................16 Commands.......................................................................................................................17 System Logbook..............................................................................................................18 Communicating with Users..............................................................................................20 Working on the System as Root............................................................................................21 Becoming the Root User..................................................................................................21 In Sum....................................................................................................................................23 Chapter 2: Installing Linux..............................................................................................................24 Overview................................................................................................................................24 Benchmarks...........................................................................................................................24 Selecting Hardware................................................................................................................25 Minimal Acceptable Hardware.........................................................................................25 CPU Performance............................................................................................................25 Random Access Memory.................................................................................................26 Selecting Hardware by Intended Usage...........................................................................27 Specialized Hardware Performance Solutions.................................................................28 Types of Hardware to Avoid.............................................................................................33 Selecting a Linux Distribution.................................................................................................35 Red Hat Linux..................................................................................................................35 Mandrake.........................................................................................................................37 Caldera.............................................................................................................................37 SuSE Linux......................................................................................................................38 Slackware Linux...............................................................................................................38 Debian..............................................................................................................................39 The Choice Is Yours.........................................................................................................39 Installing Red Hat Linux.........................................................................................................40 Preparing for Installation..................................................................................................40 Choosing a Partitioning Scheme......................................................................................41 Installing a Server............................................................................................................42 Installing a Workstation....................................................................................................50 Tying Up Loose Ends.......................................................................................................51 In Sum....................................................................................................................................51 Chapter 3: Startup and Shutdown..................................................................................................52 Overview................................................................................................................................52 The Linux Boot Process.........................................................................................................52 The Master Boot Record..................................................................................................53 Boot Loaders..........................................................................................................................55 GRUB: Definition and Configuration................................................................................55 LILO: Definition and Configuration...................................................................................57 Creating a Boot Floppy..........................................................................................................60 Creating a LILO Boot Floppy............................................................................................60 Creating a Boot Floppy without a Boot Loader................................................................61 Using LOADLIN.....................................................................................................................61 Single−User Mode.................................................................................................................62 Initialization and Startup Scripts.............................................................................................63 The Red Hat Model..........................................................................................................63 ii Table of Contents Chapter 3: Startup and Shutdown The Debian Model............................................................................................................67 User Initialization Files...........................................................................................................70 Modifying the Startup Procedure......................................................................................71 Startup Log Files..............................................................................................................75 Shutdown...............................................................................................................................76 Warning Users.................................................................................................................76 Shutdown Log Files..........................................................................................................76 In Sum....................................................................................................................................77 Chapter 4: Tools of the Trade.........................................................................................................78 Overview................................................................................................................................78 Locating Help Resources.......................................................................................................78 Man Pages.......................................................................................................................79 Info Pages........................................................................................................................81 Technical Support..................................................................................................................83 Configuration Support......................................................................................................83 Tailored Linux Development............................................................................................84 General Web Support......................................................................................................84 Webmin..................................................................................................................................85 Command−Line Tools............................................................................................................85 The Bash Shell.................................................................................................................86 Basic Commands.............................................................................................................91 In Sum..................................................................................................................................109 Part II: Managing Users, Processes, and Files...........................................................................110 Chapter List..........................................................................................................................110 Featuring..............................................................................................................................110 Chapter 5: Creating and Maintaining User Accounts.................................................................111 Overview..............................................................................................................................111 User Accounts......................................................................................................................111 The /etc/passwd File......................................................................................................112 Shadowed Passwords....................................................................................................113 Adding New Users.........................................................................................................116 Modifying User Accounts...............................................................................................118 Disabling User Accounts................................................................................................121 Deleting User Accounts..................................................................................................122 Groups.................................................................................................................................123 The Function of Groups.................................................................................................124 The /etc/group File.........................................................................................................124 Adding New Groups.......................................................................................................126 Modifying Groups...........................................................................................................128 Deleting Groups.............................................................................................................129 In Sum..................................................................................................................................130 Chapter 6: Filesystems and Disk Management..........................................................................131 Overview..............................................................................................................................131 Linux Filesystem Support.....................................................................................................131 Locating Filesystems......................................................................................................131 iii Table of Contents Chapter 6: Filesystems and Disk Management Linux Native Filesystems...............................................................................................133 Foreign Filesystems.......................................................................................................137 Network Filesystems......................................................................................................140 Filesystem Design................................................................................................................141 The Physical Structure...................................................................................................141 Inodes and Directories...................................................................................................141 Accessing Filesystems.........................................................................................................142 Mounting and Unmounting Filesystems.........................................................................142 Using Removable Media................................................................................................149 Using Swap Space.........................................................................................................153 Updating and Maintaining Filesystems................................................................................154 Disk Partitioning.............................................................................................................154 Creating a Filesystem....................................................................................................158 Adding a Disk.................................................................................................................159 Replacing a Disk............................................................................................................160 Checking Filesystem Integrity........................................................................................161 In Sum..................................................................................................................................162 Chapter 7: Linux Files and Processes.........................................................................................163 Overview..............................................................................................................................163 The Filesystem Hierarchy Standard.....................................................................................163 Directory Layout.............................................................................................................165 File Characteristics..............................................................................................................167 Determining a Linux File's Type.....................................................................................168 File Types Defined.........................................................................................................170 Processes............................................................................................................................174 The Concept of Multitasking...........................................................................................174 Types of Processes........................................................................................................175 Parent Processes and Their Children............................................................................178 The init Process.............................................................................................................179 Managing Processes......................................................................................................180 Terminating/Restarting with the kill Command...............................................................182 Terminating/Restarting Processes Using Scripts...........................................................183 In Sum..................................................................................................................................184 Chapter 8: Software Administration............................................................................................185 Overview..............................................................................................................................185 Installing Binary Packages...................................................................................................185 Installing an RPM...........................................................................................................185 Installing a Debian Package...........................................................................................189 Installing a Tarball..........................................................................................................190 Compiling Source Code.......................................................................................................191 Compiling from Packages..............................................................................................191 Compiling Tarballs.........................................................................................................192 Kernel Compilation...............................................................................................................194 Why Compile Your Kernel?............................................................................................194 Obtaining a Kernel.........................................................................................................195 Kernel Configuration Options.........................................................................................195 Compiling the Kernel......................................................................................................199 iv Table of Contents Chapter 8: Software Administration Installing the Kernel and Modules..................................................................................200 Testing Your New Kernel...............................................................................................201 Checking for OS Updates....................................................................................................202 The Importance of OS Updates.....................................................................................202 Locating Updates for Your Distribution..........................................................................203 Update Utilities...............................................................................................................205 In Sum..................................................................................................................................206 Chapter 9: Backup and Restore...................................................................................................207 Overview..............................................................................................................................207 Backup Strategies................................................................................................................207 Combining Full and Incremental Backups......................................................................207 Including Differential Backups........................................................................................208 Data−Specific Backups..................................................................................................209 Backup Media......................................................................................................................209 Tapes.............................................................................................................................210 CD−R and CD−RW........................................................................................................215 Other Alternatives..........................................................................................................216 Media Storage................................................................................................................217 Backup Commands and Utilities....................................................................................217 CD−R and CD−RW Backup Tools.................................................................................219 Linux Backup and Restore Tools.........................................................................................224 dump..............................................................................................................................224 restore............................................................................................................................227 tar...................................................................................................................................228 cpio................................................................................................................................233 afio.................................................................................................................................234 Third−Party Tools...........................................................................................................236 Tips while Restoring.......................................................................................................238 Backing Up the Operating System.......................................................................................239 Minimal Backups............................................................................................................239 Complete Backups.........................................................................................................240 Disaster Recovery Techniques............................................................................................240 Single−User Mode.........................................................................................................241 Using a Boot Floppy.......................................................................................................241 Rescue Mode.................................................................................................................242 Third−Party Recovery Software.....................................................................................244 In Sum..................................................................................................................................244 Part III: Communications and Networking..................................................................................246 Chapter List..........................................................................................................................246 Featuring..............................................................................................................................246 Chapter 10: Printers and the Spooling Subsystem....................................................................247 Overview..............................................................................................................................247 Printer Basics.......................................................................................................................247 Types of Printers............................................................................................................247 Printer Interfaces............................................................................................................250 The Linux Printing Process..................................................................................................252 v Table of Contents Chapter 10: Printers and the Spooling Subsystem Tools of the Printing Trade.............................................................................................252 The LPRng Print Spooler...............................................................................................254 Alternative Printing Utilities............................................................................................258 Configuring Printers Using Red Hat's Printconf...................................................................259 Configuring Printers in Webmin...........................................................................................262 Printing with Other Distributions...........................................................................................262 Debian............................................................................................................................262 SuSE..............................................................................................................................262 Slackware.......................................................................................................................263 Kernel Support.....................................................................................................................263 Parallel−Port Printers.....................................................................................................263 RS−232 Serial Devices..................................................................................................265 USB Devices..................................................................................................................265 Remote Printing.............................................................................................................265 In Sum..................................................................................................................................268 Chapter 11: Serial Communications, Terminals, and Modems.................................................269 Overview..............................................................................................................................269 Understanding Serial Devices..............................................................................................269 Standard Serial Devices.................................................................................................269 Unusual Serial Devices..................................................................................................274 Configuring Terminals..........................................................................................................275 Understanding Terminals...............................................................................................275 Configuring a getty Program..........................................................................................276 Using a Serial−Port Console..........................................................................................278 Configuring Modems............................................................................................................279 Dial−out Modem Uses....................................................................................................279 Dial−in Modem Uses......................................................................................................288 Configuring Serial Printers...................................................................................................291 Special Considerations for Serial Printers......................................................................292 When to Use a Serial Printer..........................................................................................292 In Sum..................................................................................................................................292 Chapter 12: TCP/IP Linux Networking.........................................................................................294 Overview..............................................................................................................................294 Understanding TCP/IP Networking......................................................................................294 Network Stacks..............................................................................................................294 Network Addresses........................................................................................................296 Ports...............................................................................................................................298 TCP/IP Configuration...........................................................................................................299 Configuring Network Hardware......................................................................................299 Using DHCP for Configuration.......................................................................................300 Manually Configuring TCP/IP.........................................................................................302 Testing the Setup...........................................................................................................306 File Sharing..........................................................................................................................307 Sharing with Unix or Linux: NFS....................................................................................307 Sharing with Windows: Samba......................................................................................310 Internet Servers...................................................................................................................316 Available Servers...........................................................................................................316 vi Table of Contents Chapter 12: TCP/IP Linux Networking Using a Super Server.....................................................................................................318 In Sum..................................................................................................................................321 Chapter 13: The X Window System..............................................................................................323 Overview..............................................................................................................................323 X Concepts..........................................................................................................................323 X as a Network Protoco.l................................................................................................323 X Security.......................................................................................................................325 X Virtual Consoles..........................................................................................................327 Configuring an X Server.......................................................................................................328 XFree86 4.x....................................................................................................................328 XFree86 3.3.x.................................................................................................................330 Using an X Configuration Tool.......................................................................................331 Starting X Automatically.................................................................................................333 Configuring a Font Server....................................................................................................334 Adding Fonts to a Font Server.......................................................................................334 Configuring a New Font Server......................................................................................336 Unusual Font Servers....................................................................................................337 Building a User Interface atop X..........................................................................................338 Window Managers.........................................................................................................338 Widget Sets....................................................................................................................341 Desktop Environments...................................................................................................341 X Applications................................................................................................................343 In Sum..................................................................................................................................344 Chapter 14: Setting Up Your Mail Server.....................................................................................345 Overview..............................................................................................................................345 Understanding E−Mail Protocols..........................................................................................345 Push and Pull Protocols.................................................................................................345 SMTP.............................................................................................................................347 POP...............................................................................................................................348 IMAP..............................................................................................................................349 Configuring Sendmai.l..........................................................................................................351 Configuring Domains......................................................................................................351 Sendmail Configuration Files and Procedures...............................................................352 Address Masquerading..................................................................................................353 Configuring Relays.........................................................................................................354 Receiving Mail................................................................................................................357 Configuring POP and IMAP.................................................................................................358 Running POP and IMAP Daemons................................................................................358 Setting Up Mail−Only Accounts.....................................................................................359 Using Fetchmail to Acquire Mail from an ISP.................................................................360 Anti−Spam Measures..........................................................................................................364 The Problem of Spam....................................................................................................364 Preventing Outgoing Spam............................................................................................364 Stopping Incoming Spam...............................................................................................366 In Sum..................................................................................................................................369 vii Table of Contents Part IV: System Optimization and Improvement.........................................................................370 Chapter List..........................................................................................................................370 Featuring..............................................................................................................................370 Chapter 15: Security......................................................................................................................371 Overview..............................................................................................................................371 Types of Attacks..................................................................................................................372 Trojan Horse..................................................................................................................372 Back Door......................................................................................................................373 Trusted Host...................................................................................................................373 Buffer Overflow..............................................................................................................374 Scanning or Sniffing.......................................................................................................374 Spoofing.........................................................................................................................374 Denial of Service............................................................................................................375 Password Cracking........................................................................................................375 Social Attacks.................................................................................................................376 Physical Attacks.............................................................................................................376 Types of Security.................................................................................................................377 Securing the Authentication Process...................................................................................379 Hashing Passwords.......................................................................................................379 Shadow Passwords........................................................................................................381 Pluggable Authentication Modules (PAM)......................................................................382 File Permissions...................................................................................................................386 Protecting against Network Intrusion...................................................................................387 Firewalls.........................................................................................................................387 TCP Wrappers...............................................................................................................403 xinetd.............................................................................................................................406 Detecting Intrusion.........................................................................................................406 Applications for Detecting Intrusion................................................................................407 In Sum..................................................................................................................................408 Chapter 16: Performance Tuning.................................................................................................409 Overview..............................................................................................................................409 The Elements of Performance.............................................................................................409 Hardware Performance..................................................................................................409 Software Performance...................................................................................................411 Measuring Performance.......................................................................................................411 Finding Bottlenecks..............................................................................................................412 Using top to Find the Bottleneck....................................................................................412 traceroute.......................................................................................................................415 Tuning the System...............................................................................................................416 nice and renice...............................................................................................................416 Virtual Memory Tuning...................................................................................................417 Serial Port Tuning..........................................................................................................418 Filesystem Tuning..........................................................................................................418 Eliminating Unnecessary Processes..............................................................................422 Compiling for Efficiency..................................................................................................423 Tuning the X Window System........................................................................................425 Upgrading............................................................................................................................426 In Sum..................................................................................................................................426 viii Table of Contents Chapter 17: Making Your Job Easier with Scripts......................................................................428 Overview..............................................................................................................................428 Common Scripting Features................................................................................................428 Identifying a Script..........................................................................................................429 Variables........................................................................................................................429 Control Statements........................................................................................................430 Commands.....................................................................................................................430 The Bash Shell Scripting Language.....................................................................................431 Variables........................................................................................................................431 Conditional Expressions.................................................................................................432 Loops.............................................................................................................................434 Other Types of Scripts.........................................................................................................436 Perl Scripts.....................................................................................................................436 Python Scripts................................................................................................................438 awk and sed Scripts.......................................................................................................438 System Initialization Scripts.................................................................................................440 Writing an Initialization Script.........................................................................................440 Tailoring the rc.local Script.............................................................................................445 Using the cron Facility..........................................................................................................447 Running a Script at a Specific Time.....................................................................................449 Commands Often Used in Shell Scripts...............................................................................449 cat..................................................................................................................................450 cut..................................................................................................................................450 echo...............................................................................................................................451 sort.................................................................................................................................451 xargs..............................................................................................................................452 Using Pipes....................................................................................................................453 In Sum..................................................................................................................................453 Chapter 18: Troubleshooting Your Linux System......................................................................454 Overview..............................................................................................................................454 General Troubleshooting Techniques..................................................................................454 Boot Problems.....................................................................................................................456 FDISK Doesn't Recognize GNU/Hurd Partition.............................................................456 Making a New Boot Floppy to Replace a Lost One.......................................................456 GRUB Is Installed but Just Hangs..................................................................................457 LILO Messages and Their Meanings.............................................................................457 Making the System Boot a New Kerne.l.........................................................................458 Hardware Not Detected at Boot.....................................................................................459 Dual−booting with Another OS Like Windows...............................................................460 Can't Remove Boot Loader from the Master Boot Record.............................................461 Kernel Won't Load or Loads Only Partially....................................................................461 Login Problems....................................................................................................................461 Lost Password................................................................................................................461 Login Incorrect after Entering Username.......................................................................462 System Flashes Quick Message and Drops Back to login Prompt................................462 Login incorrect Message Logging in as root..................................................................463 Network Problems................................................................................................................463 Unknown Host Message................................................................................................463 Network Unreachable Message.....................................................................................464 ix
Description: