linux bible by christopher negus

Linux

®

Bible
8th Edition

Linux

®

BIBLE
8th Edition

Christopher Negus
with contributions by

Christine Bresnahan

Linux® Bible 8th Edition
Published by

John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright © 2012 by John Wiley & Sons, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-1-118-21854-9
ISBN: 978-1-118-28690-6 (ebk)
ISBN: 978-1-118-28287-8 (ebk)
ISBN: 978-1-118-28397-4 (ebk)
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any
means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections
107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or
authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood
Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be
addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201)
748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO

REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS
OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION
WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY
SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE
SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS
NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL
ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT.
NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT
THAT AN ORGANIZATION OR WEB SITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL
SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE
INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE.
FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE
CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services please contact our Customer Care Department within
the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with
standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to
media such as a CD or DVD that is not included in the version you purchased, you may download this material at
http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.
Library of Congress Control Number: 2012937953

Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its
affiliates, in the United States and other countries, and may not be used without written permission. Linux is a
registered trademark of Linus Torvalds. All other trademarks are the property of their respective owners. John
Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.

As always, I dedicate this book to my wife, Sheree.
— Chris Negus
I would like to dedicate this book to my family and the Lord God Almighty.
“But as for you, be strong and do not give up, for your work will be
rewarded.” 2 Chronicles 15:7
— Christine Bresnahan

About the Authors
Chris Negus has spent the past three years as an instructor for Red Hat, Inc., teaching
IT professionals to become Red Hat Certiied Engineers (RHCE). Chris’s certiications
include RHCE, Red Hat Certiied Instructor (RHCI), and Red Hat Certiied Examiner
(RHCX). He also has certiications in Red Hat Enterprise Virtualization (RHCVA) and Red
Hat Enterprise Deployment and Systems Management.
Before joining Red Hat, Chris wrote or co-wrote dozens of books on Linux and
UNIX, including Red Hat Linux Bible (all editions), CentOS Bible, Fedora Bible, Linux

Troubleshooting Bible, Linux Toys, and Linux Toys II. Recently, Chris co-authored several
books for the Linux Toolbox series for power users: Fedora Linux Toolbox, SUSE Linux
Toolbox, Ubuntu Linux Toolbox, Mac OS X Toolbox, and BSD UNIX Toolbox.
For eight years Chris worked with the organization at AT&T that developed UNIX before
moving to Utah to contribute to Novell’s UnixWare project in the early 1990s. When not
writing about Linux, Chris enjoys playing soccer and just hanging out with his family.
Christine Bresnahan started working with computers over 25 years ago in the IT industry as a system administrator. Christine is currently an adjunct professor at Ivy Tech
Community College in Indianapolis, Indiana, teaching Linux system administration,
Linux security, and Windows security classes.

About the Technical Editor
Richard Blum has worked in the IT industry for more than 20 years as both a systems
and network administrator, and has published numerous Linux and open source books.
He has administered UNIX, Linux, Novell, and Microsoft servers, as well as helped
design and maintain a 3,500-user network utilizing Cisco switches and routers. He has
used Linux servers and shell scripts to perform automated network and system monitoring, and has written shell scripts in most of the common Linux shell environments.
Rich is also an online instructor for several Linux and web programming courses that
are used by colleges and universities around the world. When he’s not being a computer
nerd, Rich plays electric bass in a couple of different church worship bands, and enjoys
spending time with his wife, Barbara, and three daughters, Katie, Jane, and Jessica.


Credits
Acquisitions Editor
Mary James

Production Manager
Tim Tate

Project Editor
Linda Harrison

Vice President and Executive Group
Publisher
Richard Swadley

Technical Editor
Richard Blum
Production Editor
Daniel Scribner
Copy Editor

Nancy Rapoport
Editorial Manager
Mary Beth Wakefield

Vice President and Executive Publisher
Neil Edde
Associate Publisher
Jim Minatel
Project Coordinator, Cover
Katie Crocker

Freelancer Editorial Manager
Rosemarie Graham

Proofreaders
Josh Chase, Word One
Paul Sagan, Word One

Associate Director of Marketing
David Mayhew


Indexer
Robert Swanson

Marketing Manager
Ashley Zurcher

Cover Designer
Ryan Sneed

Business Manager
Amy Knies

Cover Image
© Aleksandar Velasevic / iStockPhoto

Acknowledgments

S


ince I was hired by Red Hat, Inc. over three years ago, I have been exposed to the
best Linux developers, testers, support professionals, and instructors in the world.
I can’t thank everyone individually, so instead I salute the culture of cooperation
and excellence that serves to improve my own Linux skills every day. I don’t speak well
of Red Hat because I work there; I work there because Red Hat has earned its reputation
as the leading force in Linux development.
That said, there are a few people at Red Hat I would like to acknowledge. Discussions
with Victor Costea, Andrew Blum, and other Red Hat instructors have helped me adapt
my ways of thinking about how people learn Linux. In my new role at Red Hat as a
writer for the customer portal, my manager Sam Folk-Williams has allowed me to extend
my skills into areas such as virtualization, troubleshooting, and performance tuning.
When we needed help to bring this book in on time, Christine Bresnahan was an excellent addition to the team. Christine wrote new material and updated content for the
security chapters in this book, bringing her solid Linux teaching and writing skills to
this project.
As for the people at Wiley, I particularly thank them for their patience. Mary James
and Linda Harrison have gently guided me through a demanding schedule. Thanks
to Richard Blum for his thorough technical editing . . . giving me an Ubuntu slant to
this otherwise Red Hat–centric book. Thanks to Margot Maley Hutchison and Maureen
Maloney from Waterside Productions for contracting the book for me with Wiley.
Finally, thanks to my wife, Sheree, for sharing her life with me and doing such a great

job raising Seth and Caleb.
— Christoper Negus
Many thanks go to the fantastic team of people at John Wiley & Sons for their outstanding
work on this project. Thanks to Mary James, the acquisitions editor, for offering me the
opportunity to work on this book. Also thanks to Linda Harrison, the development editor, for keeping things on track and making this book more presentable. Thanks Linda for
all your hard work and diligence. The technical editor, Rich Blum, did a wonderful job of
double-checking all the work in the book, plus making suggestions to improve the content.
Thanks to Nancy Rapoport, the copy editor, for her endless patience and diligence to make
our work readable.
I would also like to thank Carole McClendon at Waterside Productions, Inc. for arranging this opportunity for me, and for helping me in my writing career. I would also like to
thank my husband, Timothy, for his encouragement, patience, and willingness to listen,
even when he has no idea what I’m talking about.
— Christine Bresnahan

xi

Contents at a Glance
Introduction ........................................................................................................... xxxiii

Part I: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Chapter 1: Starting with Linux ...................................................................................... 3
Chapter 2: Creating the Perfect Linux Desktop ............................................................. 27

Part II: Becoming a Linux Power User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Chapter 3: Using the Shell ........................................................................................... 61
Chapter 4: Moving Around the Filesystem ................................................................... 93
Chapter 5: Working with Text Files ............................................................................113
Chapter 6: Managing Running Processes ....................................................................131
Chapter 7: Writing Simple Shell Scripts ......................................................................145

Part III: Becoming a Linux System Administrator . . . . . . . . . . . . . . . . . . . . 163
Chapter 8: Learning System Administration ...............................................................165
Chapter 9: Installing Linux ........................................................................................191
Chapter 10: Getting and Managing Software ...............................................................227
Chapter 11: Managing User Accounts .........................................................................253
Chapter 12: Managing Disks and Filesystems .............................................................277

Part IV: Becoming a Linux Server Administrator . . . . . . . . . . . . . . . . . . . . 305
Chapter 13: Understanding Server Administration ......................................................307
Chapter 14: Administering Networking ......................................................................337

Chapter 15: Starting and Stopping Services .................................................................365
Chapter 16: Coniguring a Print Server .......................................................................415
Chapter 17: Coniguring a Web Server ........................................................................439
Chapter 18: Coniguring an FTP Server ......................................................................467
Chapter 19: Coniguring a Windows File Sharing (Samba) Server ................................487
Chapter 20: Coniguring an NFS File Server................................................................515
Chapter 21: Troubleshooting Linux .............................................................................539

Part V: Learning Linux Security Techniques . . . . . . . . . . . . . . . . . . . . . . . . 571
Chapter 22: Understanding Basic Linux Security ........................................................573
Chapter 23: Understanding Advanced Linux Security..................................................615
Chapter 24: Enhancing Linux Security with SELinux ..................................................659
Chapter 25: Securing Linux on a Network ................................................................. 689

xiii

Part VI: Appendixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717
Appendix A: Media....................................................................................................719
Appendix B: Exercise Answers ...................................................................................729
Index ........................................................................................................................783

Contents
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxiii

Part I: Getting Started

1

Chapter 1: Starting with Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Understanding What Linux Is............................................................................... 4
Understanding How Linux Differs from Other Operating Systems .......................... 5
Exploring Linux History ....................................................................................... 6
Free-lowing UNIX culture at Bell Labs ........................................................ 7
Commercialized UNIX ................................................................................. 9
Berkeley Software Distribution arrives................................................. 9
UNIX Laboratory and commercialization ............................................. 9
GNU transitions UNIX to freedom .............................................................. 11
BSD loses some steam ............................................................................... 12
Linus builds the missing piece ................................................................... 13
OSI open source dei nition ......................................................................... 14
Understanding How Linux Distributions Emerged............................................... 15
Choosing a Red Hat distribution ................................................................ 16
Using Red Hat Enterprise Linux......................................................... 17
Using Fedora .................................................................................... 18
Choosing Ubuntu or another Debian distribution ....................................... 18
Finding Professional Opportunities with Linux Today ......................................... 19
Understanding how companies make money with Linux ............................ 20
Becoming Red Hat Certiied ....................................................................... 21
RHCSA topics.................................................................................... 22
RHCE topics ...................................................................................... 23
Summary........................................................................................................... 24

Chapter 2: Creating the Perfect Linux Desktop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Understanding Linux Desktop Technology .......................................................... 28
Starting with the Fedora GNOME Desktop Live CD ............................................. 30
Using the GNOME 3 Desktop .............................................................................. 31
After the computer boots up ...................................................................... 31
Navigating with the mouse ............................................................... 32
Navigating with the keyboard ........................................................... 36
Setting up the GNOME 3 desktop ............................................................... 38

xv

Contents

Extending the GNOME 3 desktop ............................................................... 39
Using GNOME shell extensions.......................................................... 39
Using the GNOME Tweak Tool ........................................................... 40
Starting with desktop applications ............................................................. 42
Managing i les and folders with Nautilus ........................................... 42
Installing and managing additional software ..................................... 44
Playing music with Rhythmbox......................................................... 45
Stopping the GNOME 3 desktop ................................................................. 46
Using the GNOME 2 Desktop .............................................................................. 46
Using the Metacity window manager ......................................................... 48
Changing GNOME appearance ................................................................... 49
Using the GNOME panels........................................................................... 50
Using the Applications and System menus ......................................... 51
Adding an applet .............................................................................. 51
Adding another panel ....................................................................... 52
Adding an application launcher ......................................................... 52
Adding a drawer ............................................................................... 53
Changing panel properties ................................................................ 53
3D effects with AIGLX ............................................................................... 54
Summary........................................................................................................... 57
Exercises ........................................................................................................... 57

Part II: Becoming a Linux Power User

59

Chapter 3: Using the Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
About Shells and Terminal Windows .................................................................. 62
Using the shell prompt ............................................................................... 63
Using a terminal window .......................................................................... 64
Using virtual consoles ............................................................................... 65
Choosing Your Shell ........................................................................................... 65
Running Commands .......................................................................................... 66
Understanding command syntax................................................................ 67
Locating commands .................................................................................. 70
Recalling Commands Using Command History ................................................... 72
Command-line editing ............................................................................... 73
Command-line completion ......................................................................... 75
Command-line recall ................................................................................. 76
Connecting and Expanding Commands .............................................................. 78
Piping between commands ........................................................................ 78
Sequential commands ............................................................................... 79
Background commands ............................................................................. 79
Expanding commands ............................................................................... 80
Expanding arithmetic expressions ............................................................. 80

xvi

Contents

Expanding variables .................................................................................. 81
Using Shell Variables.......................................................................................... 81
Creating and using aliases ......................................................................... 83
Exiting the shell ........................................................................................ 84
Creating Your Shell Environment ........................................................................ 84
Coniguring your shell ............................................................................... 84
Setting your prompt................................................................................... 85
Adding environment variables ................................................................... 87
Getting Information About Commands ............................................................... 88
Summary........................................................................................................... 90
Exercises ........................................................................................................... 90

Chapter 4: Moving Around the Filesystem  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Using Basic Filesystem Commands ..................................................................... 96
Using Metacharacters and Operators ................................................................... 98
Using i le-matching metacharacters............................................................ 98
Using i le-redirection metacharacters ......................................................... 99
Using brace expansion characters .............................................................101
Listing Files and Directories ..............................................................................101
Understanding File Permissions and Ownership ................................................105
Changing permissions with chmod (numbers)...........................................107
Changing permissions with chmod (letters) ..............................................107
Setting default i le permission with umask ................................................108
Changing i le ownership ...........................................................................109
Moving, Copying, and Removing Files ..............................................................110
Summary..........................................................................................................111
Exercises ..........................................................................................................112

Chapter 5: Working with Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Editing Files with vim and vi ............................................................................113
Starting with vi ........................................................................................115
Adding text......................................................................................115
Moving around in the text................................................................116
Deleting, copying, and changing text ...............................................117
Pasting (putting) text .......................................................................118
Repeating commands .......................................................................118
Exiting vi ........................................................................................118
Skipping around in the i le .......................................................................119
Searching for text .....................................................................................120
Using ex mode .........................................................................................120
Learning more about vi and vim ...............................................................120
Finding Files.....................................................................................................121
Using locate to ind i les by name..............................................................121
Searching for i les with ind ......................................................................122
Finding i les by name ......................................................................123

xvii

Contents

Finding i les by size .........................................................................124
Finding i les by user ........................................................................124
Finding i les by permission ..............................................................125
Finding i les by date and time ..........................................................126
Using not and or when inding i les ..................................................126
Finding i les and executing commands.............................................127
Searching in i les with grep ......................................................................128
Summary..........................................................................................................129
Exercises ..........................................................................................................130

Chapter 6: Managing Running Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Understanding Processes...................................................................................131
Listing Processes ..............................................................................................132
Listing processes with ps ..........................................................................132
Listing and changing processes with top ...................................................134
Listing processes with System Monitor ......................................................135
Managing Background and Foreground Processes ..............................................137
Starting background processes..................................................................138
Using foreground and background commands ...........................................139
Killing and Renicing Processes ..........................................................................140
Killing processes with kill and killall ........................................................140
Using kill to signal processes by PID ................................................141
Using killall to signal processes by name ..........................................141
Setting processor priority with nice and renice ..........................................142
Summary..........................................................................................................143
Exercises ..........................................................................................................143

Chapter 7: Writing Simple Shell Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Understanding Shell Scripts...............................................................................145
Executing and debugging shell scripts ......................................................146
Understanding shell variables ...................................................................147
Special shell positional parameters ...................................................148
Reading in parameters .....................................................................149
Parameter expansion in bash ...........................................................149
Performing arithmetic in shell scripts .......................................................150
Using programming constructs in shell scripts ..........................................151
The “if . . . then” statements ............................................................151
The case command ..........................................................................154
The “for . . . do” loop .......................................................................155
The “while . . . do” and “until . . . do” loops .....................................156
Trying some useful text manipulation programs........................................157
The general regular expression parser ..............................................157
Remove sections of lines of text (cut)................................................158
Translate or delete characters (tr) .....................................................158

xviii

Contents

The stream editor (sed) ....................................................................158
Using simple shell scripts .........................................................................159
Telephone list ..................................................................................159
Backup script ...................................................................................160
Summary..........................................................................................................161
Exercises ..........................................................................................................161

Part III: Becoming a Linux System Administrator

163

Chapter 8: Learning System Administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Understanding System Administration...............................................................165
Using Graphical Administration Tools ...............................................................167
Using the root User Account ..............................................................................169
Becoming root from the shell (su command) .............................................170
Allowing administrative access via the GUI ..............................................171
Gaining administrative access with sudo ..................................................172
Exploring Administrative Commands, Coniguration Files, and Log Files ........... 174
Administrative commands ........................................................................ 174
Administrative coniguration i les .............................................................175
Administrative log i les.............................................................................179
Using Other Administrative Accounts ...............................................................180
Checking and Coniguring Hardware .................................................................181
Checking your hardware...........................................................................182
Managing removable hardware .................................................................184
Working with loadable modules ................................................................186
Listing loaded modules ....................................................................187
Loading modules .............................................................................187
Removing modules ..........................................................................188
Summary..........................................................................................................188
Exercises ..........................................................................................................189

Chapter 9: Installing Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Choosing a Computer ........................................................................................192
Installing Fedora from a Live CD .......................................................................193
Installing Red Hat Enterprise Linux from Installation Media ..............................199
Installing Linux in the Enterprise ......................................................................202
Exploring Common Installation Topics ............................................................. 204
Upgrading or installing from scratch ........................................................ 204
Dual booting ............................................................................................205
Installing Linux to run virtually .............................................................. 206
Using installation boot options .................................................................207
Boot options for disabling features ...................................................207
Boot options for video problems ...................................................... 208

xix

Contents

Boot options for special installation types........................................ 208
Boot options for kickstarts and remote repositories .......................... 209
Miscellaneous boot options ..............................................................210
Using specialized storage..........................................................................210
Partitioning hard drives............................................................................211
Understanding different partition types ............................................212
Partitioning during Fedora installation .............................................212
Reasons for different partitioning schemes .......................................216
Tips for creating partitions ...............................................................216
Using the GRUB boot loader ......................................................................218
Using GRUB Legacy (version 1) .......................................................218
Using GRUB 2 ..................................................................................223
Summary......................................................................................................... 224
Exercises ..........................................................................................................225

