Table Of ContentTEAM LinG - Live, Informative, Non-cost and Genuine!
00 0672323982 FM 6/18/02 2:05 PM Page i
Teach Yourself
Unix System
Administration
24
in
Hours
Dave Taylor
800 East 96th St., Indianapolis, Indiana, 46240 USA
TEAM LinG - Live, Informative, Non-cost and Genuine!
00 0672323982 FM 6/18/02 2:05 PM Page ii
Sams Teach Yourself Unix System ACQUISITIONSEDITOR
Kathryn Purdum
Administration in 24 Hours
DEVELOPMENTEDITOR
Copyright © 2003 by Sams Publishing Heather Goodell
All rights reserved. No part of this book shall be reproduced,stored in a MANAGINGEDITOR
retrieval system,or transmitted by any means,electronic,mechanical,photo- Charlotte Clapp
copying,recording,or otherwise,without written permission from the pub-
PROJECTEDITOR
lisher. No patent liability is assumed with respect to the use of the information
Elizabeth Finney
contained herein. Although every precaution has been taken in the preparation
of this book,the publisher and author assume no responsibility for errors or PRODUCTIONEDITOR
omissions. Nor is any liability assumed for damages resulting from the use of Seth Kerney
the information contained herein.
INDEXER
International Standard Book Number:0-672-32398-2 Larry Sweazy
Library of Congress Catalog Card Number:2001099557 PROOFREADER
Suzanne Thomas
Printed in the United States of America
TECHNICALEDITORS
First Printing:July 2002
Dee-Ann LeBlanc
05 04 03 02 4 3 2 1 David Ennis
Trademarks TEAMCOORDINATOR
Amy Patton
All terms mentioned in this book that are known to be trademarks or service
marks have been appropriately capitalized. Sams Publishing cannot attest to the INTERIORDESIGNER
accuracy of this information. Use of a term in this book should not be regarded Gary Adair
as affecting the validity of any trademark or service mark. COVERDESIGNER
Alan Clements
Warning and Disclaimer
PAGELAYOUT
Every effort has been made to make this book as complete and as accurate as
Stacey Richwine-DeRome
possible,but no warranty or fitness is implied. The information provided is on
an “as is”basis. The author and the publisher shall have neither liability nor
responsibility to any person or entity with respect to any loss or damages aris-
ing from the information contained in this book.
TEAM LinG - Live, Informative, Non-cost and Genuine!
00 0672323982 FM 6/18/02 2:05 PM Page iii
Contents at a Glance
Introduction 1
PART I Installing Unix 5
Hour 1 Installing Unix 7
PART II Introduction to the Filesystem 21
Hour 2 An Unsung Resource:Unix Documentation 23
3 Disk Usage 41
4 File Ownership 67
PART III User & Package Management 83
Hour 5 Working with User Accounts 85
6 Account Management 107
7 Large File Management & Backups 133
8 Unix Package Management 161
PART IV Advanced Filesystem Topics 179
Hour 9 Fixing Broken Disks 181
10 Adding Disks to Your System 197
11 Multiple Boot Configurations 217
12 Managing Disk Quotas 231
PART V Process & System Controls 245
Hour 13 Changing System State 247
14 Exploring Processes 265
15 Running Jobs in the Future 285
16 Managing Your Log Files 301
PART VI Network Topics 325
Hour 17 Basic Network Configuration 327
18 Running Your Own Name Server 353
19 Running Internet Services 373
20 Working with E-mail 391
TEAM LinG - Live, Informative, Non-cost and Genuine!
00 0672323982 FM 6/18/02 2:05 PM Page iv
PART VII Web Server Management & Shell Programming 413
Hour 21 Shell Scripting:The Administrator’s Swiss Army Knife 415
22 Power Scripting with awkand Perl 443
23 Introduction to the Apache Web Server 457
24 Virtual Hosts with Apache 473
Index 483
TEAM LinG - Live, Informative, Non-cost and Genuine!
00 0672323982 FM 6/18/02 2:05 PM Page v
Contents
Introduction 1
PART I Installing Unix 5
HOUR 1 Installing Unix 7
Unix Installation Options........................................................................................8
Basic Red Hat Linux Installation..........................................................................10
Installation Help Online........................................................................................16
Summary................................................................................................................17
Q&A......................................................................................................................17
Workshop ..............................................................................................................18
Quiz..................................................................................................................18
Answers............................................................................................................18
PART II Introduction to the Filesystem 21
HOUR 2 An Unsung Resource: Unix Documentation 23
The Philosophy of Digging....................................................................................23
apropos:The Administrator’s Secret Weapon ....................................................24
Task 2.1:aproposand the WhatisDatabase..................................................24
Exploring the whatisDatabase............................................................................32
Task 2.2:What’s Inside the whatisDatabase ................................................32
Finding Commands................................................................................................34
Task 2.3:Which Command Are You Running? ..............................................34
Digging Around in Executable Binaries................................................................37
Task 2.4:The stringsCommand ..................................................................37
Summary................................................................................................................39
Q&A......................................................................................................................39
Workshop ..............................................................................................................39
Quiz..................................................................................................................39
Answers............................................................................................................40
HOUR 3 Disk Usage 41
Physical Disks and Partitions................................................................................41
Task 3.1:Exploring Partitions..........................................................................42
A Closer Look with du..........................................................................................47
Task 3.2:Using duto Ascertain Directory Sizes ............................................47
Simplifying Analysis with sort............................................................................52
Task 3.3:Piping Output to sort......................................................................53
Identifying the Biggest Files..................................................................................55
Task 3.4:Finding Big Files..............................................................................55
TEAM LinG - Live, Informative, Non-cost and Genuine!
00 0672323982 FM 6/18/02 2:05 PM Page vi
vi Sams Teach Yourself Unix Administration in 24 Hours
Keeping Track of Users:diskhogs ......................................................................59
Task 3.5:This Little Piggy Stayed Home?......................................................59
Summary................................................................................................................64
Q&A......................................................................................................................64
Workshop ..............................................................................................................64
Quiz..................................................................................................................64
Answers............................................................................................................65
HOUR 4 File Ownership 67
Starting at the Beginning:Permission Strings......................................................67
Task 4.1:The Basics of File Permissions........................................................68
Ownership and /etc/passwd................................................................................70
Task 4.2:Understanding /etc/passwd............................................................70
Understanding Unix Groups and /etc/group......................................................73
Task 4.3:Groups and the /etc/groupfile......................................................74
Using Groups to Control Access ..........................................................................77
Task 4.4:Access Control with Groups ............................................................77
Summary................................................................................................................80
Q&A......................................................................................................................80
Workshop ..............................................................................................................80
Questions..........................................................................................................80
Answers............................................................................................................81
PART III User & Package Management 83
HOUR 5 Working with User Accounts 85
Understanding the /etc/passwdFile ..................................................................86
Task 5.1:Exploring /etc/passwd ..................................................................86
Password Files in BSD/Mac OS X........................................................................91
Task 5.2:Accounts and the Password File in Darwin......................................91
Adding Users and the adduserScript..................................................................94
Task 5.3:Adding Users in a Conventional Unix World ..................................95
Adding Users in a NetInfo World........................................................................100
Task 5.4:The Darwin Version of adduser....................................................100
Summary..............................................................................................................103
Q&A....................................................................................................................103
Workshop ............................................................................................................104
Quiz................................................................................................................104
Answers..........................................................................................................104
HOUR 6 Accounts Management 83
Ways to Suspend User Accounts ........................................................................108
Task 6.1:Suspending Users............................................................................108
Deleting User Accounts ......................................................................................112
Task 6.2:Deleting User Accounts..................................................................112
TEAM LinG - Live, Informative, Non-cost and Genuine!
00 0672323982 FM 6/18/02 2:05 PM Page vii
Contents vii
Linux Account Management Tools114
Task 6.3:Linux Admin Tools ........................................................................115
Solaris Account Management Tools....................................................................121
Task 6.4:Solaris Account Administration Tools............................................121
Password Aging ..................................................................................................126
Task 6.5:Tools for Managing Password Aging ............................................126
Summary..............................................................................................................129
Q&A....................................................................................................................130
Workshop ............................................................................................................130
Quiz................................................................................................................130
Answers..........................................................................................................130
HOUR 7 Large File Management and Backups 133
Shrinking Big Files with compress....................................................................134
Task 7.1:Working with compress ................................................................134
ThegzipAlternative ..........................................................................................138
Task 7.2:Working with gzip ........................................................................139
A Zippy Tour of zip............................................................................................145
Task 7.3:Working with zip ..........................................................................145
Copying Directory Trees with tar......................................................................148
Task 7.4:Working with tar ..........................................................................149
dumpand System Backups ..................................................................................153
Task 7.5:Incremental Backups......................................................................153
Summary..............................................................................................................158
Q&A....................................................................................................................158
Workshop ............................................................................................................159
Quiz................................................................................................................159
Answers..........................................................................................................159
HOUR 8 Unix Package Management 161
Red Hat Package Manager and Linux ................................................................162
Task 8.1:Working with RPM ........................................................................162
Adding New RPM Packages from the Internet ..................................................165
Task 8.2:Installing New Web-Based RPM Packages....................................165
Package Management in Darwin ........................................................................168
Task 8.3:Installing and Working with fink..................................................168
Package Management in Solaris..........................................................................172
Task 8.4:Managing Packages in Solaris........................................................172
Summary..............................................................................................................177
Q&A....................................................................................................................177
Workshop ............................................................................................................177
Quiz................................................................................................................177
Answers..........................................................................................................177
TEAM LinG - Live, Informative, Non-cost and Genuine!
00 0672323982 FM 6/18/02 2:05 PM Page viii
viii Sams Teach Yourself Unix Administration in 24 Hours
PART IV Advanced File System Topics 179
Hour 9 Fixing Broken Disks 181
Introduction to fsck............................................................................................182
Task 9.1:Getting Started with fsck..............................................................183
Fixing Problems with fsck..................................................................................186
Task 9.2:Fixing Disk Problems with fsck....................................................186
Single-User Mode................................................................................................190
Task 9.3:Single-User Mode in Darwin..........................................................191
Don’t Panic! ........................................................................................................193
Summary..............................................................................................................194
Q&A....................................................................................................................194
Workshop ............................................................................................................195
Quiz................................................................................................................195
Answers..........................................................................................................195
HOUR 10 Adding Disks to Your System 197
Formatting Disks with fdisk..............................................................................198
Task 10.1:Formatting a Disk with fdisk......................................................199
Adding a Filesystem with mke2fs ......................................................................203
Task 10.2:Making a Filesystem with mke2fs ..............................................204
Mounting the New Disk......................................................................................208
Task 10.3:Adding New Drives to Your System ............................................208
Fine-tuning Your /etc/fstabConfiguration File..............................................212
Task 10.4:Creating the Perfect /etc/fstabFile..........................................212
Summary..............................................................................................................215
Q&A....................................................................................................................215
Workshop ............................................................................................................216
Quiz................................................................................................................216
Answers..........................................................................................................216
HOUR 11 Multiple Boot Configurations 217
The Theory of Dual-Booting ..............................................................................218
Task 11.1:Partitioning Disks for Dual Boot..................................................219
Dual-Boot Configurations with LILO ................................................................220
Task 11.2:Configuring LILO........................................................................221
Dual-Boot Configurations with GRUB ..............................................................223
Task 11.3:Configuring GRUB ......................................................................223
Other Solutions for Other Unixes........................................................................226
Task 11.4:Learning About Virtual Machines................................................227
TEAM LinG - Live, Informative, Non-cost and Genuine!
00 0672323982 FM 6/18/02 2:05 PM Page ix
Contents ix
Summary..............................................................................................................228
Q&A....................................................................................................................229
Workshop ............................................................................................................229
Quiz................................................................................................................229
Answers..........................................................................................................230
HOUR 12 Managing Disk Quotas 231
Implementing a Disk-Quota Policy ....................................................................232
Task 12.1:Implementing Quotas....................................................................232
Quota Nuances on Other Unixes ........................................................................237
Task 12.2:Quotas on Other Systems ............................................................237
Creating Your Own Quota System with find ....................................................239
Task 12.3:Disk-Quotas with find ................................................................239
Summary..............................................................................................................243
Q&A ..............................................................................................................243
Workshop ............................................................................................................243
Quiz................................................................................................................243
Answers..........................................................................................................244
PART V Process & System Controls 245
HOUR 13 Changing System State 247
Configuring and Working with the initProcess................................................248
Task 13.1:The initProcess and Configuration ..........................................248
Enabling Specific Services at Different Run Levels ..........................................254
Task 13.2:Configuring Your System for Run Levels....................................255
Shutting Down Your System the Right Way........................................................259
Task 13.3:Safe Shutdowns and Reboots ......................................................260
Summary..............................................................................................................262
Q&A....................................................................................................................262
Workshop ............................................................................................................262
Quiz................................................................................................................263
Answers..........................................................................................................263
HOUR 14 Exploring Processes 265
The Secret Life of Process IDs............................................................................266
Task 14.1:Process ID Information................................................................266
Examining Processes with the psCommand......................................................267
Task 14.2:Exploring ps ................................................................................267
A Typical Sysadmin Task:What’s artsd?..........................................................273
Task 14.3:A Little Unix Detective Work ......................................................273
Process Priorities..................................................................................................276
Task 14.4:Managing Process Priorities ........................................................276
TEAM LinG - Live, Informative, Non-cost and Genuine!
Description:In the wake of the highly successful Sams Teach Yourself Unix in 24 Hours, this book focuses on the additional Unix commands that an advanced user or beginning system administrator needs to know in order to administer and maintain a Unix system. The book includes coverage of the key Unix variations: