® UNIX System Administration Handbook Third Edition Evi Nemeth Garth Snyder Scott Seebass Trent R. Hein with Adam Boggs, Rob Braun, Dan Crawl, Ned McClain, Lynda McGinley, and Todd Miller Prentice Hall PTR Upper Saddle River, NJ 07458 www.phptr.com Editorial/production supervisor: Patti Guerrieri Acquisitions editor: Mary Franz Marketing manager: Bryan Gambrel Manufacturing manager: Maura Zaldivar Editorial assistant: Noreen Regina Cover design director: Jerry Votta Cover designers: Garth Snyder and Tyler Curtain © 2001 by Prentice Hall PTR Prentice-Hall, Inc. Upper Saddle River, NJ 07458 All rights reserved. No part of this book may be reproduced, in any form or by any means, without written permission from the publisher. Prentice Hall books are widely used by corporations and government agencies for training, marketing, and resale. Volume discounts are available. For more information, contact the corporate sales department: Prentice Hall PTR Phone: (800) 382-3419 Corporate sales department Fax: (201) 236-7141 One Lake Street Email: [email protected] Upper Saddle River, NJ 07458 The names of all products and services mentioned in this book are the trademarks or service marks of their respective companies or organizations. Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 ISBN 0-13-020601-6 Prentice-Hall International (UK) Limited, London Prentice-Hall of Australia Pty. Limited, Sydney Prentice-Hall Canada Inc., Toronto Prentice-Hall Hispanoamericana, S.A., Mexico Prentice-Hall of India Private Limited, New Delhi Prentice-Hall of Japan, Inc., Tokyo Pearson Education Asia Pte. Ltd. Editora Prentice-Hall do Brasil, Ltda., Rio de Janeiro We dedicate this edition of UNIX System Administration Handbook to the memory of three giants in the UNIX and Internet worlds: John Lions, Jon Postel, and Rich Stevens. John Lions, a professor at the University of New South Wales, wrote a wonderful commentary on the UNIX source code in the mid-1970s. It explained the 10,000 lines of code that made up UNIX in those days; John’s book was used in operating systems classes around the world. A copyright dispute forced the book out of print, but it circulated among students for years in the form of photocopies of photocopies. Ours is hardly readable. John died in December, 1998. Jon Postel was the editor of the RFC series (as well as the author of many RFCs), the benevolent dictator of Internet names and numbers, and the technical conscience of the Internet. For years he led the way as the Internet was transformed from a playground of geeks and university students to perhaps the most significant social and economic force since the industrial revolution. Jon died in October, 1998. (www.postel.org) Rich Stevens is well known in academia for his wonderful books on networking and UNIX programming. Students love these books because Rich’s examples always show exactly how to do something or just how to find out what the network protocols are really doing. Rich’s generous contributions to the Internet community often took the form of answers to TCP questions raised on network- related mailing lists. It’s hard to imagine a more accessible or more authoritative source; the second volume of Rich’s TCP/IP Illustrated series was effectively the definition of TCP. Rich died in September, 1999. (www.kohala.com) Table of Contents FOREWORD FOREWORD TO THE SECOND EDITION FOREWORD TO THE FIRST EDITION PREFACE ACKNOWLEDGMENTS BASIC ADMINISTRATION CHAPTER 1 WHERE TO START Suggested background The sordid history of UNIX Example UNIX systems Notation and typographical conventions System-specific information How to use your manuals Organization of the man pages man: read manual pages Essential tasks of the system administrator Adding and removing users Adding and removing hardware Performing backups Installing new software Monitoring the system Troubleshooting Maintaining local documentation Auditing security Helping users How to find files on the Internet System administration under duress System Administration Personality Syndrome Recommended reading CHAPTER 2 BOOTING AND SHUTTING DOWN Bootstrapping Automatic and manual booting Steps in the boot process Kernel initialization Hardware configuration System processes Operator intervention (manual boot only) Execution of startup scripts Multiuser operation Booting PCs How a PC is different from proprietary hardware The PC boot process LILO: the Linux boot loader Configuring LILO The FreeBSD boot loader Multibooting on PCs Multibooting gotchas LILO multiboot configuration FreeBSD multiboot configuration Booting in single-user mode Solaris single-user mode HP-UX single-user mode Linux single-user mode FreeBSD single-user mode Startup scripts SystemV-style startup scripts Solaris startup scripts HP-UX startup scripts Red Hat startup scripts FreeBSD startup scripts Rebooting and shutting down Turning off the power shutdown: the genteel way to halt the system halt: a simpler way to shut down reboot: quick and dirty restart Sending init a TERM signal telinit: change init’s run level Killing init CHAPTER 3 ROOTLY POWERS Ownership of files and processes The superuser Choosing a root password Becoming root su: substitute user identity sudo: a limited su Other pseudo-users daemon: owner of unprivileged system software bin: owner of system commands sys: owner of the kernel and memory images nobody: the generic NFS user CHAPTER 4 CONTROLLING PROCESSES Components of a process PID: process ID number PPID: parent PID UID and EUID: real and effective user ID GID and EGID: real and effective group ID Niceness Control terminal The life cycle of a process Signals kill: send signals Process states nice and renice: influence scheduling priority ps: monitor processes top: monitor processes even better Runaway processes CHAPTER 5 THE FILESYSTEM Pathnames Mounting and unmounting filesystems The organization of the file tree File types Regular files Directories Character and block device files UNIX domain sockets Named pipes Symbolic links File attributes The setuid and setgid bits The sticky bit The permission bits