Chapter 10: Getting and Managing Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Managing Software with PackageKit .................................................................227
Enabling repositories and getting updates .................................................228
Searching for packages .............................................................................229
Installing and removing packages .............................................................230
Going beyond PackageKit .........................................................................231
Understanding Linux RPM Software Packaging..................................................231
Understanding RPM packaging .................................................................232
What is in an RPM? .........................................................................233
Where do RPMs come from?............................................................ 234
Installing RPMs .............................................................................. 234
Managing RPM Packages with YUM ..................................................................235
Understanding how yum works ................................................................235
1. Checking /etc/yum.conf ...............................................................236
2. Checking /etc/sysconig/rhn/up2date (RHEL only) .......................237
3. Checking /etc/yum.repos.d/*.repo i les .........................................237
4. Downloading RPM packages and metadata from a YUM repository238
5. RPM packages installed to Linux i le system .................................238
6. Store YUM repository metadata to local RPM database ..................238
Using YUM with third-party software repositories .....................................239
Managing software with the YUM command ........................................... 240
Searching for packages ................................................................... 240
Installing and removing packages ................................................... 242
Updating packages .......................................................................... 243
Updating groups of packages ........................................................... 244
Maintaining your RPM package database and cache ........................ 245
Downloading RPMs from a yum repository...................................... 246
Installing, Querying, and Verifying Software with the rpm Command............... 246
Installing and removing packages with rpm ..............................................247

xx

Contents

Querying rpm information ........................................................................247
Verifying RPM packages ...........................................................................249
Managing Software in the Enterprise .................................................................250
Summary..........................................................................................................251
Exercises ..........................................................................................................252

Chapter 11: Managing User Accounts  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Creating User Accounts .....................................................................................253
Adding users with useradd .......................................................................256
Setting user defaults .................................................................................259
Modifying users with usermod ................................................................ 260
Deleting users with userdel ......................................................................261
Understanding Group Accounts .........................................................................262
Using group accounts ...............................................................................262
Creating group accounts ...........................................................................263
Managing Users in the Enterprise ..................................................................... 264
Setting permissions with Access Control Lists ...........................................265
Setting ACLs with setfacl .................................................................265
Setting default ACLs ........................................................................267
Enabling ACLs ................................................................................ 268
Adding directories for users to collaborate ................................................270
Creating group collaboration directories (set GID bit) ........................270
Creating restricted deletion directories (sticky bit) ............................271
Centralizing User Accounts ...............................................................................272
Using the Authentication Coniguration window .......................................273
Summary..........................................................................................................274
Exercises ..........................................................................................................275

Chapter 12: Managing Disks and Filesystems  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Understanding Disk Storage ..............................................................................277
Partitioning Hard Disks.....................................................................................279
Viewing disk partitions ........................................................................... 280
Creating a single-partition disk .................................................................281
Creating a multiple-partition disk ............................................................ 284
Using Logical Volume Management Partitions .................................................. 288
Checking an existing LVM ....................................................................... 288
Creating LVM logical volumes ...................................................................291
Growing LVM logical volumes ..................................................................293
Mounting Filesystems .......................................................................................293
Supported i lesystems ...............................................................................294
Enabling swap areas .................................................................................296
Disabling swap area .................................................................................297
Using the fstab i le to deine mountable i le systems ..................................297
Using the mount command to mount i le systems..................................... 300

xxi

Contents

Mounting a disk image in loopback...........................................................301
Using the umount command ....................................................................301
Using the mkfs Command to Create a Filesystem ...............................................302
Summary..........................................................................................................303
Exercises ..........................................................................................................303

Part IV: Becoming a Linux Server Administrator

305

Chapter 13: Understanding Server Administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Starting with Server Administration ................................................................. 308
Step 1: Install the server .......................................................................... 308
Step 2: Conigure the server ......................................................................310
Using coniguration i les ..................................................................310
Checking the default coniguration ...................................................310
Step 3: Start the server ..............................................................................311
Step 4: Secure the server...........................................................................312
Password protection .........................................................................313
Firewalls .........................................................................................313
TCP Wrappers..................................................................................313
SELinux...........................................................................................313
Security settings in coniguration i les .............................................. 314
Step 5: Monitor the server ......................................................................... 314
Conigure logging ............................................................................ 314
Run system activity reports .............................................................. 314
Keep system software up to date ...................................................... 314
Check the i lesystem for signs of crackers .........................................315
Managing Remote Access with the Secure Shell Service .....................................315
Starting the openssh-server service ...........................................................316
Using SSH client tools ...............................................................................317
Using ssh for remote login ................................................................318
Using ssh for remote execution .........................................................319
Copying i les between systems with scp and rsync ...........................320
Interactive copying with sftp ............................................................323
Using key-based (passwordless) authentication ........................................323
Coniguring System Logging ............................................................................325
Enabling system logging with rsyslog .......................................................325
Understanding the rsyslog.conf i le ...................................................326
Understanding the messages log i le .................................................327
Setting up and using a loghost with rsyslogd ....................................328
Watching logs with logwatch ....................................................................329
Checking System Resources with sar .................................................................330
Checking System Space .....................................................................................332
Displaying system space with df ...............................................................332

xxii

Contents

Checking disk usage with du ....................................................................333
Finding disk consumption with ind .........................................................333
Summary..........................................................................................................334
Exercises ..........................................................................................................335

Chapter 14: Administering Networking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Coniguring Networking for Desktops ................................................................338
Checking your network interfaces ............................................................ 340
Checking your network from NetworkManager ................................ 340
Checking your network from the command line............................... 342
Coniguring network interfaces ................................................................ 345
Coniguring a network proxy connection ..................................................347
Coniguring Networking for Servers ................................................................. 348
Using system-conig-network ....................................................................349
Choosing device coniguration .........................................................350
Choosing DNS coniguration ............................................................351
Understanding networking coniguration i les ...........................................351
Network interface i les .....................................................................352
Other networking i les .....................................................................353
Setting alias network interfaces ................................................................356
Setting up Ethernet channel bonding ........................................................357
Setting custom routes ...............................................................................358
Coniguring Networking in the Enterprise .........................................................359
Coniguring Linux as a router ...................................................................359
Coniguring Linux as a DHCP server ........................................................ 360
Coniguring Linux as a DNS server ...........................................................361
Coniguring Linux as a proxy server .........................................................361
Coniguring VLANs in Linux ....................................................................362
Summary..........................................................................................................363
Exercises ..........................................................................................................363

Chapter 15: Starting and Stopping Services  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Understanding the Linux init Daemon ...............................................................365
Understanding the classic init daemons.....................................................367
Understanding the Upstart init daemon .....................................................375
Learning Up