Ubuntu® Server Administration MICHAEL JANG New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto Copyright © 2009 by The McGraw-Hill Companies. All rights reserved. Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher. ISBN: 978-0-07-164370-2 MHID: 0-07-164370-2 The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-159892-7, MHID: 0-07-159892-8. All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps. McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs. To contact a representative please visit the Contact Us page at www.mhprofessional.com. Information has been obtained by McGraw-Hill from sources believed to be reliable. However, because of the possibility of human or mechanical error by our sources, McGraw-Hill, or others, McGraw-Hill does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from the use of such information. TERMS OF USE This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, trans- mit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent. You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these terms. THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill has no responsibility for the content of any information accessed through the work. Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise. Ubuntu: humanity towards others. ABOUT THE AUTHOR Michael Jang (RHCE, UCP, LPIC-2, LCP, Linux+, MCP) is currently a full-time writer who specializes in operating systems and networks. His experience with computers goes back to the days of jumbled punch cards. He has written other books on Linux certification, including RHCE Red Hat Certified Engineer Linux Study Guide, Ubuntu Certified Professional Study Guide, Linux+ Certification Passport, and Sair GNU/Linux Installation and Configuration Exam Cram. His other Linux books include Linux Annoyances for Geeks, Linux Patch Management, and Mastering Fedora Core Linux 5. He has also written or contributed to books on Microsoft operating systems, including MCSE Guide to Microsoft Windows 98 and Mastering Windows XP Professional, Second Edition. About the Technical Editor Elizabeth Zinkann is a logical Linux catalyst, a freelance technical editor, and an independent computer consultant. She was a contributing editor and review columnist for Sys Admin Magazine for 10 years. Some of her editing projects have included RHCE Red Hat Certified Engineer Linux Study Guide, Linux+ Certification Passport, Mastering Fedora Core Linux 5, Linux Patch Management, and Write Portable Code. She owns an iBook that thinks it’s an “UbuntuBook” and is an avid digital photographer. In a former life, she also programmed communications features, including ISDN, at AT&T Network Systems. CONTENTS Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix ▼ 1 The Ubuntu Community . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 A Short History of Ubuntu and Linux . . . . . . . . . . . . . . . . . . . . . . 2 Background on Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Linux Is Not Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 A Linux Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Linux and Open Source Licenses . . . . . . . . . . . . . . . . . . . . . 4 The Debian Project and Ubuntu . . . . . . . . . . . . . . . . . . . . . . 5 Ubuntu Just Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Hardy Heron Highlights . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 The Ubuntu Release Configuration . . . . . . . . . . . . . . . . . . . . . . . . 8 Past Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 The Ubuntu Development Cycle . . . . . . . . . . . . . . . . . . . . . 9 Support Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Desktop Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 The Ubuntu Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 v vi Ubuntu Server Administration Participate in the Ubuntu Community . . . . . . . . . . . . . . . . . . . . . 12 Sponsored by Canonical . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Request a “Hard Copy” Release with ShipIt . . . . . . . . . . . . 13 The Ubuntu Launchpad . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Ubuntu Community Resources . . . . . . . . . . . . . . . . . . . . . . 16 Launchpad Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 The Ubuntu Wiki . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Ubuntu News and Security Notices . . . . . . . . . . . . . . . . . . . 20 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 ▼ 2 Installing Ubuntu Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Acquire the Media . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Download the ISO File Online . . . . . . . . . . . . . . . . . . . . . . . 24 Download the ISO File from the Command Line . . . . . . . . . 26 Downloading the ISO File Cooperatively . . . . . . . . . . . . . . . 27 Write the ISO File to Disc . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Mount the ISO File on a Virtual Machine . . . . . . . . . . . . . . . 28 Mount the ISO File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Alternatives to Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Install from the CD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Stability or Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Hardware Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Linux Hardware Documentation . . . . . . . . . . . . . . . . . . . . . 31 The Ubuntu Server Installation Screen . . . . . . . . . . . . . . . . . 31 Install Ubuntu Server, Step by Step . . . . . . . . . . . . . . . . . . . . . . . . 34 Choose a Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Configure the Keyboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Detect and Mount the CD-ROM . . . . . . . . . . . . . . . . . . . . . . 39 Load the Debconf Preconfiguration File . . . . . . . . . . . . . . . . 39 Load Installer Components from the CD . . . . . . . . . . . . . . . 39 Detect Network Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Configure the Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Continue Installation Remotely Using SSH . . . . . . . . . . . . . 42 Choose a Mirror of the Ubuntu Archive . . . . . . . . . . . . . . . . 44 Download Installer Components . . . . . . . . . . . . . . . . . . . . . 45 Configure the Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Detect Disks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Partition Disks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Configure MD Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Install the Base System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Set Up Users and Passwords . . . . . . . . . . . . . . . . . . . . . . . . 53 Configure the Package Manager . . . . . . . . . . . . . . . . . . . . . 54 vii Contents Select and Install Software . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Build LTSP Chroot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Install the GRUB Boot Loader on a Hard Disk . . . . . . . . . . . 58 Install the LILO Boot Loader on a Hard Disk . . . . . . . . . . . . 59 Continue Without Boot Loader . . . . . . . . . . . . . . . . . . . . . . 59 Finish the Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Change Debconf Priority . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Check the CD-ROM(s) Integrity . . . . . . . . . . . . . . . . . . . . . 60 Save Debug Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Execute a Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Eject a CD from the Drive . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Abort the Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Finish the Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Network Installations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Dynamic Host Configuration Protocol (DHCP) Services . . . 64 Trivial File Transfer Protocol . . . . . . . . . . . . . . . . . . . . . . . . 66 Configure a Network Installation . . . . . . . . . . . . . . . . . . . . . 66 PXE Booting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 ▼ 3 Automated Installations with Kickstart . . . . . . . . . . . . . . . . . . . . . . . . . . 69 How to Kickstart an Installation . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Install the Kickstart Software . . . . . . . . . . . . . . . . . . . . . . . . 70 Use the Kickstart Configuration Tool . . . . . . . . . . . . . . . . . . 71 Customize the Kickstart File . . . . . . . . . . . . . . . . . . . . . . . . . 81 Boot an Installation with a Kickstart File . . . . . . . . . . . . . . . 84 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 ▼ 4 The Boot Process and Rescue Mode . . . . . . . . . . . . . . . . . . . . . . . . . . 87 What Happens After Powering Up . . . . . . . . . . . . . . . . . . . . . . . . 88 The BIOS Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Making GRUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Kernels and Hardware Detection . . . . . . . . . . . . . . . . . . . . . 96 Upstart, RCs Scripts, and Services . . . . . . . . . . . . . . . . . . . . 96 Rescue Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Recovery and Single-User Mode . . . . . . . . . . . . . . . . . . . . . 100 Using the GRUB Command Line . . . . . . . . . . . . . . . . . . . . . 102 The Installation CD Rescue Mode . . . . . . . . . . . . . . . . . . . . 104 Using a LiveCD/DVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 viii Ubuntu Server Administration ▼ 5 Filesystem Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Make the Filesystem Work for You . . . . . . . . . . . . . . . . . . . . . . . . 110 The Filesystem Hierarchy Standard . . . . . . . . . . . . . . . . . . . 110 Partition Device Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 Create Partitions with fdisk . . . . . . . . . . . . . . . . . . . . . . . . . 113 The parted Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Format New Filesystems . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Manage Filesystems in /etc/fstab . . . . . . . . . . . . . . . . . . . . 124 How to Make RAID Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 RAID Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Create RAID Partitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Format and Configure a RAID Array . . . . . . . . . . . . . . . . . . 130 Use an Active RAID Array . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Maintaining RAID Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Make RAID Work in /etc/fstab . . . . . . . . . . . . . . . . . . . . . . 132 Logical Volumes Promote Flexibility . . . . . . . . . . . . . . . . . . . . . . . 133 Logical Volume Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Create Physical Volumes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Creating a Volume Group . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Creating a Logical Volume . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Activate Logical Volumes . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 Configure Logical Volumes in /etc/fstab . . . . . . . . . . . . . . . 139 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 ▼ 6 Command Line Tools and Shell Management . . . . . . . . . . . . . . . . . . . . 141 Command Line Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Interactivity and Command Completion . . . . . . . . . . . . . . . 142 Navigate Around Directories . . . . . . . . . . . . . . . . . . . . . . . . 144 File Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 Quotes and Backslashes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Wildcards in a Glob . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 File Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Command Combinations and Data Streams . . . . . . . . . . . . 153 Set the Default Linux Text Editor . . . . . . . . . . . . . . . . . . . . . 154 Optimize the Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Profiles in Bash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 A Minor in Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Variables and More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Manage Permissions, Octal and Super . . . . . . . . . . . . . . . . . . . . . 158 Basic File Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Commands to Modify Permissions and Ownership . . . . . . 159 ix Contents Special File Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Access Control Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 ▼ 7 Basic Administrative Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Create a Secure Shell Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Configuring the SSH Server . . . . . . . . . . . . . . . . . . . . . . . . . 168 Passphrases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 A Warning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Client Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Telnet if You Must . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Schedule Important Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Standard cron Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 User cron Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Configure at Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Job Scheduling Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 Customize Services and Runlevels . . . . . . . . . . . . . . . . . . . . . . . . 181 Script Actions in Different Runlevels . . . . . . . . . . . . . . . . . . 181 Manage when a Service Starts and Stops . . . . . . . . . . . . . . . 182 Manage Those Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 General Log Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 185 General Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 Service-Specific Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 Log Rotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 ▼ 8 Manage Updates and Local Repositories . . . . . . . . . . . . . . . . . . . . . . . 191 The Basics of dpkg and apt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 A Background in dpkg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 Ubuntu Repository Organization . . . . . . . . . . . . . . . . . . . . . 194 Repository Source Management . . . . . . . . . . . . . . . . . . . . . . 195 Find the Right Mirror . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 Fundamental apt Commands . . . . . . . . . . . . . . . . . . . . . . . . 198 More apt Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 Update Management Tools . . . . . . . . . . . . . . . . . . . . . . . . . . 202 The Task Selector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 Keep the Server Up-to-Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Security Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Kernel Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Application Updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Description: