01_579495 ffirs.qxd 12/27/04 9:52 PM Page i
01_579495 ffirs.qxd 12/27/04 9:52 PM Page vi
01_579495 ffirs.qxd 12/27/04 9:52 PM Page i
01_579495 ffirs.qxd 12/29/04 8:12 PM Page ii
Linux® Bible 2005 Edition
Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256 www.wiley.com
Copyright © 2005 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 0-7645-7949-5
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
1O/RZ/QR/QV/IN
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 Legal
Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, e-mail: [email protected]
.
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 WEBSITE 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 or to obtain technical support, please contact our Customer
Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
Library of Congress Cataloging-in-Publication Data
Negus, Chris, 1957–
Linux bible 2005 edition/Christopher Negus.
p. cm.
ISBN 0-7645-7949-5 (paper/dvd)
1.
Linux. 2.
Operating systems (Computers) I. Title.
QA76.76.063N422 2005
005.4'32- - dc22
2004028132
Trademarks:
Wiley, the Wiley Publishing logo and related trade dress 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. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.
01_579495 ffirs.qxd 12/27/04 9:52 PM Page iii
has authored or co-authored dozens of books on Linux and UNIX, including the
Red Hat Linux Bible
(all editions),
Linux Troubleshooting Bible
, and
Linux Toys
. He worked with the organization at AT&T that developed UNIX for eight years before moving to Utah to help contribute to Novell’s short-lived
UnixWare project in the early 1990s. When not writing about Linux, Chris rides the
400 trail with his wife Sheree, builds things with his son Seth, and plays soccer when he can.
is foremost a husband and a father. Although formally trained as a geologist, he now spends the bulk of his professional time writing books, making and teaching music, and earning his keep as a professional geek. David has worked on books ranging in topic from Cisco certification to Apache server administration.
is a Linux enthusiast and has been a professional system administrator for six years. He is currently a technical manager, systems administrator, and network engineer at an Internet company in Washington state. He lives in Bellingham,
Washington, with his beloved wife Danielle, whom he would like to thank for her patience while he was working on this project. His future projects include continuing his education and working on the things that have recently accumulated on his
“honey-do” list.
is a professional technical writer by trade and a historian by training.
These days, Kurt works for TimeSys Corporation in Pittsburgh, Pennsylvania. His primary responsibility is managing TimeSys’ Content Group. In addition to overseeing production of the technical and end-user documentation of TimeSys’ embedded
Linux operating system and development tools, he writes most of the documentation for TimeSys’s embedded Linux products and all of the content available on the
TimeSys Network. Kurt has written all or parts of 15 books on Linux system administration and programming topics and contributes the occasional product review to
LinuxPlanet. In his spare time, he has no spare time.
Kurt, who dislikes writing about himself in the third person, receives entirely too much e-mail at [email protected]
.
, CISSP, CISA, CISM, Security+ has been in the IT field for 15 years. Paul holds a Master’s of Science degree in Network Security and a Bachelor’s in Information
Systems. He has co-authored one Linux security book, contributed to another security book, and has been the technical editor for more than 10 best-selling Linux and
UNIX books. Paul also ran a successful Linux portal site during the dot-com era and has been an avid UNIX/Linux user and administrator for many years. Paul is currently a security manager at a large financial services company.
01_579495 ffirs.qxd 12/27/04 9:52 PM Page iv
Debra Williams Cauley
Maryann Steinhart
Gabrielle Nabi
Dilip Thomas
Kim Cofer
Howard Jones
Mary Beth Wakefield
Richard Swadley
Joseph B. Wikert
Erin Smith
Beth Brooks
Carrie Foster
Jennifer Heleine
Shelly Lea
Barry Offringa
Heather Pope
Heather Ryan
Laura Albert
Amanda Briggs
John Greenough
Jessica Kramer
Susan Moritz
Carl Pierce
Brian Walls
Travis Silvers
TECHBOOKS Production Services
01_579495 ffirs.qxd 12/27/04 9:52 PM Page v
As always, I dedicate this book to my wife Sheree.
01_579495 ffirs.qxd 12/27/04 9:52 PM Page vi
02_579495 fpref.qxd 12/27/04 9:49 PM Page vii
I
nsert the DVD or CD that comes with this book into your PC. Within five minutes, you’ll be able to try out Linux with a full range of desktop applications.
Within an hour, you can have a full-blown Linux desktop or server system installed on your computer. If you are like most of us who have been bitten by the Linux bug, you won’t ever look back.
The
Linux Bible 2005 Edition
is here to open your eyes to what Linux is, where it came from, and where it’s going. But, most of all, the book is here to hand you Linux and help you get started. Because Linux is the operating system of free speech and free choice, the you.
Linux Bible
gives you choices in selecting the Linux that is right for
On the DVD and CD that come with this book are 10 different Linux distributions that you are free to install and try out. You learn how those distributions are alike or different, and the book leads you through the basics of installing and setting up your Linux system as:
✦
You have a full range of office, music, gaming, graphics, and other applications to use.
✦
Using some of the world’s best server software, you can set up your computer to be a Web server, file server, mail server, or print server.
✦
You can draw on thousands of open source programming tools to develop your own software applications.
Unlike other books on Linux, this book doesn’t tie you to one Linux distribution.
The book teaches you the essentials of Linux graphical interfaces, shell commands, and basic system administration. Separate chapters break down most of the major
Linux distributions available today. Then descriptions of the major software projects in most Linux distributions (KDE and GNOME desktops, Apache Web servers,
Samba file and printer sharing, and so on) guide you in setting up and using those features, regardless of which Linux you choose.
To calm your fears that “free” software can’t be that good, this book guides you through the strange and circuitous path of open source software development that led to the Linux phenomenon. It also details the major companies and organizations that are behind Linux and the open source movement today.
02_579495 fpref.qxd 12/27/04 9:49 PM Page viii viii
Preface
Along the way, you learn how you can become part of the open source community, whose stars are known by a single name (like Linus) or a few initials (like rms). You’ll be staggered by the number of open source projects, forums, and mailing lists that are thriving today (and always looking for more people to get involved).
Learn the basics of what goes into Linux and you will be able to use all sorts of devices and computers in the future. The book is organized in a way that will enable you to start off at the very beginning with Linux, but still grow to the point where you can get going with some powerful server and programming features, if you care to.
Part I assumes that someone has set up a Linux system in front of you and you want to start learning the basics of how to
✦
Use the shell (Chapter 2).
✦
Work with your graphical desktop (Chapter 3).
In Part II, you learn how to
✦
Do basic administration (Chapter 4).
✦
Attach to the Internet (Chapter 5).
✦
Secure your Linux system (Chapter 6).
If you don’t have Linux installed yet, this book helps you out in a big way: the companion DVD and CD include a variety of Linux distributions you can try. Part III
(Chapters 7 through 18) describe each of those distributions and how to install them. Appendix A tells you what’s on the DVD and CD, how to install from the DVD or CD, and how to burn additional installation CDs from the software we provide.
In Part IV, you learn to get some fun and useful features going in Linux so that you can
✦
Play music and video (Chapter 19).
✦
Write documents and work with graphics (Chapter 20).
✦
Use Web browsers and e-mail clients (Chapter 21).
✦
Play games (Chapter 22).
Linux creates powerful servers, and in Part V you learn to
✦
Set up a Web server using Apache, MySQL, and PHP in Linux (Chapter 23).
✦
Run a mail server (Chapter 24).
✦
Share printers with a CUPS print server (Chapter 25).
✦
Share files with a Samba or NFS file server (Chapter 26).
02_579495 fpref.qxd 12/27/04 9:49 PM Page ix
Preface
ix
If you are coming to Linux for its programming environment, Part VI provides chapters that describe
✦
Programming environments and interfaces (Chapter 27).
✦
Programming tools and utilities (Chapter 28).
In addition, Appendix B can help get you “plugged in” to the Linux community.
By the time you finish this book, you’ll have a good basic understanding of many of the major features in Linux and how you can use them. If you decide then that you want to go a bit deeper into any Red Hat Linux distribution,
Red Hat Fedora
Linux 3 Bible
would be a good next step, with content that includes how to set up many different types of Linux servers. If you are more technically oriented, the
Linux Troubleshooting Bible
can be a good way to learn more advanced skills for securing and troubleshooting Linux systems.
Given the size of thousands of software features available for Linux systems, we can’t possibly cover everything in one book. To expand our coverage in a few important areas, we created the Linux Bible 2005 Edition Web site ( www.wiley.com/go/
LinuxBible2005 ). Refer to that site for coverage of many application and server features that didn’t make it into this text.
To order the source code for Fedora, see the coupon printed at the back of the book. To order source code for any of the other Linux distributions included on the
DVD or CD, go to www.wiley/go/linuxbible2005source with further details.
to download a coupon
02_579495 fpref.qxd 12/27/04 9:49 PM Page x
03_579495 fbetw.qxd 12/27/04 9:49 PM Page xi
I
consider anyone who has contributed to the open source community to be a contributor to the book you see in front of you. The backbone of any Linux distribution is formed by the organizations that produce the distributions, the major projects included in Linux, and the thousands of people who give their time and code to support Linux. So, thanks to you all!
For their help on understanding particular Linux distributions, I’d like to thank
Patrick Volkerding (creator of Slackware), Kai Staats (CEO of Terra Soft Solutions, makers of Yellow Dog Linux), and Jesse Keating (Fedora Legacy Project), who took the time to answer my questions. Likewise, I’d like to thank Charles Mauch for helping me get started with Gentoo and Joel Parker for building my computing infrastructure so that when I work, no Linux distribution is more than a click away.
My Linux users group (TACLUG.org) was an invaluable resource. Whether on the group’s mailing list or personally at meetings, the group members have been extremely valuable to me (providing direct input to this book, as well as contributing to my personal growth with Linux).
As for the contributing authors on this book, I couldn’t have asked for a finer group.
Without the contributions of David Dalan, Wayne Tucker, Kurt Wall, and Paul Love, this book might never have gotten done. Likewise, technical editor Dilip Thomas did a great job pointing out ways of improving the book.
Thanks to the folks at Wiley for helping me press through the project. Without
Debra Williams Cauley, I would surely not have known (on a daily basis) how far behind I was on my schedule. Maryann Steinhart proved to be a tough, but kind, editor. Thanks to Margot Maley Hutchison, Kimberly Valentini, and Maureen
Maloney from Waterside productions for contracting the book for me with Wiley.
And finally, special thanks to my wife Sheree. There’s no way I could do the work I do without the solid support I get on the home front. I love you, and thanks for taking such good care of me, Seth, and Caleb.
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xii
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Chapter 1: Starting with Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Chapter 2: Running Commands from the Shell . . . . . . . . . . . . . . . . . . . . 29
Chapter 3: Getting into the Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Chapter 4: Learning Basic Administration . . . . . . . . . . . . . . . . . . . . . . 125
Chapter 5: Getting on the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Chapter 6: Securing Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Chapter 7: Installing Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Chapter 8: Running Fedora Core and Red Hat Enterprise Linux . . . . . . . . . . 273
Chapter 9: Running Debian GNU/Linux . . . . . . . . . . . . . . . . . . . . . . . . 295
Chapter 10: Running SUSE Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
Chapter 11: Running KNOPPIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
Chapter 12: Running Yellow Dog Linux . . . . . . . . . . . . . . . . . . . . . . . . 351
Chapter 13: Running Gentoo Linux . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Chapter 14: Running Slackware Linux . . . . . . . . . . . . . . . . . . . . . . . . . 383
Chapter 15: Running Linspire . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Chapter 16: Running Mandrakelinux . . . . . . . . . . . . . . . . . . . . . . . . . 409
Chapter 17: Running a Linux Firewall/Router . . . . . . . . . . . . . . . . . . . . 423
Chapter 18: Running Bootable Linux Distributions . . . . . . . . . . . . . . . . . 447
Chapter 19: Playing Music and Video . . . . . . . . . . . . . . . . . . . . . . . . . 461
Chapter 20: Working with Words and Images . . . . . . . . . . . . . . . . . . . . 501
Chapter 21: E-Mailing and Web Browsing . . . . . . . . . . . . . . . . . . . . . . . 541
Chapter 22: Gaming Alone and Online . . . . . . . . . . . . . . . . . . . . . . . . 569
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xiii
Chapter 23: Running a Linux, Apache, MySQL, and PHP (LAMP) Server . . . . . 595
Chapter 24: Running a Mail Server . . . . . . . . . . . . . . . . . . . . . . . . . . 617
Chapter 25: Running a Print Server . . . . . . . . . . . . . . . . . . . . . . . . . . 635
Chapter 26: Running a File Server . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
Chapter 27: Programming Environments and Interfaces . . . . . . . . . . . . . . 695
Chapter 28: Programming Tools and Utilities . . . . . . . . . . . . . . . . . . . . 723
Appendix A: Media . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753
Appendix B: Entering the Linux Community . . . . . . . . . . . . . . . . . . . . . 761
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xiv
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xv
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Understanding Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
What’s So Cool About Linux? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Exploring Linux History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
From a Free-Flowing UNIX Culture at Bell Labs . . . . . . . . . . . . . . 9
To a Commercialized UNIX . . . . . . . . . . . . . . . . . . . . . . . . . 11
To a GNU Free-Flowing (Not) UNIX . . . . . . . . . . . . . . . . . . . . 13
BSD Loses Some Steam . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Linus Builds the Missing Piece . . . . . . . . . . . . . . . . . . . . . . . 15
What’s So Great About Linux? . . . . . . . . . . . . . . . . . . . . . . . . . . 16
OSI Open Source Definition . . . . . . . . . . . . . . . . . . . . . . . . . 16
Vibrant Communities . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Major Software Projects . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Linux Myths, Legends, and FUD . . . . . . . . . . . . . . . . . . . . . . . . . 20
Can You Stop Worrying About Viruses? . . . . . . . . . . . . . . . . . . 20
Will You Be Sued for Using Linux? . . . . . . . . . . . . . . . . . . . . . 21
Can Linux Really Run on Everything from Handhelds to Supercomputers? . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Will Linux Crush Microsoft? . . . . . . . . . . . . . . . . . . . . . . . . 23
Are You on Your Own If You Use Linux? . . . . . . . . . . . . . . . . . 23
Is Linux Only for Geeks? . . . . . . . . . . . . . . . . . . . . . . . . . . 24
How Do Companies Make Money with Linux? . . . . . . . . . . . . . . 24
How Different Are Linux Distributions from One Another? . . . . . . . 25
Is the Linux Mascot Really a Penguin? . . . . . . . . . . . . . . . . . . 26
Running Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Common Mistakes When Starting with Linux . . . . . . . . . . . . . . 27
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xvi xvi
Contents
Starting a Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Using the Shell Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Using a Terminal Window . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Using Virtual Terminals . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Choosing Your Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Using bash (and Earlier sh) Shells . . . . . . . . . . . . . . . . . . . . . 33
Using tcsh (and Earlier csh) Shells . . . . . . . . . . . . . . . . . . . . 34
Using ash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Using ksh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Using zsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Exploring the Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Checking Your Login Session . . . . . . . . . . . . . . . . . . . . . . . . 35
Checking Directories and Permissions . . . . . . . . . . . . . . . . . . 35
Checking System Activity . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Exiting the Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Using the Shell in Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Locating Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Rerunning Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Connecting and Expanding Commands . . . . . . . . . . . . . . . . . . 48
Creating Your Shell Environment . . . . . . . . . . . . . . . . . . . . . . . . . 51
Configuring Your Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Using Shell Environment Variables . . . . . . . . . . . . . . . . . . . . 55
Managing Background and Foreground Processes . . . . . . . . . . . 58
Working with the Linux File System . . . . . . . . . . . . . . . . . . . . . . . 60
Creating Files and Directories . . . . . . . . . . . . . . . . . . . . . . . 63
Moving, Copying, and Deleting Files . . . . . . . . . . . . . . . . . . . 69
Using the vi Text Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Starting with vi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Moving Around the File . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Searching for Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Using Numbers with Commands . . . . . . . . . . . . . . . . . . . . . . 74
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Understanding Your Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Starting the Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
K Desktop Environment (KDE) . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Using the KDE Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Managing Files with the Konqueror File Manager . . . . . . . . . . . . 86
Configuring Konqueror Options . . . . . . . . . . . . . . . . . . . . . . 91
Managing Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Configuring the Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Adding Application Launchers and MIME Types . . . . . . . . . . . . 98
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xvii
Contents
xvii
The GNOME Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Using the Metacity Window Manager . . . . . . . . . . . . . . . . . . 100
Using the GNOME panel . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Using the Nautilus File Manager . . . . . . . . . . . . . . . . . . . . . 108
Changing GNOME Preferences . . . . . . . . . . . . . . . . . . . . . . 110
Exiting GNOME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Configuring Your Own Desktop . . . . . . . . . . . . . . . . . . . . . . . . . 114
Configuring X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Choosing a Window Manager . . . . . . . . . . . . . . . . . . . . . . . 118
Choosing Your Personal Window Manager . . . . . . . . . . . . . . . 120
Getting More Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Graphical Administration Tools . . . . . . . . . . . . . . . . . . . . . . . . . 125
Using Web-Based Administration . . . . . . . . . . . . . . . . . . . . 126
Graphical Administration with Different Distributions . . . . . . . . 127
Using the Root Login . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Becoming Root from the Shell (su Command) . . . . . . . . . . . . . 132
Allowing Limited Administrative Access . . . . . . . . . . . . . . . . 133
Exploring Administrative Commands, Configuration Files, and
Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Administrative Commands . . . . . . . . . . . . . . . . . . . . . . . . 134
Administrative Configuration Files . . . . . . . . . . . . . . . . . . . . 134
Administrative Log Files . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Using sudo and Other Administrative Logins . . . . . . . . . . . . . . . . . 140
Administering Your Linux System . . . . . . . . . . . . . . . . . . . . . . . 142
Creating User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Adding Users with useradd . . . . . . . . . . . . . . . . . . . . . . . . 143
Setting User Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Configuring Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Finding Available Modules . . . . . . . . . . . . . . . . . . . . . . . . 149
Listing Loaded Modules . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Managing File Systems and Disk Space . . . . . . . . . . . . . . . . . . . . . 151
Mounting File Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Using the mkfs Command to Create a File System . . . . . . . . . . . 161
Adding a Hard Disk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Checking System Space . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Monitoring System Performance . . . . . . . . . . . . . . . . . . . . . . . . 166
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xviii xviii
Contents
Connecting to the Network . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Connecting Via Dial-up Service . . . . . . . . . . . . . . . . . . . . . . 170
Connecting a Single Computer to Broadband . . . . . . . . . . . . . 171
Connecting Multiple Computers to Broadband . . . . . . . . . . . . 172
Connecting Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Connecting Other Equipment . . . . . . . . . . . . . . . . . . . . . . . 175
Using Ethernet Connections to the Internet . . . . . . . . . . . . . . . . . . 176
Configuring Ethernet During Installation . . . . . . . . . . . . . . . . 176
Configuring Ethernet from the Desktop . . . . . . . . . . . . . . . . . 177
Using Network Configuration in Fedora . . . . . . . . . . . . . . . . . 177
Identifying Other Computers (Hosts and DNS) . . . . . . . . . . . . . 179
Understanding Your Internet Connection . . . . . . . . . . . . . . . . 181
Using Dial-up Connections to the Internet . . . . . . . . . . . . . . . . . . . 184
Getting Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Setting Up Dial-up PPP . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Creating a Dial-up Connection with the Internet
Configuration Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Launching Your PPP Connection . . . . . . . . . . . . . . . . . . . . . 188
Launching Your PPP Connection on Demand . . . . . . . . . . . . . . 188
Checking Your PPP Connection . . . . . . . . . . . . . . . . . . . . . 189
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Protecting Your Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Understanding Attack Techniques . . . . . . . . . . . . . . . . . . . . . . . 193
Protecting Against Denial of Service Attacks . . . . . . . . . . . . . . . . . 194
Mailbombing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Spam Relaying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Smurf Amplification Attack . . . . . . . . . . . . . . . . . . . . . . . . 197
Protecting Against Distributed DoS Attacks . . . . . . . . . . . . . . . . . . 197
Protecting Against Intrusion Attacks . . . . . . . . . . . . . . . . . . . . . . 202
Evaluating Access to Network Services . . . . . . . . . . . . . . . . . 202
Disabling Network Services . . . . . . . . . . . . . . . . . . . . . . . . 204
Using TCP Wrappers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Detecting Intrusions from Log Files . . . . . . . . . . . . . . . . . . . . . . 208
The Role of Syslogd . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Redirecting Logs to a Loghost with syslogd . . . . . . . . . . . . . . 211
Understanding the messages Log File . . . . . . . . . . . . . . . . . . 212
Using Password Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Choosing Strong Passwords . . . . . . . . . . . . . . . . . . . . . . . 214
Using a Password File . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Using Encryption Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Symmetric Cryptography . . . . . . . . . . . . . . . . . . . . . . . . . 217
Public-Key Cryptography . . . . . . . . . . . . . . . . . . . . . . . . . 218
Secure Socket Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xix
Contents
xix
Using the Secure Shell Package . . . . . . . . . . . . . . . . . . . . . . . . . 227
Starting the SSH Service . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Using the ssh, sftp, and scp Commands . . . . . . . . . . . . . . . . . 228
Using ssh, scp, and sftp Without Passwords . . . . . . . . . . . . . . 229
Guarding Your Computer with PortSentry . . . . . . . . . . . . . . . . . . . 230
Downloading and Installing PortSentry . . . . . . . . . . . . . . . . . 231
Using PortSentry As Is . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Configuring PortSentry . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Testing PortSentry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Tracking PortSentry Intrusions . . . . . . . . . . . . . . . . . . . . . . 238
Restoring Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Security Auditing Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Choosing a Linux Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Linux at Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Other Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Getting Your Own Linux Distribution . . . . . . . . . . . . . . . . . . . . . . 245
Finding Another Linux Distribution . . . . . . . . . . . . . . . . . . . 246
Understanding What You Need . . . . . . . . . . . . . . . . . . . . . . 246
Downloading the Distribution . . . . . . . . . . . . . . . . . . . . . . 247
Burning the Distribution to CD . . . . . . . . . . . . . . . . . . . . . . 248
Exploring Common Installation Topics . . . . . . . . . . . . . . . . . . . . . 249
Knowing Your Computer Hardware . . . . . . . . . . . . . . . . . . . 249
Upgrading or Installing from Scratch . . . . . . . . . . . . . . . . . . 250
Dual Booting with Windows or Just Linux . . . . . . . . . . . . . . . 251
Using Installation Boot Options . . . . . . . . . . . . . . . . . . . . . 252
Partitioning Hard Drives . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Using LILO or GRUB Boot Loaders . . . . . . . . . . . . . . . . . . . . 261
Configuring Networking . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Configuring Other Administrative Features . . . . . . . . . . . . . . . 271
Installing from the Linux Bible DVD . . . . . . . . . . . . . . . . . . . . . . 272
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Digging into Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Red Hat Installer (Anaconda) . . . . . . . . . . . . . . . . . . . . . . . 275
RPM Package Management . . . . . . . . . . . . . . . . . . . . . . . . 276
Kudzu Hardware Detection . . . . . . . . . . . . . . . . . . . . . . . . 276
Red Hat Desktop Look-and-Feel . . . . . . . . . . . . . . . . . . . . . 276
System Configuration Tools . . . . . . . . . . . . . . . . . . . . . . . . 277
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xx xx
Contents
Going Forward with Fedora Core . . . . . . . . . . . . . . . . . . . . . . . . 277
Fedora Legacy Project . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Fedora Software Repositories . . . . . . . . . . . . . . . . . . . . . . 278
Forums and Mailing Lists . . . . . . . . . . . . . . . . . . . . . . . . . 279
Listening to the People at Red Hat . . . . . . . . . . . . . . . . . . . . . . . 279
Listening to the Red Hat Community . . . . . . . . . . . . . . . . . . . . . . 280
Installing Fedora Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Choosing Computer Hardware . . . . . . . . . . . . . . . . . . . . . . 283
Choosing an Installation Method . . . . . . . . . . . . . . . . . . . . . 284
Choosing to Install or Upgrade . . . . . . . . . . . . . . . . . . . . . . 286
Beginning the Installation . . . . . . . . . . . . . . . . . . . . . . . . . 287
Running Fedora Setup Agent . . . . . . . . . . . . . . . . . . . . . . . 293
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Inside Debian GNU/Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Debian Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Debian Package Management Tools . . . . . . . . . . . . . . . . . . . 297
Debian Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Installing Debian GNU/Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Hardware Requirements and Installation Planning . . . . . . . . . . 299
Running the Installer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Managing Your Debian System . . . . . . . . . . . . . . . . . . . . . . . . . 304
Configuring Network Connections . . . . . . . . . . . . . . . . . . . . 305
Package Management Using APT . . . . . . . . . . . . . . . . . . . . . 306
Package Management Using dpkg . . . . . . . . . . . . . . . . . . . . 309
Installing Package Sets (Tasks) with Tasksel . . . . . . . . . . . . . . 311
Alternatives, Diversions, and Stat Overrides . . . . . . . . . . . . . . 311
Managing Package Configuration with debconf . . . . . . . . . . . . 313
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Understanding SUSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
What’s in SUSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Installation and Configuration with YaST . . . . . . . . . . . . . . . . 317
RPM Package Management . . . . . . . . . . . . . . . . . . . . . . . . 320
Automated Software Updates . . . . . . . . . . . . . . . . . . . . . . . 321
Getting Support for SUSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
Installing SUSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Starting Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Starting with SUSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xxi
Contents
xxi
Understanding KNOPPIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
Looking Inside KNOPPIX . . . . . . . . . . . . . . . . . . . . . . . . . 330
What’s Cool About KNOPPIX . . . . . . . . . . . . . . . . . . . . . . . 331
Examining Challenges with KNOPPIX . . . . . . . . . . . . . . . . . . 333
Seeing Where KNOPPIX Comes From . . . . . . . . . . . . . . . . . . 334
Exploring Uses for KNOPPIX . . . . . . . . . . . . . . . . . . . . . . . 334
Starting KNOPPIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Getting a Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Booting KNOPPIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Correcting Boot Problems . . . . . . . . . . . . . . . . . . . . . . . . . 337
Using KNOPPIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
Using the KDE Desktop in KNOPPIX . . . . . . . . . . . . . . . . . . . 342
Getting on the Network . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Installing Software in KNOPPIX . . . . . . . . . . . . . . . . . . . . . . 344
Saving Files in KNOPPIX . . . . . . . . . . . . . . . . . . . . . . . . . . 344
Keeping Your KNOPPIX Configuration . . . . . . . . . . . . . . . . . . 348
Restarting KNOPPIX . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
Digging into Yellow Dog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
Installing Yellow Dog Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Hardware Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Planning Your Installation . . . . . . . . . . . . . . . . . . . . . . . . . 356
Beginning the Installation . . . . . . . . . . . . . . . . . . . . . . . . . 358
Updating Yellow Dog Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Running Mac Applications with Mac-on-Linux . . . . . . . . . . . . . . . . 365
Support Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Understanding Gentoo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Gentoo’s Open Source Spirit . . . . . . . . . . . . . . . . . . . . . . . 368
The Gentoo Community . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Building, Tuning, and Tweaking Linux . . . . . . . . . . . . . . . . . . 369
Where Gentoo Is Used . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
What’s in Gentoo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Managing Software with Portage . . . . . . . . . . . . . . . . . . . . . 372
Finding Software Packages . . . . . . . . . . . . . . . . . . . . . . . . 373
Installing Gentoo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Getting Gentoo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Starting Gentoo Installation . . . . . . . . . . . . . . . . . . . . . . . . 375
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xxii xxii
Contents
Getting into Slackware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Characterizing the Slackware Community . . . . . . . . . . . . . . . . . . . 385
The Slackware Creator . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Slackware Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
Slackware Internet Sites . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Challenges of Using Slackware . . . . . . . . . . . . . . . . . . . . . . . . . 387
Using Slackware as a Development Platform . . . . . . . . . . . . . . . . . 388
Installing Slackware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Getting Slackware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Hardware Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Starting Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Starting with Slackware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
Getting into Linspire . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Installing Software with Click-N-Run . . . . . . . . . . . . . . . . . . . 401
Other Installation Options . . . . . . . . . . . . . . . . . . . . . . . . 402
Linspire Support and Software . . . . . . . . . . . . . . . . . . . . . . . . . 403
Linspire Forums and Information . . . . . . . . . . . . . . . . . . . . 403
Audio Assistant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Installing Linspire 4.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Linspire Hardware Requirements . . . . . . . . . . . . . . . . . . . . 404
Installing Linspire . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Exploring Mandrakelinux 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
Mandrakelinux Installer (DrakX) . . . . . . . . . . . . . . . . . . . . . 411
RPM Package Management with RPMDrake . . . . . . . . . . . . . . 412
Mandrakelinux Control Center (MCC) . . . . . . . . . . . . . . . . . . 412
The Mandrakelinux Community . . . . . . . . . . . . . . . . . . . . . . . . . 413
RPM Repository on Mandrakeclub . . . . . . . . . . . . . . . . . . . . 413
Mandrakelinux Forums and News . . . . . . . . . . . . . . . . . . . . 414
Installing Mandrakelinux 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
The Right Hardware for Mandrakelinux 10 . . . . . . . . . . . . . . . 415
Begin the DrakX Installation . . . . . . . . . . . . . . . . . . . . . . . 416
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Understanding Firewalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
Protecting Desktops with Firewalls . . . . . . . . . . . . . . . . . . . . . . . 425
Starting Your Firewall in Red Hat Linux . . . . . . . . . . . . . . . . . 425
Creating a Firewall in Mandrakelinux . . . . . . . . . . . . . . . . . . 427
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xxiii
Contents
xxiii
Using Firewalls with Iptables . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Starting with Iptables . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Using Iptables to Do NAT or IP Masquerading . . . . . . . . . . . . . 434
Adding Modules with Iptables . . . . . . . . . . . . . . . . . . . . . . 435
Using Iptables as a Transparent Proxy . . . . . . . . . . . . . . . . . 435
Using Iptables for Port Forwarding . . . . . . . . . . . . . . . . . . . 436
Making a Coyote Linux Bootable Floppy Firewall . . . . . . . . . . . . . . . 437
Creating a Coyote Linux Firewall . . . . . . . . . . . . . . . . . . . . . 437
Building the Coyote Linux Floppy . . . . . . . . . . . . . . . . . . . . 438
Running the Coyote Linux Floppy Firewall . . . . . . . . . . . . . . . 444
Managing the Coyote Linux Floppy Firewall . . . . . . . . . . . . . . 444
Using Other Firewall Distributions . . . . . . . . . . . . . . . . . . . . . . . 446
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Exploring Bootable Linuxes . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
Booting Rescue Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . 449
KNOPPIX Security Tools Distribution . . . . . . . . . . . . . . . . . . 450
The Inside Security Rescue Toolkit . . . . . . . . . . . . . . . . . . . 451
Booting Multimedia Distributions . . . . . . . . . . . . . . . . . . . . . . . 452
MoviX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
GeeXboX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
Booting Tiny Desktop Distributions . . . . . . . . . . . . . . . . . . . . . . 454
Damn Small Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
Feather Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Playing Digital Media and Obeying the Law . . . . . . . . . . . . . . . . . . 461
Copyright Protection Issues . . . . . . . . . . . . . . . . . . . . . . . 462
Exploring Codecs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
Playing Music . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
Setting Up Audio Cards . . . . . . . . . . . . . . . . . . . . . . . . . . 466
Choosing an Audio CD Player . . . . . . . . . . . . . . . . . . . . . . . 468
Using MIDI Audio Players . . . . . . . . . . . . . . . . . . . . . . . . . 477
Performing Audio File Conversion and Compression . . . . . . . . . 477
Recording and Ripping Music . . . . . . . . . . . . . . . . . . . . . . . . . . 481
Creating an Audio CD with cdrecord . . . . . . . . . . . . . . . . . . . 481
Ripping CDs with Grip . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
Creating CD Labels with cdlabelgen . . . . . . . . . . . . . . . . . . . 484
Working with TV, Video, and Digital Imaging . . . . . . . . . . . . . . . . . 485
Watching TV with Tvtime . . . . . . . . . . . . . . . . . . . . . . . . . 486
Videoconferencing with GnomeMeeting . . . . . . . . . . . . . . . . . 488
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xxiv xxiv
Contents
Watching Movies and Video . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
Watching Video with Xine . . . . . . . . . . . . . . . . . . . . . . . . . 490
Using Helix Player and RealPlayer 10 . . . . . . . . . . . . . . . . . . 494
Using a Digital Camera with Gtkam and gPhoto2 . . . . . . . . . . . . . . . 494
Downloading Digital Photos with Gtkam . . . . . . . . . . . . . . . . 497
Using Your Camera as a Storage Device . . . . . . . . . . . . . . . . . 498
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
Using OpenOffice.org . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502
Other Word Processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Using StarOffice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Using AbiWord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
Using KOffice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
Getting Away from Windows . . . . . . . . . . . . . . . . . . . . . . . 507
Using Traditional Linux Publishing Tools . . . . . . . . . . . . . . . . . . . 508
Creating Documents in Groff or LaTeX . . . . . . . . . . . . . . . . . . . . . 509
Text Processing with Groff . . . . . . . . . . . . . . . . . . . . . . . . 511
Text Processing with TeX/LaTeX . . . . . . . . . . . . . . . . . . . . . 521
Converting Documents . . . . . . . . . . . . . . . . . . . . . . . . . . 524
Building Structured Documents . . . . . . . . . . . . . . . . . . . . . 526
Printing Documents in Linux . . . . . . . . . . . . . . . . . . . . . . . . . . 530
Printing to the Default Printer . . . . . . . . . . . . . . . . . . . . . . 530
Printing from the Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . 531
Checking the Print Queues . . . . . . . . . . . . . . . . . . . . . . . . 531
Removing Print Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
Checking Printer Status . . . . . . . . . . . . . . . . . . . . . . . . . . 532
Displaying Documents with Ghostscript and Acrobat . . . . . . . . . . . . 533
Using the ghostscript and gv Commands . . . . . . . . . . . . . . . . 533
Using Adobe Acrobat Reader . . . . . . . . . . . . . . . . . . . . . . . 534
Working with Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
Manipulating Images with GIMP . . . . . . . . . . . . . . . . . . . . . 535
Acquiring Screen Captures . . . . . . . . . . . . . . . . . . . . . . . . 537
Modifying Images with KPaint . . . . . . . . . . . . . . . . . . . . . . 537
Using Scanners Driven by SANE . . . . . . . . . . . . . . . . . . . . . . . . . 538
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
Using E-Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Choosing an E-Mail Client . . . . . . . . . . . . . . . . . . . . . . . . . 541
Getting Here from Windows . . . . . . . . . . . . . . . . . . . . . . . . 543
Getting Started with E-Mail . . . . . . . . . . . . . . . . . . . . . . . . 544
Tuning Up E-Mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
Reading E-Mail with Mozilla Mail . . . . . . . . . . . . . . . . . . . . . 546
Managing E-Mail in Evolution . . . . . . . . . . . . . . . . . . . . . . . 550
Getting Thunderbird . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
Working with Text-Based E-Mail Readers . . . . . . . . . . . . . . . . 554
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xxv
Contents
xxv
Choosing a Web Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556
Web Browsing with Mozilla . . . . . . . . . . . . . . . . . . . . . . . . 556
Using Text-Based Web Browsers . . . . . . . . . . . . . . . . . . . . . 566
Running Firefox Web Browser . . . . . . . . . . . . . . . . . . . . . . 567
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
Basic Linux Gaming Information . . . . . . . . . . . . . . . . . . . . . . . . 570
Where to Get Information About Linux Gaming . . . . . . . . . . . . 570
Getting Started with Linux Gaming . . . . . . . . . . . . . . . . . . . . 571
Choosing a Video Card for Gaming . . . . . . . . . . . . . . . . . . . . 571
X Window Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
GNOME Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
KDE Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574
Chess Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
Freeciv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
Commercial Linux Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583 id Software Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
TransGaming and Cedega Gaming . . . . . . . . . . . . . . . . . . . . 585
Loki Software Game Demos . . . . . . . . . . . . . . . . . . . . . . . . 588
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
Components of a LAMP Server . . . . . . . . . . . . . . . . . . . . . . . . . 596
Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
Setting Up Your LAMP Server . . . . . . . . . . . . . . . . . . . . . . . . . . 598
Installing Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598
Installing PHP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
Installing MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
Operating Your LAMP Server . . . . . . . . . . . . . . . . . . . . . . . . . . 601
Editing Your Apache Configuration Files . . . . . . . . . . . . . . . . 602
Adding a Virtual Host to Apache . . . . . . . . . . . . . . . . . . . . . 604
Installing a Web Application: Gallery . . . . . . . . . . . . . . . . . . 606
Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
Configuration Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
Access Forbidden and Server Internal Errors . . . . . . . . . . . . . 611
Securing Your Web Traffic with SSL/TLS . . . . . . . . . . . . . . . . . . . . 612
Generating Your Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . 614
Configuring Apache to Support SSL/TLS . . . . . . . . . . . . . . . . 615
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xxvi xxvi
Contents
Internet E-Mail’s Inner Workings . . . . . . . . . . . . . . . . . . . . . . . . 617
Server Configuration Options . . . . . . . . . . . . . . . . . . . . . . . . . . 619
Preparing Your System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620
Network Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 620
Common Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
Installing and Running sendmail . . . . . . . . . . . . . . . . . . . . . . . . 623
Installing and Running Postfix . . . . . . . . . . . . . . . . . . . . . . . . . . 626
Testing and Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . 630
Configuring Mail Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
Configuring Fetchmail . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
Configuring Web-Based Mail . . . . . . . . . . . . . . . . . . . . . . . 632
Securing Communications with SSL/TLS . . . . . . . . . . . . . . . . . . . . 632
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
Common UNIX Printing Service (CUPS) . . . . . . . . . . . . . . . . . . . . 636
Setting Up Printers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
Using Web-Based CUPS Administration . . . . . . . . . . . . . . . . . 637
Using the Red Hat Printer Configuration Window . . . . . . . . . . . 640
Working with CUPS Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . 649
Configuring the CUPS Server (cupsd.conf) . . . . . . . . . . . . . . . 649
Starting the CUPS Server . . . . . . . . . . . . . . . . . . . . . . . . . 650
Configuring CUPS Printer Options Manually . . . . . . . . . . . . . . 651
Using Printing Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652
Printing with lpr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652
Listing Status with lpc . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
Removing Print Jobs with lprm . . . . . . . . . . . . . . . . . . . . . . 653
Configuring Print Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 654
Configuring a Shared CUPS Printer . . . . . . . . . . . . . . . . . . . . 654
Configuring a Shared Samba Printer . . . . . . . . . . . . . . . . . . . 656
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658
Setting Up an NFS File Server . . . . . . . . . . . . . . . . . . . . . . . . . . 660
Getting NFS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 662
Sharing NFS File Systems . . . . . . . . . . . . . . . . . . . . . . . . . 662
Using NFS File Systems . . . . . . . . . . . . . . . . . . . . . . . . . . 667
Unmounting NFS File Systems . . . . . . . . . . . . . . . . . . . . . . 672
Other Cool Things to Do with NFS . . . . . . . . . . . . . . . . . . . . 673
Setting Up a Samba File Server . . . . . . . . . . . . . . . . . . . . . . . . . 674
Getting and Installing Samba . . . . . . . . . . . . . . . . . . . . . . . 675
Configuring Samba with SWAT . . . . . . . . . . . . . . . . . . . . . . 676
Working with Samba Files and Commands . . . . . . . . . . . . . . . 685
Using Samba Shared Directories . . . . . . . . . . . . . . . . . . . . . 688
Troubleshooting Your Samba Server . . . . . . . . . . . . . . . . . . 689
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 692
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xxvii
Contents
xxvii
Linux Programming Environments . . . . . . . . . . . . . . . . . . . . . . . 696
The Linux Development Environment . . . . . . . . . . . . . . . . . . 696
Graphical Programming Environments . . . . . . . . . . . . . . . . . 705
The Command-Line Programming Environment . . . . . . . . . . . . 709
Linux Programming Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . 710
Creating Command-Line Interfaces . . . . . . . . . . . . . . . . . . . 710
Creating Graphical Interfaces . . . . . . . . . . . . . . . . . . . . . . . 717
Application Programming Interfaces . . . . . . . . . . . . . . . . . . 718
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722
The Well-Stocked Toolkit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723
Using the GCC Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724
Compiling Multiple Source Code Files . . . . . . . . . . . . . . . . . . 726
GCC Command-Line Options . . . . . . . . . . . . . . . . . . . . . . . 728
Automating Builds with Make . . . . . . . . . . . . . . . . . . . . . . . . . . 730
Library Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732
The nm Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 734
The ar Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735
The ldd Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735
The ldconfig Command . . . . . . . . . . . . . . . . . . . . . . . . . . 736
Environment Variables and Configuration Files . . . . . . . . . . . . 736
Source Code Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737
Source Code Control Using RCS . . . . . . . . . . . . . . . . . . . . . 737
Source Code Control with CVS . . . . . . . . . . . . . . . . . . . . . . 740
Debugging with GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744
Starting GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744
Inspecting Code in the Debugger . . . . . . . . . . . . . . . . . . . . . 747
Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 748
Setting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750
Working with Source Code . . . . . . . . . . . . . . . . . . . . . . . . 751
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 752
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767
04_579495 ftoc.qxd 12/27/04 9:52 PM Page xxviii
05_579495 pt01.qxd 12/27/04 9:52 PM Page 1
P A R T
I
I
✦ ✦ ✦ ✦
In This Part
Chapter 1
Starting with Linux
Chapter 2
Running Commands from the Shell
Chapter 3
Getting into the
Desktop
✦ ✦ ✦ ✦
05_579495 pt01.qxd 12/27/04 9:52 PM Page 2
06_579495 ch01.qxd 12/27/04 10:29 PM Page 3
L
inux is ready for prime time. Are you ready for Linux?
Well, whether you know it or not, you probably run into Linux every day. When you buy a book from Amazon.com or search the Web with Google, you use Linux. You use Linux in your TiVo when you record TV shows, and Linux may be running the PDA in your pocket. Animations you saw in the movie
Shrek 2
were created by hundreds of Linux workstations and rendered by a server farm of hundreds of other Linux systems.
Linux truly is everywhere.
Big computer companies, such as IBM, Oracle, Novell, and
Red Hat, are lining up their products behind Linux. After dismissing it for years, companies such as Microsoft and Sun
Microsystems are gathering their forces to deal with it. Who would have thought that some of the world’s largest computer companies would fear a computer system built from code nobody can own that is given away for free?
But despite the fact that IBM featured Mohammed Ali in commercials for Linux during the Super Bowl and that the mere mention of “Linux” for a dot-com company sent its stock through the roof in the 1990s, most people don’t really know what Linux is. As Linux continues to improve exponentially, that’s going to change.
The
Linux Bible 2005 Edition
brings you into the world of open source software that, through some strange twists and turns, has fallen most publicly under the “Linux” banner. Through descriptions and procedures, this book helps you to do the following:
✦
Understand what Linux is and where it comes from.
✦
Sort through the various incarnations of Linux to choose one (or more) that is right for you (you get several of them on this book’s DVD and CD).
✦ ✦ ✦ ✦
In This Chapter
Understanding Linux
Using Linux
Linux myths, legends, and FUD
✦ ✦ ✦ ✦
06_579495 ch01.qxd 12/27/04 10:29 PM Page 4
4
Part I ✦
Linux First Steps
✦
Try out Linux as a desktop computer, server computer, or programmer’s workstation.
✦
Become connected (if you so choose) to the open source software movement, as well as many separate high-quality software projects that are included with
Linux.
Whether you are using Linux for the first time or just want to try out a new Linux distribution, the
Linux Bible 2005 Edition
is your guide to using Linux and the latest open source technology. While different Linux distributions vary in the exact software they include (you’ll see why that is later), this book describes the most popular software available for Linux to
✦
Manage your desktop (menus, icons, windows, and so on).
✦
Listen to music and watch video.
✦
Use word processor, spreadsheet, and other office productivity applications.
✦
Browse the Web and send e-mail.
✦
Play games.
✦
Find thousands of other open source software packages you can get for free.
Because most Linux distributions also include features that let them act as servers
(in fact, that’s what Linux has always been best at), you’ll also learn about software available for Linux that lets you:
✦
Connect to the Internet or other network.
✦
Use Linux as a firewall, router, and DHCP server to protect and manage your private network.
✦
Run a Web server (using Apache, MySQL, and PHP).
✦
Run a mail server (using sendmail or another mail transfer agent).
✦
Run a print server (using Samba or CUPS).
✦
Run a file server (using FTP or Samba).
This book guides you through the basics of getting started with the Linux features just mentioned plus many more features that I’ll get to later. You’ll go through the following basic steps:
You need to know where Linux came from, how it is developed, and how it’s ultimately packaged. This chapter describes the
UNIX heritage on which Linux was founded, the open source software development efforts underway, and the organizations and individuals that package and produce Linux distributions.
In the past, an impediment to trying Linux has been getting it installed on a computer that is devoted solely to Microsoft Windows. With bootable Linux systems such as KNOPPIX (and others included with this book),
06_579495 ch01.qxd 12/27/04 10:29 PM Page 5
Chapter 1
✦
Starting with Linux
5 you can boot a fully functioning Linux from DVD, CD, or floppy disk without disturbing the current contents of your computer.
You can install a fully functioning Linux system permanently on your hard disk. Disk space required varies from a few hundred megabytes for a minimal installation to 6 gigabytes for a full range of desktop, server, and programming features. Chapters in Part III, “Choosing and Installing a Linux
Distribution,” describe how to install several different Linux distributions.
You won’t know if Linux can be used to replace your current desktop or server system until you start using it. This book helps you try
OpenOffice.org software to write documents, create spreadsheets, and build presentations. It describes XMMS and MPlayer for playing your music and video content, respectively, and covers some of the best Linux tools available for Web browsing (for example, Mozilla and Konqueror) and managing your e-mail (such as Evolution and Thunderbird).
Linux works very well as a desktop system, and it also can be configured to act as a router, a firewall, and a variety of server types. While there are some excellent graphical tools for administering Linux systems, most
Linux administrators edit configuration files and run commands to configure
Linux. Part II, “Running the Show,” contains basic information for administering Linux, and Part V, “Running Servers,” discusses procedures for setting up various types of servers.
Once you’ve been through the book, you should be proficient enough to track down your more advanced questions through the volumes of man pages, FAQs, HOW-TOs, and forums that cover different aspects of the Linux operating system.
People who don’t know what Linux is sometimes ask me if it’s a program that runs on Microsoft Windows. When I tell them that Linux is, itself, an operating system like Windows and that they can remove (or never purchase) Windows, I sometimes get a surprised reaction: “A PC can run with nothing from Microsoft on it?”
Yes, Linux is a full-blown operating system that is a free clone of the UNIX operating system. Start your computer with Linux, and Linux takes over the operation of your
PC and manages the following aspects of your computer:
✦
— Because Linux can run many processes from many different users at the same time (even with multiple CPUs on the same machine), Linux needs to be able to manage those processes. The Linux scheduler sets the priorities for running tasks and manages which processes run on which CPUs (if multiple processors are present). The scheduler can be tuned differently for different types of Linux systems. If it’s tuned properly, the most important processes get the quickest responses from the processor. For example, a Linux scheduler on a desktop system gives higher priority to things like moving a window on the desktop than it does to a background file transfer.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 6
6
Part I ✦
Linux First Steps
✦
— Linux tries to keep processes with the most immediate need in
RAM, while managing how processes that exceed the available memory are moved to swap space. Swap space is a defined area on your hard disk that’s used to handle the overflow of running processes and data. When RAM is full, processes are placed in swap space. When swap space is full (something that you don’t want to happen), new processes can’t start up.
✦
— Linux supports thousands of hardware devices, yet keeps the kernel a manageable size by including only a small set of drivers in the active kernel.
Using loadable modules, the kernel can add support for other hardware as needed. Modules can be loaded and unloaded on demand, as hardware is added and removed. (The kernel, described in detail a bit later on, is the heart of the Linux operating system.)
✦
— File systems provide the structure in which files are stored on hard disk, CD, DVD, floppy disk, or other media. Linux knows about different file system types (such as Linux ext3 and reiserfs file systems, or VFAT and
NTFS from Windows systems) and how to manage them.
✦
— Like UNIX, Linux was built from the ground up to enable multiple users to access the system simultaneously. To protect each user’s resources, every file, directory, and application is assigned sets of read, write, and execute permissions that define who can access them. In a standard Linux system, the root user has access to the entire system, some special logins have access to control particular services (such as Apache for Web services), and users can be assigned permission individually or in groups. Recent features, such as
Security-Enhanced Linux, enable more refined tuning, and protection in highly secure computing environments.
What I have just described are components that primarily make up what is referred to as the Linux
kernel.
In fact, the Linux kernel (which was created and is still managed by Linus Torvalds) is what gives Linux its name. The kernel is the software that starts up when you boot your computer and manages the programs you use so they can communicate effectively and simply with your computer hardware.
Other components, such as administrative commands and applications, are added to the kernel from other open source projects to make Linux a complete operating system. The GNU project, in particular, contributed many components that are now in Linux. (GNU, Apache, KDE, GNOME, and other key open source projects in Linux are discussed a bit later.) Those other projects added such things as:
✦
— Consisting of a graphical framework (typically the X Window System), window managers, panels, icons, and menus. GUIs enable you to use Linux with a keyboard and mouse combination, instead of just typing commands (as was done in the old days).
✦
— Including hundreds (perhaps thousands) of commands and graphical windows to do such things as add users, manage disks, monitor the network, install software, and generally secure and manage your computer.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 7
Chapter 1
✦
Starting with Linux
7
✦
— Although no Linux distribution includes all of them, there are literally thousands of games, office productivity tools, Web browsers, chat windows, multimedia players, and other applications available for Linux.
✦
— Including programming utilities for creating applications and libraries for implementing specialty interfaces.
✦
— Enabling you to offer services from your Linux computer to another computer on the network. In other words, while Linux includes Web browsers to view Web pages, it can also be the computer that serves up Web pages to others. Popular server features include Web, mail, database, printer, file, DNS, and DHCP servers.
Once Linus Torvalds and friends had a working Linux kernel, pulling together a complete open source operating system was possible. The reason this could be done was because so much of the available “free” software was:
✦
Covered by the GNU Public License (GPL) or similar license. That allowed the entire operating system to be freely distributed, provided that some guidelines were followed relating to how the source code for that software was made available going forward.
✦
Based on UNIX-like systems. Clones of virtually all the other user-level components of a UNIX system had been created. Those and other utilities and applications were built to run on UNIX or other UNIX-like systems.
Linux has become the culmination of the open source software movement. But the traditions of sharing code and building communities that made Linux possible started years before Linux was born. You could argue that it began in a comfortable think tank known as Bell Laboratories.
If you have not used Linux before, you should expect a few things to be different from other operating systems. Here is a brief list of some features that you might find cool about using Linux:
✦
— Uptime is valued as a matter of pride (remember,
Linux and other UNIX systems are most often used as servers, which are expected to stay up 24x7). After the original installation, you can install or remove most software without having to reboot your computer.
✦
— You can start and stop individual services (such as Web, file, and e-mail services) without rebooting or even interrupting the work of any other users or features of the computer.
In other words, you should not have to reboot your computer every time someone sneezes.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 8
8
Part I ✦
Linux First Steps
✦
You can usually change to another Linux, UNIX, or BSD system and still use the exact same software! Most open source software projects were created to run on any UNIX-like system, and many also run on Windows systems, if you need them to. If it won’t run where you want it to, chances are that you, or someone you hire, can port it to the computer you want.
✦
— If the applications you want are not delivered with your version of Linux, you can often download and install them with a single command, using tools such as apt and yum.
✦
— Once you learn your way around
Linux, you’ll find that (given the right permissions on your computer) most configuration is done in plain-text files that are easy to find and change.
✦
— The X Window System (providing the framework for your
Linux desktop) has been around longer than Microsoft Windows. The KDE and
GNOME desktop environments provide graphical interfaces (windows, menus, icons, and so forth) that rival those on Microsoft systems. Ease-of-use problems with Linux systems are rapidly evaporating.
✦
— Linux, in its most basic form, has no corporate agenda or bottom line to meet. You are free to choose the Linux distribution that suits you, look at the code that runs the system, add and remove any software you like, and make your computer do what you want it to do.
Some aspects of Linux make it hard for some new users to get started. One is that
Linux is typically set up to be secure by default, so you need to adjust to using an administrative login (root) to make most changes that affect the whole computer system. Although this can be a bit inconvenient, trust me, it makes your computer safer than just letting anyone do anything.
For the same reason, many services are off by default, so you need to turn them on and do at least minimal configuration to get them going. Linux can be more difficult than Windows because it is just different, but because you’re reading this book, I assume you want to learn about those differences.
Some histories of Linux begin with this message posted by Linus Torvalds to the comp.os.minix
newsgroup on August 25, 1991:
Hello everybody out there using minix -
I’m doing a (free) operating system (just a hobby, won’t be big and professional like gnu) for 386(486) AT clones. This has been brewing since april, and is starting to get ready. I’d like any feedback on things people like/dislike in minix, as
06_579495 ch01.qxd 12/27/04 10:29 PM Page 9
Chapter 1
✦
Starting with Linux
9 my OS resembles it somewhat (same physical layout of the file-system (due to practical reasons) among other things)... Any suggestions are welcome, but I won’t promise I’ll implement them :-)
Linus ([email protected])
PS. Yes — it’s free of any minix code, and it has a multi-threaded fs. It is NOT protable[sic] (uses 386 task switching etc), and it probably never will support anything other than AT-harddisks, as that’s all I have :-(.
Reprinted from Linux International Web site ( www.li.org/linuxhistory.php
)
Minix was a free UNIX-like operating system that ran on PCs in the early 1990s. Like
Minix, Linux was also a clone of the UNIX operating system. To truly appreciate how a free operating system could have been modeled after a proprietary system from
AT&T Bell Laboratories, it helps to understand the culture in which UNIX was created and the chain of events that made the essence of UNIX possible to reproduce freely.
From the very beginning, the UNIX operating system was created and nurtured in a communal environment. Its creation was not driven by market needs but by a desire to overcome impediments to producing programs. AT&T, which owned the
UNIX trademark originally, eventually made UNIX into a commercial product, but by that time, many of the concepts (and even much of the early code) that made UNIX special had fallen into the public domain.
If you are under 30 years old, you may not remember a time when AT&T was “the” phone company. Up until the early 1980s, AT&T didn’t have to think much about competition because if you wanted a phone in the United States, you had to go to
AT&T. It had the luxury of funding pure research projects. The Mecca for such projects was the Bell Laboratories site in Murray Hill, New Jersey.
After the failure of a project called Multics around 1969, Bell Labs employees Ken
Thompson and Dennis Ritchie set off on their own to create an operating system that would offer an improved environment for developing software. Up to that time, most programs were written on punch cards that had to be fed in batches to mainframe computers. In a 1980 lecture on “The Evolution of the UNIX Time-sharing System,”
Dennis Ritchie summed up the spirit that started UNIX:
What we wanted to preserve was not just a good environment in which to do programming, but a system around which a fellowship could form. We knew from experience that the essence of communal computing as supplied by remote-access, time-shared machines is not just to type programs into a terminal instead of a keypunch, but to encourage close communication.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 10
10
Part I ✦
Linux First Steps
The simplicity and power of the UNIX design began breaking down barriers that impeded software developers. The foundation of UNIX was set with several key elements:
✦
— After creating the structure that allowed levels of subdirectories (which, for today’s desktop users, looks like folders inside of folders), UNIX could be used to organize the files and directories in intuitive ways. Furthermore, complex methods of accessing disks, tapes, and other devices were greatly simplified by representing those devices as individual device files that you could also access as items in a directory.
✦
— Early UNIX systems also included the concept of input redirection and pipes. From a command line, UNIX users could direct the output of a command to a file using a right arrow key ( > ). Later, the concepts of pipes was added ( | ) where the output of one command could be directed to the input of another command. For example, the command line
$
cat file1 file2 | sort | pr | lpr
concatenates ( cat ) file1 and file2, sorts ( sort ) the lines in those files alphabetically, paginates the sorted text for printing ( pr ), and directs the output to the computer’s default printer ( lpr ). This method of directing input and output enabled developers to create their own specialized utilities that could be joined together with existing utilities. This modularity made it possible for lots of code to be developed by lots of different people.
✦
— Much of the early work in simplifying the experience of using
UNIX led to its also becoming extraordinarily portable to run on different computers. By having device drivers (represented by files in the file system tree),
UNIX could present an interface to applications in such a way that the programs didn’t have to know about the details of the underlying hardware. To later port
UNIX to another system, developers only had to change the drivers. The applications program didn’t have to change for different hardware!
To make the concept of portability a reality, however, a high-level programming language was needed to implement the software needed. To that end,
Brian Kernighan and Dennis Ritchie created the C programming language. In
1973, UNIX was rewritten in C. Today, C is still the primary language used to create the UNIX (and Linux) operating system kernels.
As Ritchie went on to say in his 1980 lecture:
Today, the only important UNIX program still written in assembler is the assembler itself; virtually all the utility programs are in C, and so are most of the applications programs, although there are sites with many in Fortran, Pascal, and
Algol 68 as well. It seems certain that much of the success of UNIX follows from the readability, modifiability, and portability of its software that in turn follows from its expression in high-level languages.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 11
Chapter 1
✦
Starting with Linux
11
If you are a Linux enthusiast and are interested in what features from the early days of Linux have survived, an interesting read is Dennis Ritchie’s reprint of the first
UNIX programmer’s manual (dated November 3, 1971). You can find it at Dennis
Ritchie’s Web site: http://cm.bell-labs.com/cm/cs/who/dmr/1stEdman.html
.
The form of this documentation is UNIX man pages — which is still the primary format for documenting UNIX and Linux operating system commands and programming tools today.
What’s clear as you read through the early documentation and accounts of the
UNIX system is that the development was a free-flowing process, lacked ego, and was dedicated to making UNIX excellent. This process led to a sharing of code
(both inside and outside of Bell Labs) that allowed rapid development of a highquality UNIX operating system. It also led to an operating system that AT&T would find difficult to reel back in later.
Before AT&T divestiture in 1984, when it was split up into AT&T and seven “baby
Bell” companies, AT&T was forbidden to sell computer systems. Companies you now know by names such as Verizon, Qwest, SBC Communications, and Lucent
Technologies were all part of AT&T. As a result of AT&T’s monopoly of the telephone system, the U.S. government was concerned that an unrestricted AT&T might dominate the fledgling computer industry.
Because AT&T was restricted from selling computers directly to customers before its divestiture, UNIX source code was licensed to universities for a nominal fee.
There was no UNIX operating system for sale from AT&T that you didn’t have to compile yourself.
In 1975, UNIX V6 became the first version of UNIX available for widespread use outside of Bell Laboratories. From this early UNIX source code, the first major variant of
UNIX was created at University of California at Berkeley. It was named the Berkeley
Software Distribution (BSD).
For most of the next decade, the BSD and Bell Labs versions of UNIX headed off in separate directions. BSD continued forward in the free-flowing, share-the-code manner that was the hallmark of the early Bell Labs UNIX, while AT&T started steering
UNIX toward commercialization. With the formation of a separate UNIX Laboratory, which moved out of Murray Hill and down the road to Summit, New Jersey, AT&T began its attempts to commercialize UNIX. By 1984, divestiture was behind AT&T, and it was ready to really start selling UNIX.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 12
12
Part I ✦
Linux First Steps
The UNIX Laboratory was considered a jewel that couldn’t quite find a home or a way to make a profit. As it moved between Bell Laboratories and other areas of AT&T, its name changed several times. It is probably best remembered by its last name, which it had as it began its spin off from AT&T: UNIX System Laboratories (USL).
Note
The UNIX source code that came out of USL, the legacy of which is now owned by
Santa Cruz Operation (SCO), is being used as the basis for lawsuits by SCO against major Linux vendors (such as IBM and Red Hat Inc.). Because of that, I think the efforts from USL that have contributed to the success of Linux are sometimes disrespected.
You have to remember that, during the 1980s, many computer companies were afraid that a newly divested AT&T would pose more of a threat to controlling the computer industry than would an upstart company in Redmond, Washington. To calm the fears of IBM, Intel, DEC, and other computer companies, the UNIX Lab made the following commitments to ensure a level playing field:
✦
— Instead of producing its own boxed set of UNIX, AT&T continued to only sell source code and to make it available equally to all licensees.
Each company would then port UNIX to its own equipment. It wasn’t until about
1992, when the lab was spun off as a joint venture with Novell (called Univel) and then eventually sold to Novell, that a commercial boxed set of UNIX (called
UnixWare) was produced directly from that source code.
✦
— To create an environment of fairness and community to its OEMs (original equipment manufacturers), AT&T began standardizing what different ports of UNIX had to be able to do to still be called UNIX. To that end, compliance with POSIX standards and the AT&T UNIX System V Interface
Definition (SVID) were specifications UNIX vendors could use to create compliant UNIX systems. Those same documents also served as road maps for the creation of Linux.
In an early e-mail newsgroup post from Linus Torvalds, Linux makes a request for a copy, preferably online, of the POSIX standard. I think that nobody from AT&T expected someone to actually be able to write their own clone of UNIX from those interfaces without using any of its UNIX source code.
✦
— Again, until the very end of USL, most decisions on the direction of UNIX were made based on technical considerations. Management was promoted up through the technical ranks, and there was never any talk that I heard of writing software to break other companies’ software or otherwise restrict the success of USL’s partners.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 13
Chapter 1
✦
Starting with Linux
13
When USL eventually started taking on marketing experts and creating a desktop
UNIX product for end users, Microsoft Windows already had a firm grasp on the desktop market. Also, because the direction of UNIX had always been toward source code licensing destined for large computing systems, USL had pricing difficulties for its products. For example, on software it was including with UNIX, USL found itself having to pay out per-computer licensing fees that were based on $100,000 mainframes instead of $2,000 PCs. Add to that the fact that no application programs were available with UNIXWare, and you can see why the endeavor failed.
Successful marketing of UNIX systems at the time, however, was happening with other computer companies. SCO had found a niche market, primarily selling PC versions of UNIX running dumb terminals in small offices. Sun Microsystems was selling lots of
UNIX workstations (originally based on BSD but which was merged with UNIX in SVR4) for programmers and high-end technology applications (such as stock trading).
Other commercial UNIXs were also emerging by the 1980s as well. This new ownership assertion of UNIX was beginning to take its toll on the spirit of open contributions.
Lawsuits were being raised to protect UNIX source code and trademarks. In 1984, this new, restrictive UNIX gave rise to an organization that eventually led a path to
Linux: the Free Software Foundation.
In 1984, Richard M. Stallman started the GNU project ( www.gnu.org
), recursively named by the phrase GNU is Not UNIX. As a project of the Free Software Foundation
(FSF), GNU was intended to become a recoding of the entire UNIX operating system that could be freely distributed.
While rewriting millions of lines of code might seem daunting to one or two people, spreading the effort across dozens, or even hundreds, of programmers made the project possible. It turned out that not only could the same results be gained by all new code, but that in some cases that code was better than the original UNIX versions. Because everyone could see the code being produced for the project, poorly written code could be corrected quickly or replaced over time.
If you are familiar with UNIX, try searching the more than 3,400 GNU software packages for your favorite UNIX commands from the Free Software Directory ( http:// directory.fsf.org/GNU ). Chances are you will find it there, along with many, many other software projects available as add-ons.
Over time, the term
free software
has been mostly replaced by the term
open source software.
This helps bring home the fact that, while you are free to use the software as you like, you have some responsibility to make the improvements you make to the code available to others. In that way, everyone in the community can benefit from your work as you have benefited from others’.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 14
14
Part I ✦
Linux First Steps
To clearly define how open source software should be handled, the GNU software project created the GNU Public License. Although there are many other software licenses covering slightly different approaches to protecting free software, the GPL is perhaps the most well known — and it’s the one that covers the Linux kernel itself.
Basic features of the GNU Public License include:
✦
— The original author retains the rights to his or her software.
✦
— People can use the GNU software in their own software, changing and redistributing it as they please. They do, however, have to include the source code with their distribution (or make it easily available).
✦
— Even if you were to repackage and resell the software, the original GNU agreement must be maintained with the software, which means all future recipients of the software have the opportunity to change the source code, just as you did.
There is no warranty on GNU software. If something goes wrong, the original developer of the software has no obligation to fix the problem. However, many organizations, big and small, offer paid support packages for the software when it is included in their Linux or other open source software distribution. (See the
“OSI Open Source Definition” section later in this chapter for a more detailed definition of open source software.)
Despite its success producing thousands of UNIX utilities, the GNU project itself failed to produce one critical piece of code: the kernel. Its attempts to build an open source kernel with the GNU Hurd project ( www.gnu.org/software/hurd
) were unsuccessful.
The one software project that had a chance of beating out Linux to be the premier open source software project was the venerable old BSD project. By the late 1980s,
BSD developers at UC Berkeley realized that they had already rewritten most of the
UNIX source code they had received a decade earlier.
In 1989, UCB distributed its own UNIX-like code as Net/1 and later (in 1991) as Net/2.
Just as UC Berkeley was preparing a complete, UNIX-like operating system that was free from all AT&T code, AT&T hit them with a lawsuit in 1992. The suit claimed that the software was written using trade secrets taken from AT&T’s UNIX system.
The lawsuit was dropped when Novell bought UNIX System Laboratories from AT&T in 1994. But, during that critical time period, there was enough fear and doubt about the legality of the BSD code that the momentum BSD had gained to that point in the fledgling open source community was lost. Many people started looking for another open source alternative. The time was ripe for a college student from Finland who was working on his own kernel.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 15
Chapter 1
✦
Starting with Linux
15
Note
Today, BSD versions are available from three projects: FreeBSD, NetBSD, and
OpenBSD. People generally characterize FreeBSD as the easiest to use, NetBSD as available on the most computer hardware platforms, and OpenBSD as fanatically secure. Many security-minded individuals still prefer BSD over Linux.
In 1991, Linus Torvalds, a student at the University of Helsinki, Finland, started work on a UNIX-like kernel because he wanted to be able to use the same kind of operating system on his home PC that he used at school. At the time, Linus was using Minix, but he wanted to go beyond what the Minix standards permitted.
As noted earlier, Linus announced the first public version of the Linux kernel to the comp.os.minix
newsgroup on August 25, 1991. Although Linus guesses that the first version didn’t actually come out until mid-September of that year (see the Linux
International Web site’s Linux History page: www.li.org/linuxhistory.php
).
Although Torvalds stated that Linux was written for the 386 processor and probably wasn’t portable, others persisted in encouraging (and contributing to) a more portable approach in the early versions of Linux. By October 5, Linux 0.02 was released with much of the original assembly code rewritten in the C programming language, which made it possible to start porting it to other machines.
The Linux kernel was the last — and the most important — piece of code that was needed to complete a whole UNIX-like operating system under the GPL. So, when people started putting together distributions, the name Linux and not GNU is what stuck. Some distributions such as Debian, however, refer to themselves as GNU/Linux distributions.
Within the next few years, commercial and noncommercial Linux distributions began to emerge. MCC Interim Linux ( ftp.mcc.ac.uk/pub/linux/distributions/
MCC ) was released in the U.K. in February 1992. Slackware Linux (described in Chapter 14), which was first released in April 1993, is one of the oldest surviving Linux distributions.
Today, Linux can be described as an open source UNIX-like operating system that reflects a combination of SVID, POSIX, and BSD compliance. Linux continues to aim toward compliance with POSIX as well as with standards set by the new owner of the UNIX trademark, The Open Group ( www.unix-systems.org
).
The nonprofit Open Source Development Labs ( www.osdl.org
), which employs
Linus Torvalds, manages the direction today of Linux development efforts. Its sponsors’ list is like a who’s who of commercial Linux vendors, including IBM, Red Hat,
SUSE (Novell), VA Software, HP, Dell, Computer Associates, Intel, Cisco Systems, and others. OSDL’s primary charter is to accelerate the growth of Linux in telecommunications and data centers.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 16
16
Part I ✦
Linux First Steps
Although much of the thrust of corporate Linux efforts is on corporate, enterprise computing, huge improvements are continuing in the desktop arena as well. The
KDE and GNOME desktop environments continuously improve the Linux experience for casual users. Major efforts are underway to offer critical pieces of desktop components that are still not available in open source versions, including multimedia software and office productivity applications.
Note
Linus continues to maintain and improve the Linux kernel.
To get more detailed histories of Linux, I recommend visiting the LWN.net site.
LWN.net has kept a detailed Linux timeline from 1998 to the present day. For example, the 2003 timeline is available at http://lwn.net/Articles/
Timeline2003
.
Leveraging work done on UNIX and GNU projects helped to get Linux up and running quickly. The culture of sharing in the open source community and adoption of a wide array of tools for communicating on the Internet have helped Linux to move quickly through infancy and adolescence to become a mature operating system.
The simple commitment to share code is probably the single most powerful contributor to the growth of the open source software movement in general, and Linux in particular. That commitment has also encouraged involvement from the kind of people who are willing to contribute back to that community in all kinds of ways.
The following sections characterize Linux and the communities that support it.
For software developers, Linux provides a platform that lets them change the operating system as they like and get a wide range of help creating the applications they need. One of the watchdogs of the open source movement is the Open Source
Initiative ( www.opensource.org
). This is how the OSI Web site describes open source software:
The basic idea behind open source is very simple: When programmers can read, redistribute, and modify the source code for a piece of software, the software evolves. People improve it, people adapt it, people fix bugs. And this can happen at a speed that, if one is used to the slow pace of conventional software development, seems astonishing.
We in the open source community have learned that this rapid evolutionary process produces better software than the traditional closed model, in which only a very few programmers can see the source and everybody else must blindly use an opaque block of bits.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 17
Chapter 1
✦
Starting with Linux
17
While the primary goal of open source software is to make source code available, other goals are also defined by OSI in its Open Source Definition. Most of the following rules for acceptable open source licenses are to protect the freedom and integrity of the open source code:
✦
— An open source license can’t require a fee from anyone who resells the software.
✦
— The source code has to be included with the software and not be restricted from being redistributed.
✦
— The license must allow modification and redistribution of the code under the same terms.
✦
— The license may require that those who use the source code remove the original project’s name or version if they change the source code.
✦
— The license must allow all people to be equally eligible to use the source code.
✦
— The license can’t restrict a project from using the source code because it is commercial or because it is associated with a field of endeavor that the software provider doesn’t like.
✦
— No additional license should be needed to use and redistribute the software.
✦
— The license can’t restrict the source code to a particular software distribution.
✦
— The license can’t prevent someone from including the open source software on the same medium as non-open source software.
✦
— The license can’t restrict methods in which the source code can be redistributed.
Open source licenses used by software development projects must meet these criteria to be accepted as open source software by OSI. More than 40 different licenses are accepted by OSI to be used to label software as “OSI Certified Open Source
Software.” In addition to GPL, other popular OSI-approved licenses include:
✦
— The GNU Lesser General Public License (LGPL) allows people to redistribute certain software but not change its contents. This license is often used for distributing libraries that other application programs depend upon.
✦
— The Berkeley Software Distribution License allows redistribution of source code, with the requirement that the source code keep the BSD copyright notice and not use the names of contributors to endorse or promote derived software without written permission.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 18
18
Part I ✦
Linux First Steps
✦
— The MIT license is like the BSD license except that it doesn’t include the endorsement and promotion requirement.
✦
— The Mozilla license covers use and redistribution of source code associated with the Mozilla Web browser and related software. It is a much longer license than the others just mentioned because it contains more definitions of how contributors and those reusing the source code should behave.
This includes submitting a file of changes when submitting modifications and that those making their own additions to the code for redistribution should be aware of patent issues or other restrictions associated with their code.
The end result of open source code is software that has more flexibility to grow and fewer boundaries in how it can be used. Many believe that the fact that many people look over the source code for a project will result in higher-quality software for everyone. As open source advocate Eric S. Raymond says in an often-quoted line,
“Many eyes make all bugs shallow.”
Communities of professionals and enthusiasts have grown around Linux and its related open source projects. Many have shown themselves willing to devote their time, knowledge, and skills on public mailing lists, forums, Wikis, and other Internet venues (provided you ask politely and aren’t too annoying).
Linux User Groups (LUGs) have sprung up all over the world. Many LUGs sponsor
Linux installfests (where members help you install the Linux of your choice on your computer) or help nonprofit groups and schools use Linux on older computers that will no longer support the latest Microsoft Windows software. The LUG I’m a member of holds monthly meetings to give talks on Linux topics and has an active Web site, mailing list, and chat server where we can help each other with Linux questions that come up.
Free online bulletin board services have sprung up to get information on specific
Linux topics. Popular general Linux forums are available from www.LinuxQuestions.
org , www.LinuxForums.org
, and www.LinuxHelp.net
. Most of these sites are built with open source software (see www.e107.org
open source forum software).
and www.phpBB.com
for examples of
Communities also gather around specific software projects and Linux distributions.
www.Sourceforge.net
is home to thousands of open source software projects.
Go to the Sourceforge.net site and try keyword searches for topics that interest you (for example, image gallery or video editing). Each project provides links to project home pages, forums, and software download sites. There are always projects looking for people to help write code or documentation or just participate in discussions.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 19
Chapter 1
✦
Starting with Linux
19
You’ll find that most major Linux distributions have associated mailing lists and forums. You can go directly to the Web sites for Red Hat Fedora Linux ( www.redhat.
com/fedora ), Debian ( www.debian.com
), SUSE ( www.suse.com
), Gentoo ( www.
gentoo.org
), and others to learn how to participate in forums and contribute to those projects.
Some software projects have grown beyond the status of being simply a component of Linux or some other UNIX derivative. Some of these projects are sponsored and maintained by organizations that oversee multiple open source projects. This section introduces some of the most popular open source projects and organizations.
The Apache Software Foundation ( www.apache.org
) is not only the world’s most popular open source Web server software, it’s the most popular of all Web server software. Most Linux distributions that contain server software include Apache.
The Apache Software Foundation maintains the Apache Web (HTTP) server and about a dozen other projects, including SpamAssassin (for blocking and filtering e-mail spam), Apache Portals (to provide portal software), and a bunch of projects for producing modules to use with your Apache Web server.
The Internet Systems Consortium ( www.isc.org
) supports critical Internet infrastructure projects under open source licenses. Those projects include Bind (DNS server software), DHCP (to assign IP addresses and other information to Internet clients), INN (for creating Internet news servers), and OpenReg (a tool for managing delegation of domains in a shared registry).
The Free Software Foundation ( www.fsf.org) is the principal sponsor of the GNU
Project. Most of the UNIX commands and utilities included in Linux that were not closely associated with the kernel were produced under the umbrella of the GNU project.
The Mozilla ( www.mozilla.org
) project’s most well-known product is the very popular open source Web browser Mozilla Navigator, which was originally based on code released to the open source community from Netscape Communicator. Most other open source browsers incorporate Mozilla’s engine. The Mozilla project also offers related e-mail, composer, IRC Chat, and address book software. New projects include the Thunderbird e-mail and news client and Firefox Web browser.
The Sendmail ( www.sendmail.org
) Consortium maintains the sendmail mail transport agent, which is the world’s most popular software for transporting mail across the Internet.
There are, of course, many more open source projects and organizations that provide software included in various Linux distributions, but the ones discussed here will give you a good feel for the kind of organizations that produce open source software.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 20
20
Part I ✦
Linux First Steps
The unlikely rise in the popularity of Linux has led to rampant (and sometimes strange) speculation about all the terrible things it could lead to or, conversely, to almost manic declarations of how Linux will solve all the problems of the world.
I’ll try as best I can (with my own admitted bias toward Linux) to present facts to address beliefs about Linux and to combat some of the unrealistic fear, uncertainty, and doubt (FUD) being spread by those with a vested interest in seeing Linux not succeed.
Well, you can (and should) always worry about the security of any computer connected to the Internet. At the moment, however, you are probably less likely to get a virus from infected e-mail or untrusted Web sites with standard e-mail clients and
Web browsers that come with Linux systems than you would with those that come with the average Microsoft Windows system.
The most commonly cited warnings to back up that statement come in a report from the United States Computer Emergency Readiness Team (CERT) regarding a vulnerability in Microsoft Internet Explorer ( www.kb.cert.org/vuls/id/713878 ):
There are a number of significant vulnerabilities in technologies relating to the IE domain/zone security model, the DHTML object model, MIME type determination, and ActiveX. It is possible to reduce exposure to these vulnerabilities by using a different Web browser, especially when browsing untrusted sites. Such a decision may, however, reduce the functionality of sites that require IE-specific features such as DHTML, VBScript, and ActiveX. Note that using a different Web browser will not remove IE from a Windows system, and other programs may invoke IE, the WebBrowser ActiveX control, or the HTML rendering engine
(MSHTML).
—
US-CERT Vulnerability Note VU#713878
While the note also recommends keeping up with patches from Microsoft to reduce your risks, it seems that the only real solutions are to disable Active scripting and
ActiveX, use plain-text e-mail, and don’t visit sites you don’t trust with Internet
Explorer. In other words, use a browser that disables insecure features included in
Microsoft products.
This announcement apparently caused quite a run on the Mozilla.org site to download a Mozilla or Firefox browser and related e-mail client (described in Chapter 21 of this book). Versions of those software projects run on Windows and Mac OS X, as well as on Linux. Many believe that browsers such as Mozilla are inherently more secure because they don’t allow nonstandard Web features that might do such things as automatically download unrequested software without your knowledge.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 21
Chapter 1
✦
Starting with Linux
21
Of course, no matter what browser or e-mail client you are using, you need to follow good security practices (such as not opening attachments or downloading files you don’t trust). Also, as open source browsers and e-mail clients, such as those from Mozilla.org, become more popular, the number of possible machines to infect through those applications will make it more tempting to virus writers. (At the moment, most viruses and worms are created specifically to attack Microsoft software.)
In the United States, anyone can try to sue anyone for anything. That doesn’t mean that the people who bring lawsuits will win, but they can try. So far, the threat to individuals has not been substantial, but there have been some well-financed lawsuits against Linux providers. Those with litigation against Linux have gone primarily after big companies, such as IBM, Novell, and Red Hat Inc., and have made only vague threats regarding end users of Linux. Linus Torvalds himself is the rare individual who has been named in lawsuits.
The lawsuits getting the most press these days are the ones involving Santa Cruz
Operation (SCO). SCO is the current owner of the UNIX source code that passed from AT&T Bell Labs to UNIX System Laboratories to Univel (a lot of people don’t know that one) to Novell and eventually to the company formed by joining SCO and
Caldera Systems.
Although the particulars of the claims seem to change daily, SCO’s basic assertion in lawsuits against IBM and others is that Linux contains UNIX System V source code that is owned by SCO, so those who sell or use Linux owe licensing fees to SCO. To a layman (I am not a lawyer!), the assertions seem weak based on the fact that:
✦
There seems to be no original UNIX code in Linux. And, even if a small amount of code that could be proved to be owned by SCO had made it in there by mistake, that code could be easily dropped and rewritten.
✦
Concepts that created UNIX all seem to be in the public domain, with public specifications of UNIX interfaces blessed by AT&T itself in the form of published POSIX and System V Interface Definition standards.
✦
AT&T dropped a similar lawsuit in 1994 against BSD, which had actually started with UNIX source code but had rewritten it completely over the years.
✦
Exactly what SCO owns has been brought into question because Novell still claims some rights to the UNIX code it sold to SCO. (In fact, SCO doesn’t even own the UNIX trademark, which Novell gave away to the Open Group before it sold the source code to SCO. Attempts were underway in 2004 by SCO to trademark the name UNIX System Laboratories.)
06_579495 ch01.qxd 12/27/04 10:29 PM Page 22
22
Part I ✦
Linux First Steps
Responses to SCO’s lawsuits (which certainly hold more weight than any explanations I could offer) are available from Open Group ( www.opengroup.org
), OSDL
( www.osdl.org
), IBM ( ibm.com/linux ), and Red Hat ( www.redhat.com
). If you are interested in the paper trail relating SCO’s ownership of UNIX, I recommend the
Novell’s Unique Legal Rights page ( www.novell.com/licensing/indemnity/ legal.html
).
OSDL.org has prepared a legal defense fund to protect Linux end users and other
Linux litigants (including Linus and OSDL itself). You can read about this fund at
ODSL’s Linux Legal Defense Fund page ( www.osdl.org/about_osdl/legal/lldf
).
Few will argue that it is illegal for someone to copy a software company’s code and redistribute it without permission. However, the concept of being able to patent an idea that a company might incorporate in its code has become a major point of contention in recent years. Can someone patent the idea of clicking an icon to open a window?
Software companies are scrambling to file thousands of patents relating to how software is used. While those companies may never create products based on those patents, the restrictions those patents might place on other software companies or open source software development is a major issue.
The EuroLinux Alliance is a group dedicated to “protecting software freedom based on copyright, open standards, open competition, and open source software, such as Linux.” EuroLinux is filing a petition in the European Parliament and European
Council to warn about the dangers of software patents. To find out more, go to http://eurolinux.org
.
Particularly contentious legal issues surround audio and video software. In Red Hat
Linux 8, Red Hat Inc. removed support for MP3 and DVD players because of questions about licensing associated with those music and movie formats. Red Hat’s advice at the time was to download and install the players yourself for personal use. Red Hat didn’t want to distribute those players because companies owning patents related to certain audio and video encoders might ask Red Hat to pay licensing fees for distributing those players (see www.redhat.com/advice/ speaks_80mm.html
).
Check with an attorney about into any legal issues that concern you.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 23
Chapter 1
✦
Starting with Linux
23
Linux is extraordinarily scalable and runs on everything from handhelds to supercomputers. Features in the Linux 2.6 kernel have been particularly aimed at making the kernel easier to port to embedded Linux systems as well as large multiprocessor, enterprise-quality servers.
Linux doesn’t seem to be trouncing Microsoft, although the rhetoric from Microsoft has targeted Linux as a particular threat in the server area. Microsoft is still the most popular desktop operating system in the world, holding more than 90% of the desktop market, by most accounts.
Major inroads into the desktop market by Linux systems are expected to be slow in coming. However, the area where desktop Linux systems are making the greatest gains are in low-end, mass-market computers. For less than $300, you can buy a decent computer with Linspire Linux pre-installed from Wal-Mart, PC Clubs, or several other retailers. Because it is Linux, the system comes with a boatload of applications as well (not Microsoft Office, but OpenOffice.org instead). (Linspire is discussed in Chapter 15.)
So far, most of the market share that Linux has gained has been taken from other
UNIX systems, such as those from Sun Microsystems. Apache Web servers running on Linux are already considered the world’s most popular Web servers. With efforts underway from the likes of IBM, Oracle, Red Hat, and Novell, major pushes into the
Enterprise market are already taking place. But Linux is still some distance from crushing Microsoft.
If you are new to Linux and are concerned about support, there are several companies offering well-supported versions of Linux. Those include Red Hat Enterprise
Linux (from Red Hat Inc.) and SUSE Linux (from Novell, Inc.), as well as a number of other smaller players. In the corporate arena, add IBM to that list.
As noted earlier, there are also many community sites on the Internet that offer forums, mailing lists, and other venues for getting help if you get stuck.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 24
24
Part I ✦
Linux First Steps
It doesn’t hurt to be a geek if you want to fully explore all the potential of your
Linux system. However, with a good desktop Linux distribution, tremendous improvements over the past few years relating to ease of use and features have made it possible to do most things you would do on any Mac or Windows system without being a Linux expert.
Start with a Linux system that uses the KDE or GNOME desktop. Simple menus let you select word processors, Web browsers, games, and dozens of other applications you commonly use on other operating systems. In most cases, you’ll get along fine just using your mouse to work with windows, menus, and forms.
With Linux distributions that offer graphical tools for basic system administration
(such as configuring a printer or network connection), you can be led through most tasks you need to do. Fedora, Red Hat Enterprise Linux, and SUSE are good examples of Linux distributions that offer simplified administration tools. With a basic understanding of the Linux shell (see Chapter 2) and some help from a Linux forum, you should be able to troubleshoot almost anything that goes wrong.
Open source enthusiasts believe that better software can result from an open source software development model than from proprietary development models.
So in theory, any company creating software for its own use can save money by adding its software contributions with those of others to gain a much better end product for themselves.
Companies that want to make money selling software need to be more creative than they were in the old days. While you can sell the software you create that includes
GPL software, you must pass the source code of that software forward. Of course, others can then recompile that product, basically using your product without charge.
Here are a few ways that companies are dealing with that issue:
✦
— Red Hat sells its Red Hat Enterprise Linux products on a subscription basis. For a certain amount of money per year, you get binary code to run Linux (so you don’t have to compile it yourself), guaranteed support, tools for tracking the hardware and software on your computer, and access to the company’s knowledge base.
Although Red Hat’s Fedora project includes much of the same software and is also available in binary form, there are no guarantees associated with the software or future updates of that software. A small office or personal user might take a risk on Fedora (which is itself an excellent operating system), but a big company that’s running mission-critical applications will probably put down a few dollars for RHEL.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 25
Chapter 1
✦
Starting with Linux
25
✦
— Many open source projects accept donations from open source individuals or companies that use code from their projects. Amazingly, many open source projects support one or two developers and run exclusively on donations.
✦
— The concept of software bounties is a fascinating way for open source software companies to make money. Let’s say that you are using XYZ software package and you need a new feature right away. By paying a software bounty to the project itself, or to other software developers, you can have your needed improvements moved to the head of the queue. The software you pay for will remain covered by its open source license, but you will have the features you need, at probably a fraction of the cost of building the project from scratch.
✦
— Many open source projects have online stores where you can buy boxed sets (some people still like physical CDs and hard copies of documentation) and a variety of mugs, T-shirts, mouse pads, and other items. If you really love a project, for goodness sake, buy a T-shirt!
This is in no way an exhaustive list because more creative ways are being invented every day to support those who create open source software. Remember that many people have become contributors to and maintainers of open source software because they needed or wanted the software themselves. The contributions they make for free are worth the return they get from others who do the same.
Although different Linux systems will add different logos, choose some different software components to include, and have different ways of installing and configuring Linux, most people who become used to Linux can move pretty easily from one
Linux to another. There are a few reasons for this.
✦
— There is an effort called the Linux Standard Base
( www.linuxbase.org
) to which most major Linux systems subscribe. The
Linux Standard Base Specification (available from this site) has as one of its primary goals to ensure that applications written for one Linux system will work on other systems. To that end, the LSB will define what libraries need to be available, how software packages can be formatted, commands and utilities that must be available, and, to some extent, how the file system should be arranged. In other words, you can rely on many components of Linux being in the same place on LSB-certified Linux systems.
✦
Many Linux distributions include the same open source projects. So, for example, the most basic command and configuration files for an Apache Web server, Samba file/print server, and sendmail mail server will be the same whether you use Red Hat, Debian, or many other
Linux systems. And although they can change backgrounds, colors, and other elements of your desktop, most of the ways of navigating a KDE or GNOME desktop stay the same, regardless of which Linux you use.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 26
26
Part I ✦
Linux First Steps
✦
— Although you can put different pretty faces on it, once you open a shell command-line interpreter (such as bash or sh) in Linux, most experienced Linux or UNIX users find it pretty easy to get around on most any
Linux system. For that reason, I recommend that if you are serious about using
Linux, you take some time to try the shell (as described in Chapter 2). Additionally, Chapters 23 through 26 focus on command-line and configuration-file interfaces for setting up servers because learning those ways of configuring servers will make your skills most portable across different Linux systems.
Figure 1-1 shows the penguin logo that Linus Torvalds approved as the official Linux mascot. His name is Tux. Use of this logo is freely available, and you find it everywhere on Linux Web sites, magazines, and other Linux venues. (I used it in my book
Linux Toys
and Linuxtoys.net Web site, for example.)
Tux was created by Larry Ewing. Different versions of Tux are available from his
Web site ( www.isc.tamu.edu/~lewing/linux ). Find out more about Tux from the Linux Online Logos and Mascots page ( www.linux.org/info/logos.html
).
Figure 1-1:
Tux, a gentle and pleasant penguin, is the official Linux mascot.
Although I’ve gone on a bit about Linux history and what it does, the primary goal of this book is to get you using it. To that end, I’d like to describe some things that might help you get started with Linux.
06_579495 ch01.qxd 12/27/04 10:29 PM Page 27
Chapter 1
✦
Starting with Linux
27
While Linux will run great on many low-end computers (even some old 486s and early Pentiums), if you are completely new to Linux, I recommend that you start with a PC that has a little more muscle. Here’s why:
✦
Full-blown Linux operating systems with complete GNOME or KDE desktop environments perform poorly on slow CPUs and less than the recommended amount of RAM.
✦
You can create streamlined graphical Linux installations that will fit on small hard disks (as small as 100MB) and run fairly well on slow processors. However, putting together such a system requires some knowledge of which software packages to select and often requires some additional configuration.
If you are starting with a Pentium II, 400MHz, your desktop will run slowly in default
KDE or GNOME configurations with less than 128MB of RAM. A simpler desktop system, with just X and a window manager, will work but won’t give you the full flavor of a Linux desktop. (See Chapter 3 for information about different desktop choices and features.)
The good news is that, as mentioned earlier, cheap computers that you can buy from
Wal-Mart or other retailers start at less than $300. Those systems will perform better than most PCs you have laying around that are more than a few years old and will come with Linux (usually Linspire) pre-installed. The bottom line is that the less you know about Linux, the more you should try to have computer hardware that is up to spec to have a pleasant experience.
If you already have a Linux system sitting in front of you, Chapters 2 through 6 will walk you through the Linux shell, using the desktop, and some basic system administration. If you don’t have a Linux system running on your computer yet, you have a couple of choices:
✦
— If you are reluctant to mess with the contents of your computer, a bootable Linux enables you to run Linux directly from a removable medium (DVD, CD, or even a floppy disk in some cases). You’ll be able to try
Linux without even touching the contents of your hard disk.
✦
— If you have available disk space that’s not already assigned to Windows or another system, you can install Linux on your hard disk and have a more permanent operating system. (Some Linux distributions, such as SUSE and Mandrake, let you resize your Windows hard disk to make room to install Linux.)
06_579495 ch01.qxd 12/27/04 10:29 PM Page 28
28
Part I ✦
Linux First Steps
Linux itself is just a kernel (like the engine of a car), so to use Linux you need to select a Linux distribution. Because the distribution you choose is so critical to your Linux experience, Part III of this book is entirely devoted to understanding, choosing, and installing the most popular Linux distributions. Several of these distributions are included with this book, along with several useful bootable Linux distributions. If you don’t already have a Linux system in front of you, refer to
Chapter 7 to get started getting the Linux you want.
Linux is the most popular representation of the open source software model today and reflects a rich history of shared software development techniques that date back to the first UNIX systems of three decades ago. Today’s Linux computer systems form the backbone of many major computing centers around the world.
In recent years, Linux has become a great choice as a desktop system as well. You will find many open source applications available for any type of application you can imagine (word processing, music playing, e-mail, games, and so on). With its powerful networking and built-in security features, Linux can provide a much safer computing environment than other desktop computing systems.
Linux gives you the freedom to create the kind of computer system you need.
✦ ✦ ✦
07_579495 ch02.qxd 12/27/04 9:51 PM Page 29
B
efore icons and windows took over computer screens, you typed commands to run most computers. On UNIX systems, from which Linux was derived, the program used to interpret and manage commands was referred to as the shell.
No matter which Linux distribution you are using, you can always count on one thing being available to you: the shell.
It provides a way to run programs, work with file systems, compile computer code, operate a system, and manage the computer. Although the shell is less intuitive than common
GUIs (graphical user interfaces), most Linux experts consider the shell to be much more powerful than GUIs. Shells have been around a long time, and many advanced features have been built into them.
The Linux shell illustrated in this chapter is called the bash shell, which stands for Bourne Again SHell. The name is derived from the fact that bash is compatible with the first UNIX shell: the Bourne shell (represented by the sh command). Other popular shells include the C Shell (csh), which is popular among
BSD UNIX users, and the Korn Shell (ksh), which is popular among UNIX System V users. Linux also has a tcsh shell (a C shell look-alike) and an ash shell (another Bourne shell lookalike). Several different shells are introduced in this chapter.
Three major reasons for learning how to use the shell are:
✦
You will know how to get around any Linux or other UNIXlike system. For example, I can log in to my Red Hat Linux
MySQL server, my bootable floppy router/firewall, or my wife’s iMAC and explore and use any of those computer systems from a shell.
✦ ✦ ✦ ✦
In This Chapter
Understanding the
Linux shell
Using the Linux shell
Working with the
Linux file system
Using the vi text editor in Linux
✦ ✦ ✦ ✦
07_579495 ch02.qxd 12/27/04 9:51 PM Page 30
30
Part I ✦
Linux First Steps
✦
Special shell features enable you to gather data input and direct data output between commands and the Linux file system. To save on typing, you can find, edit, and repeat commands from your shell history. Many power users hardly touch a graphical interface, doing most of their work from a shell.
✦
You can gather commands into a file using programming constructs such as loops and case statements to quickly do complex operations that would be difficult to retype over and over. Programs consisting of commands that are stored and run from a file are referred to as
shell scripts.
Most Linux system administrators use shell scripts to automate tasks such as backing up data, monitoring log files, or checking system health. (See Chapter 27 for information on shell scripts.)
The shell is a command language interpreter. If you have used Microsoft operating systems, you’ll see that using a shell in Linux is similar to — but generally much more powerful than — the interpreter used to run commands in DOS. You can happily use Linux from a graphical desktop interface, but as you grow into Linux you will surely need to use the shell at some point to track down a problem or administer some features.
How to use the shell isn’t obvious at first, but with the right help you can quickly learn to avail yourself of many of the most important shell features. This chapter is your guide to working with the Linux system commands, processes, and file system from the shell. It describes the shell environment and helps you tailor it to your needs. It also explains how to use and move around the file system.
Several ways exist to get to a shell interface in Linux. Three of the most common are the shell prompt, Terminal window, and virtual terminal. They’re discussed in the following sections.
If your Linux system has no graphical user interface (or one that isn’t working at the moment), you will most likely see a shell prompt after you log in. Typing commands from the shell will probably be your primary means of using the Linux system.
The default prompt for a regular user is simply a dollar sign:
$
07_579495 ch02.qxd 12/27/04 9:51 PM Page 31
Chapter 2
✦
Running Commands from the Shell
31
The default prompt for the root user is a pound sign (also called a hash mark):
#
In most Linux systems, the
$ and
# prompts are preceded by your username, system name, and current directory name. For example, a login prompt for the user named jake on a computer named pine with
/tmp as the current directory would appear as
[[email protected] tmp]$
You can change the prompt to display any characters you like — you can use the current directory, the date, the local computer name, or any string of characters as your prompt, for example. To configure your prompt, see the “Setting Your Prompt” section later in this chapter.
Although a tremendous number of features are available with the shell, it’s easy to begin by just typing a few commands. Try some of the commands shown in the remainder of this section to become familiar with your current shell environment.
In the examples that follow, the $ and
# symbols indicate a prompt. The prompt is followed by the command that you type (and then you press Enter or Return, depending on your keyboard). The lines that follow show the output resulting from the command.
With the desktop GUI running, you can open a terminal emulator program (sometimes referred to as a Terminal window) to start a shell. Most Linux distributions make it easy for you to get to a shell from the GUI. Here are two common ways to launch a Terminal window from a Linux desktop:
✦
In the context menu that appears, look for New
Terminal, Terminal Window, Xterm, or some similar item and select it.
✦
Many Linux desktops include a panel at the bottom of the screen from which you can launch applications. For example, in Red Hat
Linux systems, you can select the Red Hat icon and then choose System
Tools
➪
Terminal to open a Terminal window.
In all cases, you should just be able to type a command as you would from a shell with no GUI. Different terminal emulators are available with Linux. One of the following is likely to be the default used with your Linux system:
07_579495 ch02.qxd 12/27/04 9:51 PM Page 32
32
Part I ✦
Linux First Steps
Emulator
xterm gnome-terminal kterm
Description
A common terminal emulator for the X Window System (in fact, I’ve never seen an X Window System that didn’t include xterm). Although it doesn’t provide menus or many special features, it is available with most Linux distributions that support a GUI.
The default Terminal emulator window that comes with GNOME. It consumes more system resources than xterm does, and it has useful menus for cutting and pasting, opening new Terminal tabs or windows, and setting terminal profiles.
The kterm terminal emulator that comes with the KDE desktop environment. With kterm, you can display multilanguage text encoding and text in different colors.
If you don’t like the terminal emulator you get by default, type a command name from the Emulator column to try out one of those instead.
Many Linux systems, including Fedora and Red Hat Enterprise Linux, start multiple virtual terminals running on the computer. Virtual terminals are a way to have multiple shells open at once without having a GUI running.
You can switch between virtual terminals much the same way that you would switch between workspaces on a GUI. Press Ctrl+Alt+F1 (or F2, F3, F4, and so on up to F6 on Fedora and other Linux systems) to display one of six virtual terminals.
The next virtual workspace after the virtual terminals is where the GUI is, so if there are six virtual terminals, you can return to the GUI (if one is running) by pressing
Ctrl+Alt+F7. (For a system with four virtual terminals, you’d return to the GUI by pressing Ctrl+Alt+F5.)
In most Linux systems, your default shell is the bash shell. To find out what your current login shell is, type the following command:
$
echo $SHELL
/bin/bash
In this example, it’s the bash shell. There are many other shells, and you can activate a different one by simply typing the new shell’s command ( ksh , tcsh , csh , sh , bash , and so forth) from the current shell.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 33
Chapter 2
✦
Running Commands from the Shell
33
Note
Most full Linux systems include all the shells described in this section. However, some smaller Linux distributions may include only one or two shells. The best way to find out if a particular shell is available is to type the command and see if the shell starts.
You might want to choose a different shell to use because:
✦
You are used to using UNIX System V systems (often ksh by default) or Sun
Microsystems and other Berkeley UNIX-based distributions (frequently csh by default), and you are more comfortable using default shells from those environments.
✦
You want to run shell scripts that were created for a particular shell environment, and you need to run the shell for which they were made so you can test or use those scripts.
✦
You might simply like features in one shell over those in another. For example, a member of my Linux Users Group prefers ksh over bash because he doesn’t like the way aliases are always set up with bash.
Although most Linux users have a preference for one shell or another, when you know how to use one shell, you can quickly learn any of the others by occasionally referring to the shell’s man page (for example, type
). Most people use bash just because they don’t have a particular reason for using a different shell.
In Chapter 4, you learn how to assign a different default shell for a user.
The following sections introduce several of the most common shells available with
Linux.
The name bash is an acronym for Bourne Again SHell, acknowledging the roots of bash coming from the Bourne shell ( sh command) created by Steve Bourne at
AT&T Bell Labs. Brian Fox of the Free Software foundation created bash, under the auspices of the GNU project. Development was later taken over by Chet Ramey at
Case Western Reserve University.
Bash includes features originally developed for sh and ksh shells in early UNIX systems as well as some csh features. Expect bash to be the default shell in whatever
Linux system you are using, with the exception of some specialized Linux systems
(such as those run on embedded devices or run from a floppy disk) that may require a smaller shell that needs less memory and entails fewer features. Most of the examples in this chapter are based on the bash shell.
Bash can be run in various compatibility modes so that it behaves like different shells. It can be run to behave as a Bourne shell (sh) or as a POSIX-compliant shell
( bash --posix ), for example, enabling it to read configuration files that are specific to those shells and run shell scripts written directly for those shells, with a greater chance of success.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 34
34
Part I ✦
Linux First Steps
All of the Linux distributions included with this book use bash as the default shell with the exception of some bootable Linux distributions, which use the ash shell instead.
The tcsh shell is the open source version of the C shell (csh). The csh shell was created by Bill Joy and used with most Berkeley UNIX systems (such as those produced by Sun Microsystems) as the default shell.
Many features of the original csh shell, such as command-line editing and its history mechanism, are included in tcsh as well as in other shells. Just as the sh command runs bash in sh compatibility mode, so does starting csh actually run the tcsh shell in csh compatibility mode.
The ash shell is a lightweight version of the Berkeley UNIX sh shell. It doesn’t include many of the sh shell’s basic features and is missing such features as command histories.
The ash shell is a good shell for embedded systems that have fewer system resources available. In Fedora Core 2, the ash shell is about one-sixth the size of bash.
The ksh shell was created by David Korn at AT&T Bell Labs and is the predecessor of the sh shell. It became the default and most commonly used shell with UNIX
System V systems. The open source version of ksh is available in many rpm-based systems (such as Fedora and Red Hat Enterprise Linux) as part of the pdksh package.
The zsh shell is another clone of the sh shell. It is POSIX-compliant (as is bash) but includes some different features, such as spell checking and a different approach to command editing. The first Mac OSX systems used zsh as the default shell, although now bash is used by default.
Once you have access to a shell in Linux, you can begin by typing some simple commands. The “Using the Shell in Linux” section later in this chapter provides more details about options, arguments, and environment variables. For the time being, the following sections will help you poke around the shell a bit.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 35
Chapter 2
✦
Running Commands from the Shell
35
Note
If you don’t like your default shell, simply type the name of the shell you want to try out temporarily. To change your shell permanently, use the usermod command.
For example, to change your shell to the csh shell for the user named chris, type the following as root user from a shell:
# usermod -s /bin/csh chris
When you log in to a Linux system, Linux views you as having a particular identity, which includes your username, group name, user ID, and group ID. Linux also keeps track of your login session: It knows when you logged in, how long you have been idle, and where you logged in from.
To find out information about your identity, use the id command as follows:
$
id
uid=501(chris) gid=105(sales) groups=105(sales),4(adm),7(lp)
In this example, the username is chris , which is represented by the numeric user
ID (uid) 501 . The primary group for chris is called sales , which has a group ID (gid) of 105 . Chris also belongs to other groups called adm (gid 4) and lp names and numbers represent the permissions that chris
(gid 7). These has to access computer resources. (Permissions are described in the “Understanding File Permissions” section later in this chapter.)
You can see information about your current login session by using the who command. In the following example, the -u time and the process ID and -H option says to add information about idle asks that a header be printed:
$
who -uH
NAME LINE TIME IDLE PID COMMENT chris tty1 Jan 13 20:57 . 2013
The output from this who command shows that the user chris is logged in on tty1
(which is the monitor connected to the computer) and his login session began at
20:57 on January 13. The IDLE time shows how long the shell has been open without any command being typed (the dot indicates that it is currently active). PID shows the process ID of the user’s login shell. COMMENT would show the name of the remote computer the user had logged in from, if that user had logged in from another computer on the network, or the name of the local X display if you were using a Terminal window (such as :0.0).
Associated with each shell is a location in the Linux file system known as the
current
or
working directory.
Each user has a directory that is identified as the user’s home directory. When you first log in to Linux, you begin with your home directory as the current directory.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 36
36
Part I ✦
Linux First Steps
When you request to open or save a file, your shell uses the current directory as the point of reference. Simply provide a filename when you save a file, and it is placed in the current directory. Alternatively, you can identify a file by its relation to the current directory (relative path), or you can ignore the current directory and identify a file by the full directory hierarchy that locates it (absolute path). The structure and use of the file system is described in detail later in this chapter.
To find out what your current directory is, type the pwd command:
$
pwd
/usr/bin
In this example, the current/working directory is /usr/bin . To find out the name of your home directory, type the echo command, followed by the
$HOME variable:
$
echo $HOME
/home/chris
Here, the home directory is /home/chris . To get back to your home directory, just type the change directory ( cd
) command. (Although cd followed by a directory name changes the current directory to the directory that you choose, simply typing cd with no directory name takes you to your home directory.)
$
cd
To list the contents of your home directory, either type the full path to your home directory, or use the ls command without a directory name. Using the
-a option to ls
-l enables you to view the hidden files (dot files) as well as all other files. With the option, you can see a long, detailed list of information on each file. (You can put multiple single-letter options together after a single dash, for example, -la .)
$
ls -la /home/chris
total 158 drwxrwxrwx 2 chris sales 4096 May 12 13:55 .
drwxr-xr-x 3 root root 4096 May 10 01:49 ..
-rw------- 1 chris sales 2204 May 18 21:30 .bash_history
-rw-r--r-- 1 chris sales 24 May 10 01:50 .bash_logout
-rw-r--r-- 1 chris sales 230 May 10 01:50 .bash_profile
-rw-r--r-- 1 chris sales 124 May 10 01:50 .bashrc
drw-r--r-- 1 chris sales 4096 May 10 01:50 .kde
-rw-rw-r-- 1 chris sales 149872 May 11 22:49 letter
^ ^ ^ ^ ^ ^ ^
col 1 col 2 col 3 col 4 col 5 col 6 col 7
Displaying a long list ( -l option) of the contents of your home directory shows you more about file sizes and directories. The total line shows the total amount of disk space used by the files in the list (158 kilobytes in this example). Directories such as the current directory (
.
) and the parent directory (
..
) — the directory above
07_579495 ch02.qxd 12/27/04 9:51 PM Page 37
Chapter 2
✦
Running Commands from the Shell
37 the current directory — are noted as directories by the letter d each entry (each directory begins with a d at the beginning of and each file begins with a
-
). The file and directory names are shown in column 7. In this example, a dot ( .
) represents
/home/chris and two dots (
..
) represents
/home
. Most of the files in this example are dot ( .
) files that are used to store GUI properties ( .kde
erties (
.bash
directory) or shell propfiles). The only nondot file in this list is the one named letter
.
Column 3 shows the directory or file owner. The
/home directory is owned by root, and everything else is owned by the user chris, who belongs to the sales group
(groups are listed in column 4).
Note
In addition to the d or
-
, column 1 on each line contains the permissions set for that file or directory. (Permissions and configuring shell property files are described later in this chapter.) Other information in the listing includes the number of links to the item (column 2), the size of each file in bytes (column 5), and the date and time each file was most recently modified (column 6).
The number of characters shown for a directory (4,096 bytes in these examples) reflects the size of the file containing information about the directory. While this number can grow above 4,096 bytes for a directory that contains a lot of files, this number doesn’t reflect the size of files contained in that directory.
In addition to being a multiuser operating system, Linux is also a multitasking system.
Multitasking
means that many programs can be running at the same time. An instance of a running program is referred to as a
process.
Linux provides tools for listing running processes, monitoring system usage, and stopping (or killing) processes when necessary.
The most common utility for checking running processes is the ps command. Use it to see which programs are running, the resources they are using, and who is running them. Here’s an example of the ps command:
$
ps -au
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 2146 0.0 0.8 1908 1100 ttyp0 S 14:50 0:00 login -- jake jake 2147 0.0 0.7 1836 1020 ttyp0 S 14:50 0:00 -bash jake 2310 0.0 0.7 2592 912 ttyp0 R 18:22 0:00 ps -au
In this example, the -a option asks to show processes of all users who are associated with your current terminal, and the
-u option asks that usernames be shown, as well as other information such as the time the process started and memory and
CPU usage. The concept of terminal comes from the old days, when people worked exclusively from character terminals, so a terminal typically represented a single person at a single screen. Now you can have many “terminals” on one screen by opening multiple Terminal windows.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 38
38
Part I ✦
Linux First Steps
On this shell session, there isn’t much happening. The first process shows that the user named jake logged in to the login process (which is controlled by the root user). The next process shows that jake ps -au is using a bash shell and has just run the command. The terminal device ttyp0 is being used for the login session.
The STAT column represents the state of the process, with running process and
S representing a sleeping process.
R indicating a currently
The
USER column shows the name of the user who started the process. Each process is represented by a unique ID number referred to as a process ID (PID). (You can use the PID if you ever need to kill a runaway process.) The
%CPU and
%MEM columns show the percentage of the processor and random access memory, respectively, that the process is consuming.
VSZ
(virtual set size) shows the size of the image process
(in kilobytes), and RSS
START
(resident set size) shows the size of the program in memory.
shows the time the process began running, and
TIME shows the cumulative system time used. (Many commands consume very little CPU time, as is reflected by 0:00 for processes that haven’t even used a whole second of CPU time.)
Many processes running on a computer are not associated with a terminal. A normal
Linux system has many processes running in the background. Background system processes perform such tasks as logging system activity or listening for data coming in from the network. They are often started when Linux boots up and run continuously until it shuts down. To page through all the processes running on your Linux system, add the pipe ( | ) and the less command to ps –aux , like this:
$
ps -aux | less
A pipe lets you direct the output of one command to be the input of the next command, so in this example, the output of the ps directed to the less command (a list of processes) is command, which lets you page through that information. Use the spacebar to page through and type
to end the list. You can also use the arrow keys to move one line at a time through the output.
To exit the shell when you are done, either type
or press Ctrl+D. If you are exiting from your login shell (the shell that started when you first logged in), type
to exit the shell.
You’ve just seen a few commands that can help you quickly familiarize yourself with your Linux system. There are hundreds of other commands that you can try.
You’ll find many in the /bin and /usr/bin directories, and you can use ls to see a directory’s command list: ls /bin
, for example, results in a list of commands in the /bin . Then use the man command (for example, man hostname ) to see what each command does. There are also administrative commands in
/sbin or
/usr/sbin directories.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 39
Chapter 2
✦
Running Commands from the Shell
39
When you type a command in a shell, you can include other characters that change or add to how the command works. You can also set sequences of command or redirect input and output of a command by using control characters such as pipes
( | ), semicolons ( ; ), and greater-than ( > ) and less-than ( < ) signs.
Note
In addition to the command itself, these are some of the other items that you can type on a shell command line:
✦
— Most commands have one or more options you can add to change their behavior. Options typically consist of a single letter preceded by a dash.
You can also often combine several options after a single dash. For example, the command ls -la lists the contents of the current directory. The -l for a detailed (long) list of information, and the -a asks asks that files beginning with a dot ( .
) also be listed. When a single option consists of a word, it is usually preceded by a double dash ( -). For example, to use the help option on many commands, you enter --help on the command line.
You can use the
--help option with most commands to see the options and arguments that they support. For example, hostname --help
.
Tip
✦
— Many commands also accept arguments after certain options are entered or at the end of the entire command line. An argument is an extra piece of information, such as a filename, that can be used by the command.
For example, cat /etc/passwd displays the contents of the /etc/passwd file on your screen. In this case, /etc/passwd is the argument.
✦
— The shell itself stores information that may be useful to the user’s shell session in what are called
environment variables.
Examples of environment variables include $SHELL (which identifies the shell you are using), $PS1 (which defines your shell prompt), and $MAIL (which identifies the location of your mailbox). See the “Using Shell Environment
Variables” section later in this chapter for more information.
You can check your environment variables at any time. Type declare to list the current environment variables. Or you can type
echo $
VALUE
, where VALUE is replaced by the name of a particular environment variable you want to list.
✦
— These are characters that have special meaning to the shell. They can be used to direct the output of a command to a file ( > ), pipe the output to another command ( | ), and run a command in the background
( & ), to name a few. Metacharacters are discussed later in this chapter.
To save you some typing, there are shell features that store commands you want to reuse, recall previous commands, and edit commands. You can create aliases that enable you to type a short command to run a longer one. The shell stores previously entered commands in a history list, which you can display and from which you can recall commands. You’ll see how this works a little later in the chapter.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 40
40
Part I ✦
Linux First Steps
Unless you specifically change to another shell, the bash shell is the one you use with most Linux systems. The bash shell contains most of the powerful features available in other shells. Although the description in this chapter steps you through many bash shell features, you can learn more about the bash shell by typing man bash , and the sidebar “Getting Help Using the Shell” shows you a few other ways to learn about using the shell.
If you know the directory that contains the command you want to run, one way to run it is to type the full path to that command. For example, you run the date command from the /bin directory by typing
$
/bin/date
Of course, this can be inconvenient, especially if the command resides in a directory with a long path name. The better way is to have commands stored in well-known directories, and then add those directories to your shell’s
PATH environment variable. The path consists of a list of directories that are checked sequentially for the commands you enter. To see your current path, type the following:
$ echo $PATH
/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin:/home/chris/bin
The results show the default path for a regular Linux user. Directories in the path list are separated by colons. Most user commands that come with Linux are stored in the /bin , /usr/bin , or /usr/local/bin directories. Although many graphical commands (that are used with GUIs) are contained in
/usr/bin
, there are some special X commands that are in /usr/bin/X11
The last directory shown is the bin and /usr/X11R6/bin directories.
directory in the user’s home directory.
Tip
If you want to add your own commands or shell scripts, place them in the bin directory in your home directory (such as
/home/chris/bin for the user named chris). This directory is automatically added to your path. So as long as you add the command to your bin with execute permission (described in the “Understanding
File Permissions” section later in this chapter), you can immediately begin using the command by simply typing the command name at your shell prompt.
If you are the root user, directories containing administrative commands are typically in your path. These directories include
/sbin and
/usr/sbin
.
The path directory order is important. Directories are checked from left to right.
So, in this example, if there is a command called foo
/usr/bin directories, the one in
/bin located in both the is executed. To have the other
/bin foo and command run, you either type the full path to the command or change your PATH
(Changing your
PATH variable.
and adding directories to it are described later in this chapter.)
07_579495 ch02.qxd 12/27/04 9:51 PM Page 41
Chapter 2
✦
Running Commands from the Shell
41
Not all the commands that you run are located in directories in your PATH variable.
Some commands are built into the shell. Other commands can be overridden by creating aliases that define any commands and options that you want the command to run. There are also ways of defining a function that consists of a stored series of commands. Here is the order in which the shell checks for the commands you type:
— Names set by the alias command that represent a particular command and a set of options. (Type
to see what aliases are set.) Often, aliases enable you to define a short name for a long, complicated command.
— Words that are reserved by the shell for special use.
Many of these are words that you would use in programming-type functions, such as do , while , case , and else .
— A set of commands that are executed together within the current shell.
— A command that is built into the shell. As a result, there is no representation of the command in the file system. Some of the most common commands you will use are shell built-in commands, such as cd directories), echo (to echo text to the screen), exit
(to change
(to exit from a shell), fg
(to bring a command running in the background to the foreground), history
(to see a list of commands that were previously run), pwd (to list the present working directory), set of a command).
(to set shell options), and type (to show the location
— This is a command that is stored in and executed from the computer’s file system. (These are the commands that are indicated by the value of the PATH variable.)
To find out where a particular command is taken from, you can use the type mand. (If you are using a shell other than bash, use the which comcommand instead.)
For example, to find out where the bash shell command is located, type the following:
$
type bash
bash is /bin/bash
Tip
Try these few words with the type command to see other locations of commands: which , case , and return . If a command resides in several locations, you can add the
-a option to have all the known locations of the command printed.
Sometimes you run a command and receive an error message that the command was not found or that permission to run the command was denied. In the first case, check that you spelled the command correctly and that it is located in your
PATH variable. In the second case, the command may be in the
PATH variable but may not be executable. Adding execute permissions to a command is described later in this chapter.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 42
42
Part I ✦
Linux First Steps
It’s annoying, after typing a long or complex command line, to learn that you mistyped something. Fortunately, some shell features let you recall previous command lines, edit those lines, or complete a partially typed command line.
The
shell history
is a list of the commands that you have entered before. Using the history command in a bash shell, you can view your previous commands. Then, using various shell features, you can recall individual command lines from that list and change them however you please.
The rest of this section describes how to do command-line editing, how to complete parts of command lines, and how to recall and work with the history list.
If you type something wrong on a command line, the bash shell ensures that you don’t have to delete the entire line and start over. Likewise, you can recall a previous command line and change the elements to make a new command.
When you first start using the shell, it can be intimidating. All you see is a prompt. How do you know which commands are available, which options they use, or how to use advanced features? Fortunately, lots of help is available. Here are some places you can look to supplement what you learn in this chapter:
✦
Check the
PATH
— Type echo $PATH. You see a list of the directories containing commands that are immediately accessible to you. Listing the contents of those directories displays most standard Linux commands.
✦
Use the help command — Some commands are built into the shell, so they do not appear in a directory. The help command lists those commands and shows options available with each of them. (Type help | less to page through the list.) For help with a particular built-in command, type help command, replacing command with the name that interests you. The help command only works with the bash shell.
✦
Use
--help with the command — Many commands include a
--help option that you can use to get information about how the command is used. For example, type
date --help | less. The output shows not only options, but also time formats you can use with the date command.
✦
Use the man command — To learn more about a particular command, type man
command. (Replace command with the command name you want.) A description of the command and its options appears on the screen.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 43
Chapter 2
✦
Running Commands from the Shell
43
Tip
By default, the bash shell uses command-line editing that is based on the emacs text editor. (Type
to read about it, if you care to.) If you are familiar with emacs, you probably already know most of the keystrokes described here.
If you prefer the vi command for editing shell command lines, you can easily make that happen. Add the line set -o vi to the
.bashrc
can use vi file in your home directory. The next time you open a shell, you commands (as described in the tutorial later in this chapter) to edit your command lines.
To do the editing, you can use a combination of control keys, meta keys, and arrow keys. For example, Ctrl+F means to hold the Ctrl key and type F. Alt+F means to hold the Alt key and type F. (Instead of the Alt key, your keyboard may use a Meta key or the Esc key. On a Windows keyboard, you can use the Windows key.)
To try out a bit of command-line editing, type the following:
$
ls /usr/bin | sort -f | less
This command lists the contents of the
/usr/bin directory, sorts the contents in alphabetical order (regardless of case), and pipes the output to less . The less command displays the first page of output, after which you can go through the rest of the output a line (press Enter) or a page (press spacebar) at a time (press Q when you are done). Now, suppose you want to change
/usr/bin to
/bin
. You can use the following steps to change the command:
Press Ctrl+A. This moves the cursor to the beginning of the command line.
Press Ctrl+F or the right arrow (
→
) key. Repeat this command a few times to position the cursor under the first slash (/).
Press Ctrl+D. Type this command four times to delete /usr .
Press Enter. This executes the command line.
As you edit a command line, at any point you can type regular characters to add those characters to the command line. The characters appear at the location of your cursor. You can use right (
→
) and left (
←
) arrows to move the cursor from one end to the other on the command line. You can also press the up (
↑
) and down (
↓
) arrow keys to step through previous commands in the history list to select a command line for editing. (See the discussion on command recall for details on how to recall commands from the history list.)
There are many keystrokes you can use to edit your command lines. Table 2-1 lists the keystrokes that you can use to move around the command line.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 44
44
Part I ✦
Linux First Steps
Keystroke
Ctrl+F
Ctrl+B
Alt+F
Alt+B
Ctrl+A
Ctrl+E
Ctrl+L
Table 2-1
Full Name
Character forward
Character backward
Word forward
Word backward
Beginning of line
End of line
Clear screen
Meaning
Go forward one character.
Go backward one character.
Go forward one word.
Go backward one word.
Go to the beginning of the current line.
Go to the end of the line.
Clear screen and leave line at the top of the screen.
The keystrokes in Table 2-2 can be used to edit command lines.
Keystroke
Ctrl+D
Backspace or Rubout
Ctrl+T
Alt+T
Alt+U
Alt+L
Alt+C
Ctrl+V
Table 2-2
Full Name
Delete current
Delete previous
Transpose character
Transpose words
Uppercase word
Lowercase word
Capitalize word
Insert special character
Meaning
Delete the current character.
Delete the previous character.
Switch positions of current and previous characters.
Switch positions of current and previous characters.
Change the current word to uppercase.
Change the current word to lowercase.
Change the current word to an initial capital.
Add a special character. For example, to add a Tab character, press Ctrl+V+Tab.
Use the keystrokes in Table 2-3 to cut and paste text on a command line.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 45
Chapter 2
✦
Running Commands from the Shell
45
Table 2-3
Keystroke
Ctrl+K
Ctrl+U
Ctrl+W
Alt+D
Ctrl+Y
Alt+Y
Ctrl+C
Full Name
Cut end of line
Cut beginning of line
Cut previous word
Cut next word
Paste recent text
Paste earlier text
Delete whole line
Meaning
Cut text to the end of the line.
Cut text to the beginning of the line.
Cut the word located behind the cursor.
Cut the word following the cursor.
Paste most recently cut text.
Rotate back to previously cut text and paste it.
Delete the entire line.
To save you a few keystrokes, the bash shell offers several different ways of completing partially typed values. To attempt to complete a value, type the first few characters, and then press Tab. Here are some of the values you can type partially:
✦
— If the text begins with a dollar sign ( $ ), the shell completes the text with an environment variable from the current shell.
✦
— If the text begins with a tilde (
~
), the shell completes the text with a username.
✦
— If the text begins with regular characters, the shell tries to complete the text with a command, alias, or function name.
✦
— If the text begins with an at ( @ ) sign, the shell completes the text with a host name taken from the
/etc/hosts file.
Tip
To add host names from an additional file, you can set the
HOSTFILE variable to the name of that file. The file must be in the same format as
/etc/hosts
.
Here are a few examples of command completion. (When you see <Tab> , it means to press the Tab key on your keyboard.) Type the following:
$
echo
$OS<Tab>
$
cd ~ro<Tab>
$
fing<Tab>
$
mail [email protected]<Tab>
07_579495 ch02.qxd 12/27/04 9:51 PM Page 46
46
Part I ✦
Linux First Steps
The first example causes $OS to expand to the $OSTYPE variable. In the next example,
~ro expands to the root user’s home directory (
~root/
). Next, fing expands to the finger command. Finally, the address of name localhost
.
[email protected] expands to computer
Of course, there will be times when there are several possible completions for the string of characters you have entered. In that case, you can check the possible ways text can be expanded by pressing Esc+? (or by pressing Tab twice) at the point where you want to do completion. This shows the result you would get if you checked for possible completions on
$P
:
$
echo $P<Esc+?>
$PATH $PPID $PS1 $PS2 $PS4 $PWD
$ echo $P
In this case, there are six possible variables that begin with $P . After possibilities are displayed, the original command line returns, ready for you to complete it as you choose.
If text you want to complete is not preceded by a $ , ~ , or @ , you can still try to complete the text with a variable, username, or host name.
Press Key
Combination
Alt+~
Alt+$
Alt+!
Ctrl+X+/
Ctrl+X+$
Ctrl+X+!
To
Complete the text before this point as a username.
Complete the text before this point as a variable.
Complete the text before this point as a host name.
Complete the text before this point as a command name (alias, reserved word, shell function, shell built-in command, and filenames are checked in that order). In other words, complete this key sequence with a command that you previously ran.
List possible username text completions.
List possible environment variable completions.
List possible host name completions.
List possible command name completions.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 47
Chapter 2
✦
Running Commands from the Shell
47
After you type a command line, that entire command line is saved in your shell’s history list. The list is stored in a history file, from which any command can be recalled to run again. After it is recalled, you can modify the command line, as described earlier.
To view your history list, use the history command. Type the command without options or followed by a number to list that many of the most recent commands.
For example:
$
history 8
382 date
383 ls /usr/bin | sort -a | more
384 man sort
385 cd /usr/local/bin
386 man more
387 useradd -m /home/chris -u 101 chris
388 passwd chris
389 history 8
A number precedes each command line in the list. There are several ways to run a command immediately from this list, including:
✦
!n
— Run command number. Replace the n with the number of the command line, and that line is run. For example, here’s how to repeat the date command shown as command number 382 in the preceding history listing:
$ !382
date
Thu May 13 21:30:06 PDT 2004
✦
!!
— Run previous command. Runs the previous command line. Here’s how you’d immediately run that same date command:
$ !!
date
Thu May 13 21:30:39 PDT 2004
✦
!?string?
— Run command containing string. This runs the most recent command that contains a particular
string
of characters. For example, you can run the date as follows: command again by just searching for part of that command line
$ !?dat?
date
Wed Oct 13 21:32:41 PDT 2004
07_579495 ch02.qxd 12/27/04 9:51 PM Page 48
48
Part I ✦
Linux First Steps
Instead of just running a history command line immediately, you can recall a particular line and edit it. You can use the following keys or key combinations to do that:
Key(s)
Arrow Keys
(
↑ and
↓
)
Ctrl+R
Ctrl+S
Alt+P
Alt+N
Alt+<
Alt+>
Function Name
Step
Reverse Incremental Search
Forward Incremental Search
Reverse Search
Forward Search
Beginning of History List
End of History List
Description
Press the up and down arrow keys to step through each command line in your history list to arrive at the one you want. (Ctrl+P and
Ctrl+N do the same functions, respectively.)
After you press these keys, you enter a search string to do a reverse search. As you type the string, a matching command line appears that you can run or edit.
Same as the preceding function but for forward search.
After you press these keys, you enter a string to do a reverse search. Type a string and press
Enter to see the most recent command line that includes that string.
Same as the preceding function but for forward search.
Brings you to the first entry of the history list.
Brings you to the last entry of the history list.
Another way to work with your history list is to use the fc command. Type
followed by a history line number, and that command line is opened in a text editor.
Make the changes that you want. When you exit the editor, the command runs. You can also give a range of line numbers (for example, fc 100 105
). All the commands open in your text editor, and then run one after the other when you exit the editor.
The history list is stored in the .bash_history
file in your home directory. Up to
1,000 history commands are stored for you by default.
A truly powerful feature of the shell is the capability to redirect the input and output of commands to and from other commands and files. To allow commands to be strung together, the shell uses metacharacters. As noted earlier, a metacharacter is a typed character that has special meaning to the shell for connecting commands or requesting expansion.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 49
Chapter 2
✦
Running Commands from the Shell
49
The pipe ( | ) metacharacter connects the output from one command to the input of another command. This lets you have one command work on some data and then have the next command deal with the results. Here is an example of a command line that includes pipes:
$
cat /etc/password | sort | less
This command lists the contents of the /etc/password the sort command. The sort file and pipes the output to command takes the usernames that begin each line of the /etc/password less file, sorts them alphabetically, and pipes the output to the command (to page through the output).
Pipes are an excellent illustration of how UNIX, the predecessor of Linux, was created as an operating system made up of building blocks. A standard practice in UNIX was to connect utilities in different ways to get different jobs done. For example, before the days of graphical word processors, users created plain-text files that included macros to indicate formatting. To see how the document really appeared, they would use a command such as the following:
$ gunzip < /usr/share/man/man1/grep.1.gz | nroff -c -man | less
In this example, the contents of the grep man page ( grep.1.gz
) are directed to the gunzip command to be unzipped. The output from gunzip is piped to the nroff command to format the man page using the manual macro ( -man ). The output is piped to the less command to display the output. Because the file being displayed is in plain text, you could have substituted any number of options to work with the text before displaying it. You could sort the contents, change or delete some of the content, or bring in text from other documents. The key is that, instead of all those features being in one program, you get results from piping and redirecting input and output between multiple commands.
Sometimes you may want a sequence of commands to run, with one command completing before the next command begins. You can do this by typing several commands on the same command line and separating them with semicolons ( ; ):
$ date ; troff -me verylargedocument | lpr ; date
In this example, I was formatting a huge document and wanted to know how long it would take. The first command ( date ) showed the date and time before the formatting started. The troff command formatted the document and then piped the output to the printer. When the formatting was done, the date and time was printed again (so I knew how long the troff command took to complete).
07_579495 ch02.qxd 12/27/04 9:51 PM Page 50
50
Part I ✦
Linux First Steps
Some commands can take a while to complete. Sometimes you may not want to tie up your shell waiting for a command to finish. In those cases, you can have the commands run in the background by using the ampersand ( & ).
Text formatting commands (such as nroff and troff , described earlier) are examples of commands that are often run in the background to format a large document.
You also might want to create your own shell scripts that run in the background to check continuously for certain events to occur, such as the hard disk filling up or particular users logging in.
Here is an example of a command being run in the background:
$ troff -me verylargedocument | lpr &
Other ways to manage background and foreground processes are described in the
“Managing Background and Foreground Processes” section later in this chapter.
With command substitution, you can have the output of a command interpreted by the shell instead of by the command itself. In this way, you can have the standard output of a command become an argument for another command. The two forms of command substitution are $(command) and `command` (backslashes, not single quotes).
The command in this case can include options, metacharacters, and arguments.
Here is an example of using command substitution:
$
vi $(find /home | grep xyzzy)
In this example, the command substitution is done before the vi
First, the find command starts at the /home command is run.
directory and prints out all files and directories below that point in the file system. The output is piped to the grep command, which filters out all files except for those that include the string xyzzy . Finally, the vi command opens all filenames for editing (one at a time) that include xyzzy .
This particular example is useful if you want to edit a file for which you know the name but not the location. As long as the string is uncommon, you can find and open every instance of a filename existing beneath a point you choose in the file system. (In other words, don’t use grep a from the root file system or you’ll match and try to edit several thousand files.)
There may be times when you want to pass arithmetic results to a command. There are two forms you can use to expand an arithmetic expression and pass it to the shell: $[expression] or $(expression) . Here is an example:
07_579495 ch02.qxd 12/27/04 9:51 PM Page 51
Chapter 2
✦
Running Commands from the Shell
51
$
echo “I am $[2005 - 1957] years old.”
I am 48 years old.
The shell interprets the arithmetic expression first (
2005 - 1957
) and then passes that information to the echo command. The the results of the arithmetic (
48
) inserted.
echo command displays the text, with
Here’s an example of the other form:
$
echo “There are $(ls | wc -w) files in this directory.”
There are 14 files in this directory.
This lists the contents of the current directory ( ls ) and runs the word count command to count the number of files found ( wc -w
). The resulting number
(14 in this case) is echoed back with the rest of the sentence shown.
Environment variables that store information within the shell can be expanded using the dollar sign ( $ ) metacharacter. When you expand an environment variable on a command line, the value of the variable is printed instead of the variable name itself, as follows:
$
ls -l $BASH
-rwxr-xr-x 1 root root 625516 Dec 5 11:13 /bin/bash
Using
$BASH as an argument to ls -l causes a long listing of the bash command to be printed. The following section discusses shell environment variables.
You can tune your shell to help you work more efficiently. Your prompt can provide pertinent information each time you press Enter. You can set aliases to save your keystrokes and permanently set environment variables to suit your needs. To make each change occur when you start a shell, add this information to your shell configuration files.
Several configuration files support how your shell behaves. Some of the files are executed for every user and every shell, whereas others are specific to the user who creates the configuration file. Here are the files that are of interest to anyone using the bash shell in Linux:
07_579495 ch02.qxd 12/27/04 9:51 PM Page 52
52
Part I ✦
Linux First Steps
File
/etc/profile
/etc/bashrc
~/.bash_profile
~/.bashrc
~/.bash_logout
Description
Sets up user environment information for every user. It is executed when you first log in. This file provides values for your path, as well as setting environment variables for such things as the location of your mailbox and the size of your history files. Finally,
/etc/profile gathers shell settings from configuration files in the
/etc/profile.d
directory.
Executes for every user who runs the bash shell each time a bash shell is opened. It sets the default prompt and may add one or more aliases. Values in this file can be overridden by information in each user’s ~/.bashrc
file.
Used by each user to enter information that is specific to their own use of the shell. It is executed only once, when the user logs in. By default it sets a few environment variables and executes the user’s
.bashrc
file.
Contains the information that is specific to your bash shells. It is read when you log in and also each time you open a new bash shell. This is the best location to add environment variables and aliases so that your shell picks them up.
Executes each time you log out (exit the last bash shell). By default, it simply clears your screen.
To change the /etc/profile or /etc/bashrc files, you must be the root user.
Users can change the information in the $HOME/.bash_profile
, $HOME/.bashrc
, and $HOME/.bash_logout
files in their own home directories.
The following sections provide ideas about items to add to your shell configuration files. In most cases, you add these values to the .bashrc
file in your home directory.
However, if you administer a system, you may want to set some of these values as defaults for all of your Linux system’s users.
Your prompt consists of a set of characters that appears each time the shell is ready to accept a command. The PS1 environment variable sets what the prompt contains.
If your shell requires additional input, it uses the values of PS2 , PS3 , and PS4 .
When your Linux system is installed, often a prompt is set to contain more than just a dollar sign or pound sign. For example, in Linux systems from Red Hat, your prompt is set to include the following information: your username, your host name, and the base name of your current working directory. That information is surrounded by brackets and followed by a dollar sign (for regular users) or a pound sign (for the root user). Here is an example of that prompt:
[[email protected] bin]$
07_579495 ch02.qxd 12/27/04 9:51 PM Page 53
Chapter 2
✦
Running Commands from the Shell
53
If you change directories, the bin name would change to the name of the new directory. Likewise, if you were to log in as a different user or to a different host, that information would change.
You can use several special characters (indicated by adding a backslash to a variety of letters) to include different information in your prompt. These can include your terminal number, the date, and the time, as well as other pieces of information.
Here are some examples (you can find more on the bash man page):
Tip
\]
\\
\d
\h
\n
\
nnn
\s
\t
\u
\w
Special Description
Character
\!
\#
\$
\W
\[
Shows the current command history number. This includes all previous commands stored for your username.
Shows the command number of the current command. This includes only the commands for the active shell.
Shows the user prompt (
$
) or root prompt (
#
), depending on which user you are.
Shows only the current working directory base name. For example, if the current working directory was
/var/spool/mail
, this value would simply appear as mail
.
Precedes a sequence of nonprinting characters. This could be used to add a terminal control sequence into the prompt for such things as changing colors, adding blink effects, or making characters bold. (Your terminal determines the exact sequences available.)
Follows a sequence of nonprinting characters.
Shows a backslash.
Displays the day, month, and number of the date. For example: Sat Jan 23.
Shows the host name of the computer running the shell.
Causes a new line to occur.
Shows the character that relates to the octal number replacing nnn.
Displays the current shell name. For the bash shell, the value would be bash
.
Prints the current time in hours, minutes, and seconds (for example, 10:14:39).
Prints your current username.
Displays the full path to the current working directory.
If you are setting your prompt temporarily by typing at the shell, you should put the value of
PS1 in quotes. For example, you could type export
PS1=”[\t \w]\$ “
to see a prompt that looks like this:
[20:26:32 /var/spool]$
.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 54
54
Part I ✦
Linux First Steps
To make a change to your prompt permanent, add the value of PS1 to your .bashrc
file in your home directory (assuming that you are using the bash shell). There may already be a PS1 value in that file that you can modify.
Caution
You may consider adding a few environment variables to your
.bashrc
file. These can help make working with the shell more efficient and effective:
✦
TMOUT — Sets how long the shell can be inactive before bash automatically exits. The value is the number of seconds for which the shell has not received input. This can be a nice security feature, in case you leave your desk while you are still logged in to Linux. So as not to be logged off while you are working, you may want to set the value to something like of idle time).
TMOUT=1800 (to allow 30 minutes
✦
PATH — As described earlier, the PATH variable sets the directories that are searched for commands you use. If you often use directories of commands that are not in your PATH , you can permanently add them. To do this, add a
PATH variable to your .bashrc
file. For example, to add a directory called
/getstuff/bin , add the following:
PATH=$PATH:/getstuff/bin ; export PATH
This example first reads all the current path directories into the new PATH
( $PATH ), adds the /getstuff/bin directory, and then exports the new PATH .
Some people add the current directory to their
PATH fied simply as a dot (
.
), as follows: by adding a directory identi-
PATH=.:$PATH ; export PATH
This lets you always run commands in your current directory (which people may be used to if they have used DOS). However, the security risk with this procedure is that you could be in a directory that contains a command that you don’t intend to run from that directory. For example, a hacker could put an ls command in a directory that, instead of listing the content of your directory, does something devious.
✦
WHATEVER
— You can create your own environment variables to provide shortcuts in your work. Choose any name that is not being used and assign a useful value to it. For example, if you do a lot of work with files in the /work/time/ files/info/memos directory, you could set the following variable:
M=/work/time/files/info/memos ; export M
You could make that your current directory by typing
cd $M
. You could run a program from that directory called hotdog by typing
$M/hotdog
. You could edit a file from there called bun by typing
.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 55
Chapter 2
✦
Running Commands from the Shell
55
Setting aliases can save you even more typing than setting environment variables.
With aliases, you can have a string of characters execute an entire command line.
You can add and list aliases with the alias command. Here are some examples: alias p=’pwd ; ls –CF’ alias rm=’rm -i’ alias p=’pwd ; ls -CF’ alias rm=’rm -i’
In the first example, the letter p is assigned to run the command pwd and then to run ls -CF to print the current working directory and list its contents in column form. The second runs the rm command with the -i option each time you simply type
. (This is an alias that is often set automatically for the root user, so that instead of just removing files, you are prompted for each individual file removal.
This prevents you from removing all the files in a directory by mistakenly typing something such as rm *
)
While you are in the shell, you can check which aliases are set by typing the alias command. If you want to remove an alias, type
. (Remember that if the alias is set in a configuration file, it will be set again when you open another shell.)
Every active shell stores pieces of information that it needs to use in what are called
environment variables
. An environment variable can store things such as locations of configuration files, mailboxes, and path directories. It can also store values for your shell prompts, the size of your history list, and type of operating system.
To see the environment variables currently assigned to your shell, type the declare command. (It will probably fill more than one screen, so type
.) You can refer to the value of any of those variables by preceding it with a dollar sign ( $ ) and placing it anywhere on a command line. For example:
$
echo $USER
chris
This command prints the value of the USER
(chris). Substitute any other value for USER variable, which holds your username to print its value instead.
When you start a shell (by logging in or opening a Terminal window), a lot of environment variables are already set. Here are some variables that are either set when you use a bash shell or that can be set by you to use with different features.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 56
56
Part I ✦
Linux First Steps
Variable
BASH
BASH_VERSION
EUID
FCEDIT
HISTFILE
HISTFILESIZE
HISTCMD
HOME
HOSTTYPE
OLDPWD
OSTYPE
PATH
PPID
PROMPT_COMMAND
Description
Contains the full path name of the bash command. This is usually
/bin/bash
.
A number of the current version of the bash command.
This is the effective user ID number of the current user. It is assigned when the shell starts, based on the user’s entry in the
/etc/passwd file.
If set, this variable indicates the text editor used by the fc command to edit history mand is used.
commands. If this variable isn’t set, the vi com-
The location of your history file. It is typically located at
$HOME/.
bash_history .
The number of history entries that can be stored. After this number is reached, the oldest commands are discarded. The default value is 1000.
This returns the number of the current command in the history list.
This is your home directory. It is your current working directory each time you log in or type the cd command with any options.
A value that describes the computer architecture on which the Linux system is running. For Intel-compatible PCs, the value is i386, i486, i586, i686, or something like i386-linux. For AMD 64-bit machines, the value is x86_64.
This is the location of your mailbox file. The file is typically your username in the
/var/spool/mail directory
.
The directory that was the working directory before you changed to the current working directory.
A name identifying the current operating system. For Fedora Core
Linux, the OSTYPE value is either linux or linux-gnu, depending on the type of shell you are using. (Bash can run on other operating systems as well.)
The colon-separated list of directories used to find commands that you type. The default value for regular users is /bin:/usr/bin:/ usr/local/bin:/usr/bin/X11:/usr/X11R6/bin:~/bin
.
You need to type the full path or a relative path to a command you want to run that is not in your
PATH
. For the root user, the value also includes /sbin , /usr/sbin , and /usr/local/sbin .
The process ID of the command that started the current shell
(for example, its parent process).
Can be set to a command name that is run each time before your shell prompt is displayed. Setting PROMPT_COMMAND=date current date/time before the prompt appears.
lists the
07_579495 ch02.qxd 12/27/04 9:51 PM Page 57
Chapter 2
✦
Running Commands from the Shell
57
Variable
PS1
PWD
RANDOM
SECONDS
SHLVL
TMOUT
UID
Description
Sets the value of your shell prompt. There are many items that you can read into your prompt (date, time, username, host name, and so on). Sometimes a command requires additional prompts, which you can set with the variables
PS2
,
PS3
, and so on.
This is the directory that is assigned as your current directory. This value changes each time you change directories using the cd command.
Accessing this variable causes a random number to be generated.
The number is between 0 and 99999.
The number of seconds since the time the shell was started.
The number of shell levels associated with the current shell session.
When you log in to the shell, the
SHLVL is
1
. Each time you start a new bash command (by, for example, using su to become a new user, or by simply typing
bash
), this number is incremented.
Can be set to a number representing the number of seconds the shell can be idle without receiving input. After the number of seconds is reached, the shell exits. This is a security feature that makes it less likely for unattended shells to be accessed by unauthorized people.
(This must be set in the login shell for it to actually cause the shell to log out the user.)
The user ID number assigned to your username. The user ID number is stored in the
/etc/password file.
Environment variables can provide a handy way of storing bits of information that you use often from the shell. You can create any variables that you want (avoiding those that are already in use) so that you can read in the values of those variables as you use the shell. (The bash man page lists variables already in use.)
To set an environment variable temporarily, you can simply type a variable name and assign it to a value. Here’s an example:
$ AB=/usr/dog/contagious/ringbearer/grind ; export AB
This example causes a long directory path to be assigned to the AB export AB variable. The command says to export the value to the shell so that it can be propagated to other shells you may open. With the following:
AB set, you go to the directory by typing
$
cd $AB
07_579495 ch02.qxd 12/27/04 9:51 PM Page 58
58
Part I ✦
Linux First Steps
The problem with setting environment variables in this way is that as soon as you exit the shell in which you set the variable, the setting is lost. To set variables permanently, add variable settings to a bash configuration file, as described later in this section.
If you want to have other text right up against the output from an environment variable, you can surround the variable with braces. This protects the variable name from being misunderstood. For example, if you wanted to add a command name to the AB variable shown earlier, you could type the following:
$
echo ${AB}/adventure
/usr/dog/contagious/ringbearer/grind/adventure
Remember that you must export the variable so that it can be picked up by other shell commands. You must add the export line to a shell configuration file for it to take effect the next time you log in. The export command is fairly flexible. Instead of running the export step, as follows: command after you set the variable, you can do it all in one
$
export XYZ=/home/xyz/bin
You can override the value of any environment variable. This can be temporary, by simply typing the new value, or you can add the new export line to your
$HOME/.bashrc
file. One useful variable to update is PATH :
$ export PATH=$PATH:/home/xyz/bin
In this example the
/home/xyz/bin directory is added to the
PATH
, a useful technique if you want to run a bunch of commands from a directory that is not normally in your
PATH
, without typing the full or relative path each time.
If you decide that you no longer want a variable to be set, you can use the unset command to erase its value. For example, you could type
unset XYZ
, which would cause
XYZ to have no value set. (Remember to remove the export from the
$HOME/.
bashrc file — if you added it there — or it will return the next time you open a shell.)
If you are using Linux over a network or from a
dumb
terminal (a monitor that allows only text input with no GUI support), your shell may be all that you have.
You may be used to a windowing environment where you have a lot of programs active at the same time so that you can switch among them as needed. This shell thing can seem pretty limited.
Although the bash shell doesn’t include a GUI for running many programs, it does let you move active programs between the background and foreground. In this way, you can have a lot of stuff running while selectively choosing the one you want to deal with at the moment.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 59
Chapter 2
✦
Running Commands from the Shell
59
You can place an active program in the background in several ways. One mentioned earlier is to add an ampersand (
&
) to the end of a command line. Another way is to use the at the shell.
command to run commands in a way in which they are not connected to
To stop a running command and put it in the background, press Ctrl+Z. After the command is stopped, you can either bring it to the foreground to run (the or start it running in the background (the bg command).
fg command)
If you have programs that you want to run while you continue to work in the shell, you can place the programs in the background. To place a program in the background at the time you run the program, type an ampersand ( & ) at the end of the command line, like this:
$ find /usr > /tmp/allusrfiles &
This example command finds all files on your Linux system (starting from /usr ), prints those filenames, and puts those names in the file
/tmp/allusrfiles
. The ampersand ( & ) runs that command line in the background. To check which commands you have running in the background, use the jobs command, as follows:
$
jobs
[1] Stopped (tty output) vi /tmp/myfile
[2] Running find /usr -print > /tmp/allusrfiles &
[3] Running nroff -man /usr/man2/* >/tmp/man2 &
[4]- Running nroff -man /usr/man3/* >/tmp/man3 &
[5]+ Stopped nroff -man /usr/man4/* >/tmp/man4
The first job shows a text-editing command ( vi ) that I placed in the background and stopped by pressing Ctrl+Z while I was editing. Job 2 shows the find command
I just ran. Jobs 3 and 4 show nroff commands currently running in the background.
Job 5 had been running in the shell (foreground) until I decided too many processes were running and pressed Ctrl+Z to stop job 5 until a few processes had completed.
Tip
The plus sign ( + ) next to number 5 shows that it was most recently placed in the background. The minus sign (
-
) next to number 4 shows that it was placed in the background just before the most recent background job. Because job 1 requires terminal input, it cannot run in the background. As a result, it is
Stopped until it is brought to the foreground again.
To see the process ID for the background job, add a
-l option to the jobs command. If you type ps
, you can use the process ID to figure out which command is for a particular background job.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 60
60
Part I ✦
Linux First Steps
Continuing with the example, you can bring any of the commands on the jobs list to the foreground. For example, to edit myfile again, type
$
fg %1
Caution
As a result, the vi the vi job.
command opens again, with all text as it was when you stopped
Before you put a text processor, word processor, or similar program in the background, make sure you save your file. It’s easy to forget you have a program in the background and you will lose your data if you log out or the computer reboots later on.
To refer to a background job (to cancel or bring it to the foreground), use a percent sign ( % ) followed by the job number. You can also use the following to refer to a background job:
✦
% — Refers to the most recent command put into the background (indicated by the plus sign). This action brings the command to the foreground.
✦
%
string
— Refers to a job where the command begins with a particular
string
of characters. The
string
must be unambiguous. (In other words, typing %vi when there are two vi an error message.) commands in the background results in
✦
%?
string
— Refers to a job where the command line contains a string at any point. The string must be unambiguous or the match will fail.
✦
%--
— Refers to the previous job stopped before the one most recently stopped.
If a command is stopped, you can start it running again in the background using the bg command. For example, take job number 5 from the jobs list in the previous example:
[5]+ Stopped nroff -man man4/* >/tmp/man4
Type the following:
$
bg %5
After that, the job runs in the background. Its jobs entry appears as follows:
[5] Running nroff -man man4/* >/tmp/man4 &
The Linux file system is the structure in which all the information on your computer is stored. Files are organized within a hierarchy of directories. Each directory can contain files, as well as other directories.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 61
Chapter 2
✦
Running Commands from the Shell
61
If you were to map out the files and directories in Linux, it would look like an upside-down tree. At the top is the root directory, which is represented by a single slash ( / ). Below that is a set of common directories in the Linux system, such as bin
, dev
, home
, lib
, and tmp
, to name a few. Each of those directories, as well as directories added to the root, can contain subdirectories.
Figure 2-1 illustrates how the Linux file system is organized as a hierarchy. To demonstrate how directories are connected, the figure shows a
/home directory that contains subdirectories for three users: chris , mary , and tom . Within the chris directory are subdirectories: briefs
, memos
, and personal
. To refer to a file called inventory in the chris/memos directory, you could type the full path of
/home/chris/memos/inventory
. If your current directory were
/home/ chris/memos , you could refer to the file as simply inventory .
/ bin/ dev/ etc/ home/ root/ tmp/ ...
chris/ mary/ tom/ briefs/ memos/ personal/
Figure 2-1:
The Linux file system is organized as a hierarchy of directories.
Some of the Linux directories that may interest you include the following:
✦
/bin — Contains common Linux user commands, such as ls , sort , date , and chmod .
✦
/boot — Has the bootable Linux kernel and boot loader configuration files
(GRUB).
✦
/dev — Contains files representing access points to devices on your systems.
These include terminal devices ( tty* ), floppy disks ( fd* ), hard disks ( hd* ),
RAM ( ram* ), and CD-ROM ( cd* ). (Users normally access these devices directly through the device files.)
✦
/etc — Contains administrative configuration files.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 62
62
Part I ✦
Linux First Steps
✦
/home — Contains directories assigned to each user with a login account.
✦
/mnt — Provides a location for mounting devices, such as remote file systems and removable media (with directory names of cdrom, floppy, and so on).
✦
/proc — Contains information about system resources.
✦
/root — Represents the root user’s home directory.
✦
/sbin
— Contains administrative commands and daemon processes.
✦
/sys (A /proc -like file system, new in the Linux 2.6 kernel and intended to contain files for getting hardware status and reflecting the system’s device tree as it is seen by the kernel. It pulls many of its functions from /proc .
✦
/tmp — Contains temporary files used by applications.
✦
/usr — Contains user documentation, games, graphical files (X11), libraries
(lib), and a variety of other user and administrative commands and files.
✦
/var — Contains directories of data used by various applications. In particular, this is where you would place files that you share as an FTP server (
/var/ftp
) or a Web server ( /var/www ). It also contains all system log files ( /var/log ).
The file systems in the DOS or Microsoft Windows operating systems differ from
Linux’s file structure, as the “Linux File Systems Versus Windows-Based File Systems” sidebar explains.
Although similar in many ways, the Linux file system has some striking differences from file systems used in MS-DOS and Windows operating systems. Here are a few:
✦
In MS-DOS and Windows file systems, drive letters represent different storage devices
(for example, A: is a floppy drive and C: is a hard disk). In Linux, all storage devices are fit into the file system hierarchy. So, the fact that all of
/usr hard disk or that
/mnt/rem1 may be on a separate is a file system from another computer is invisible to the user.
✦
Slashes, rather than backslashes, are used to separate directory names in Linux. So,
C:\home\chris in an MS system is
/home/chris in a Linux system.
✦
Filenames almost always have suffixes in DOS (such as
.txt
for text files or
.doc
for word-processing files). Although at times you can use that convention in Linux, three-character suffixes have no required meaning in Linux. They can be useful for identifying a file type.
✦
Every file and directory in a Linux system has permissions and ownership associated with it. Security varies among Microsoft systems. Because DOS and MS Windows began as single-user systems, file ownership was not built into those systems when they were designed. Later releases added features such as file and folder attributes to address this problem.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 63
Chapter 2
✦
Running Commands from the Shell
63
As a Linux user, most of the files you save and work with will probably be in your home directory. Here are commands to create and use files and directories:
Command
cd pwd mkdir chmod ls
Result
Change to another current working directory.
Print the name of the current working directory.
Create a directory.
Change the permission on a file or directory.
List the contents of a directory.
Note
The following steps lead you through creating directories within your home directory and moving among your directories, with a mention of setting appropriate file permissions:
Go to your home directory. To do this, simply type
. (For other ways of referring to your home directory, see the “Identifying Directories” sidebar.)
To make sure that you got to your home directory, type
. When I do this, I get the following response (yours will reflect your home directory):
$
pwd
/home/chris
Create a new directory called test in your home directory, as follows:
$
mkdir test
Check the permissions of the directory:
$
ls -ld test
drwxr-xr-x 2 chris sales 1024 Jan 24 12:17 test
This listing shows that test is a directory ( d ); followed by the permissions
( rwxr-xr-x ), which are explained later in the “Understanding File Permissions” section; the owner ( chris ); the group ( sales ); and that the file was most recently modified on Jan. 24 at 12:17 p.m.
In some Linux systems, such as Fedora Core, when you add a new user, the user is assigned to a group of the same name by default. For example, in the preceding text, the user chris would be assigned to the group chris
. This approach to assigning groups is referred to as the user private group scheme. For more information on user private groups, see Chapter 4.
For now, type the following:
$
chmod 700 test
07_579495 ch02.qxd 12/27/04 9:51 PM Page 64
64
Part I ✦
Linux First Steps
This step changes the permissions of the directory to give you complete access and everyone else no access at all. (The new permissions should read like rwx------
.)
Last, make the test directory your current directory as follows:
$
cd test
To make efficient use of your shell, the bash shell lets you use certain special characters, referred to as metacharacters and operators. Metacharacters can help you match one or more files without typing each file completely. Operators let you direct information from one command or file to another command or file.
To save you some keystrokes and to be able to refer easily to a group of files, the bash shell lets you use metacharacters. Anytime you need to refer to a file or directory, such as to list it, open it, or remove it, you can use metacharacters to match the files you want. Here are some useful metacharacters for matching filenames:
✦
*
Matches any number of characters.
✦
?
Matches any one character.
✦
[...]
Matches any one of the characters between the brackets, which can include a dash-separated range of letters or numbers.
When you need to identify your home directory on a shell command line, you can use the following:
✦
$HOME
— This environment variable stores your home directory name.
✦
~
— The tilde (
~
) represents your home directory on the command line.
You can also use the tilde to identify someone else’s home directory. For example,
~chris would be expanded to the chris home directory (probably
/home/chris
).
Other special ways of identifying directories in the shell include the following:
✦
.
— A single dot (
.
) refers to the current directory.
✦
..
— Two dots (
..
) refers to a directory directly above the current directory.
✦
$PWD
— This environment variable refers to the current working directory.
✦
$OLDPWD
— This environment variable refers to the previous working directory before you changed to the current one.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 65
Chapter 2
✦
Running Commands from the Shell
65
Try out some of these file-matching metacharacters by first going to an empty directory (such as the test directory described in the previous section) and creating some empty files:
$ touch apple banana grape grapefruit watermelon
The touch command creates empty files. The next few commands show you how to use shell metacharacters with the ls command to match filenames. Try the following commands to see if you get the same responses:
$
ls a*
apple
$
ls g*
grape grapefruit
$
ls g*t
grapefruit
$
ls *e*
apple grape grapefruit watermelon
$
ls *n*
banana watermelon
The first example matches any file that begins with an a ( apple ). The next example matches any files that begin with g
( grape
, grapefruit
). Next, files beginning with g and ending in t are matched ( grapefruit ). Next, any file that contains an e in the name is matched ( apple
, grape
, grapefruit
, watermelon
). Finally, any file that contains an n is matched ( banana , watermelon ).
Here are a few examples of pattern matching with the question mark ( ?
):
$
ls ????e
apple grape
$
ls g???e*
grape grapefruit
The first example matches any five-character file that ends in e
( apple
, grape
).
The second matches any file that begins with g
( grape
, grapefruit
).
and has e as its fifth character
Here are a couple of examples using braces to do pattern matching:
$
ls [abw]*
apple banana watermelon
$
ls [agw]*[ne]
apple grape watermelon
07_579495 ch02.qxd 12/27/04 9:51 PM Page 66
66
Part I ✦
Linux First Steps
In the first example, any file beginning with a , b , or w is matched. In the second, any file that begins with a
, g
, or w and also ends with either n or e is matched. You can also include ranges within brackets. For example:
$
ls [a-g]*
apple banana grape grapefruit
Here, any filenames beginning with a letter from a through g is matched.
Commands receive data from standard input and send it to standard output. Using pipes (described earlier), you can direct standard output from one command to the standard input of another. With files, you can use less-than ( < ) and greater-than ( > ) signs to direct data to and from files. Here are the file redirection characters:
✦
<
— Direct the contents of a file to the command.
✦
> — Direct the output of a command to a file, deleting the existing file.
✦
>> — Direct the output of a command to a file, adding the output to the end of the existing file.
Here are some examples of command lines where information is directed to and from files:
$
mail root < ~/.bashrc
$
man chmod | col -b > /tmp/chmod
$
echo “I finished the project on $(date)” >> ~/projects
In the first example, the contents of the
.bashrc
file in the home directory are sent in a mail message to the computer’s root user. The second command line formats the chmod man page (using the man command), removes extra back spaces ( col -b
) and sends the output to the file /tmp/chmod (erasing the previous /tmp/chmod file, if it exists). The final command results in the following text being added to the user’s project file:
I finished the project on Sat Jan 22 13:46:49 PST 2005
After you’ve worked with Linux for a while, you are almost sure to get a “Permission denied” message. Permissions associated with files and directories in Linux were designed to keep users from accessing other users’ private files and to protect important system files.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 67
Chapter 2
✦
Running Commands from the Shell
67
The nine bits assigned to each file for permissions define the access that you and others have to your file. Permission bits appear as rwxrwxrwx. The first three bits apply to the owner’s permission, the next three apply to the group assigned to the file, and the last three apply to all others. The r stands for read
,
the w stands for write
,
and the x stands for execute permissions. If a dash appears instead of the letter, it means that permission is turned off for that associated read, write, or execute.
Because files and directories are different types of elements, read, write, and execute permissions on files and directories mean different things. Here’s what you can do with each of them:
Permission
Read
Write
Execute
File
View what’s in the file.
Change the file’s content, rename it, or delete it.
Run the file as a program.
Directory
See what files and subdirectories it contains.
Add files or subdirectories to the directory.
Change to that directory as the current directory, search through the directory, or execute a program from the directory.
You can see the permission for any file or directory by typing the ls -ld
The named file or directory appears as those shown in this example: command.
$
ls -ld ch3 test
-rw-rw-r-- 1 chris sales 4983 Jan 18 22:13 ch3 drwxr-xr-x 2 chris sales 1024 Jan 24 13:47 test
The first line shows that the ch3 file has read and write permission for the owner and the group. All other users have read permission, which means they can view the file but cannot change its contents or remove it. The second line shows the test tory (indicated by the letter d direcbefore the permission bits). The owner has read, write, and execute permission, while the group and other users have only read and execute permissions. As a result, the owner can add, change, or delete files in that directory, and everyone else can only read the contents, change to that directory, and list the contents of the directory.
If you own a file, you can use the chmod command to change the permission on it as you please. In one method of doing this, each permission (read, write, and execute), is assigned a number — r=4, w=2, and x=1 — and you use each set’s total number to establish the permission. For example, to make permissions wide open for yourself as owner, you’d set the first number to 7 (4+2+1), and to give the group and others only read permission, you’d set both the second and third numbers to 4 (4+0+0), so that the final number is 744. Any combination of permissions can result from 0 (no permission) through 7 (full permission).
07_579495 ch02.qxd 12/27/04 9:51 PM Page 68
68
Part I ✦
Linux First Steps
Here are some examples of how to change permission on a file (named file ) and what the resulting permission would be:
#
chmod 777 file
#
chmod 755 file
#
chmod 644 file
#
chmod 000 file
rwxrwxrwx rwxr-xr-x rw-r--r-
---------
You can also turn file permissions on and off using plus (+) and minus (–) signs, respectively. This can be done for the owner user (u), owner group (g), others (o), and all users (a). For example, each time starting with a file that has all permissions open (rwxrwxrwx), here are some chmod examples with resulting permissions after using a minus sign:
chmod a-w files chmod o-x files chmod go-rwx files
r-xr-xr-x rwsrwsrwrwx------
Likewise, here are some examples, starting with all permissions closed (
---------
) where the plus sign is used with chmod to turn permissions on:
chmod u+rw files chmod a+x files chmod ug+rx files
rw-------
--x--x--x r-xr-x---
When you create a file, it’s given the permission rw-r--r-- by default. A directory is given the permission rwxr-xr-x. These default values are determined by the value of umask
. Type
to see what your umask value is. For example:
$
umask
022
Tip
The umask value masks the permissions value of 666 for a file and 777 for a directory. The umask value of 022 results in permission for a directory of 755 (rwxr-xr-x).
That same umask results in a file permission of 644 (rw-r--r--). (Execute permissions are off by default for regular files.)
Time saver: Use the
-R options of chmod to change the permission for all of the files and directories within a directory structure at once. For example, if you wanted to open permissions completely to all files and directories in the tory, you could type the following:
/tmp/test direc-
$ chmod -R 777 /tmp/test
This command line runs chmod recursively (
-R
) for the
/tmp/test directory, as well as any files or directories that exist below that point in the file system (for example,
/tmp/test/hat
,
/tmp/test/hat/caps
, and so on). All would be set to 777 (full read/write/execute permissions). This is not something you would do on an important directory on a read/write file system. However, you might do this before you create a directory structure on a CD-ROM that you want to be fully readable and executable to someone using the CD-ROM later.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 69
Chapter 2
✦
Running Commands from the Shell
69
Caution
The
-R option of chmod works best if you are opening permissions completely or adding execute permission (as well as the appropriate read/write permission).
The reason is that if you turn off execute permission recursively, you close off your capability to change to any directory in that structure. For example, chmod -R 644
/tmp/test turns off execute permission for the
/tmp/test directory and then fails to change any files or directories below that point.
Commands for moving, copying, and deleting files are fairly straightforward. To change the location of a file, use the mv command. To copy a file from one location to another, use the cp some examples: command. To remove a file, use the rm command. Here are
$
mv abc def
$
mv abc ~
$
cp abc def
$
cp abc ~
$
rm abc
$ rm *
Note
Of the two move ( mv ) commands, the first moves the file abc to the file def in the same directory (essentially renaming it), whereas the second moves the file abc to your home directory ( ~ ). The first copy command ( cp ) copies abc def , whereas the second copies abc to the file to your home directory ( ~ ). The first remove command ( rm ) deletes the abc file; the second removes all the files in the current directory (except those that start with a dot).
For the root user, the mv
, cp
, and rm commands are aliased to each be run with the
-i option. This causes a prompt to appear asking you to confirm each move, copy, and removal, one file at a time, and is done to prevent the root user from messing up a large group of files by mistake.
Another alternative with mv is to use the
-b option. With
-b
, if a file of the same name exists at the destination, a backup copy of the old file is made before the new file is moved there.
It’s almost impossible to use Linux for any period of time and not need to use a text editor. This is because most Linux configuration files are plain-text files that you will almost certainly need to change manually at some point.
If you are using a GUI, you can run gedit , which is fairly intuitive for editing text.
There’s also a simple text editor you can run from the shell called nano . However, most Linux shell users will use either the vi or emacs command to edit text files.
The advantage of vi or emacs over a graphical editor is that you can use them from
07_579495 ch02.qxd 12/27/04 9:51 PM Page 70
70
Part I ✦
Linux First Steps
any shell, a character terminal, or a character-based connection over a network
(using telnet or ssh
, for example) — no GUI is required. They also each contain tons of features, so you can continue to grow with them.
This section provides a brief tutorial of the vi text editor, which you can use to manually edit a configuration file from any shell. (If vi doesn’t suit you, see the
“Exploring Other Text Editors” sidebar for other options.)
The vi editor is difficult to learn at first, but once you know it, you never have to use a mouse or a function key — you can edit and move around quickly and efficiently within files just by using the keyboard.
Most often, you start vi to open a particular file. For example, to open a file called
/tmp/test , type the following command:
$
vi /tmp/test
If this is a new file, you should see something similar to the following:
~
~
~
~
~
“/tmp/test” [New File]
The box at the top represents where your cursor is. The bottom line keeps you informed about what is going on with your editing (here you just opened a new file). In between, there are tildes ( ~ ) as filler because there is no text in the file yet.
Now here’s the intimidating part: There are no hints, menus, or icons to tell you what to do. On top of that, you can’t just start typing. If you do, the computer is likely to beep at you. And some people complain that Linux isn’t friendly.
The first things you need to know are the different operating modes: command and input. The vi editor always starts in command mode. Before you can add or change text in the file, you have to type a command (one or two letters and an optional number) to tell vi what you want to do. Case is important, so use upper- and lowercase exactly as shown in the examples! To get into input mode, type an input command.
To start out, type either of the following:
✦ a — The add command. After it, you can input text that starts to the
right
the cursor.
of
✦ i — The insert command. After it, you can input text that starts to the
left
the cursor.
of
07_579495 ch02.qxd 12/27/04 9:51 PM Page 71
Chapter 2
✦
Running Commands from the Shell
71
Tip
Type a few words and then press Enter. Repeat that a few times until you have a few lines of text. When you’re finished typing, press Esc to return to command mode.
Now that you have a file with some text in it, try moving around in your text with the following keys or letters:
Remember the Esc key! It always places you back into command mode.
✦
— Move the cursor up, down, left, or right in the file one character at a time. To move left and right you can also use Backspace and the spacebar, respectively. If you prefer to keep your fingers on the keyboard, move the cursor with h (left), l (right), j (down), or k (up).
✦
— Moves the cursor to the beginning of the next word.
✦
— Moves the cursor to the beginning of the previous word.
✦
(zero)
— Moves the cursor to the beginning of the current line.
✦
— Moves the cursor to the end of the current line.
✦
— Moves the cursor to the upper-left corner of the screen (first line on the screen).
✦
— Moves the cursor to the first character of the middle line on the screen.
✦
— Moves the cursor to the lower-left corner of the screen (last line on the screen).
The only other editing you need to know is how to delete text. Here are a few vi commands for deleting text:
✦
— Deletes the character under the cursor.
✦
— Deletes the character directly before the cursor.
✦
— Deletes from the current character to the end of the current word.
✦
— Deletes from the current character to the end of the current line.
✦
— Deletes from the previous character to the beginning of the current line.
To wrap things up, use the following keystrokes for saving and quitting the file:
✦
— Save the current changes to the file and exit from vi.
✦
— Save the current file but continue editing.
✦
— Same as ZZ.
✦
— Quit the current file. This works only if you don’t have any unsaved changes.
✦
— Quit the current file and
don’t
save the changes you just made to the file.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 72
72
Part I ✦
Linux First Steps
Tip
If you’ve really trashed the file by mistake, the
:q!
command is the best way to exit and abandon your changes. The file reverts to the most recently changed version.
So, if you just did a
:w
, you are stuck with the changes up to that point. If you just want to undo a few bad edits, press u to back out of changes.
You have learned a few vi editing commands. I describe more commands in the following sections. First, though, here are a few tips to smooth out your first trials with vi:
✦
— Remember that Esc gets you back to command mode. (I’ve watched people press every key on the keyboard trying to get out of a file.) Esc followed by ZZ gets you out of command mode, saves the file, and exits.
✦
— Press U to undo the previous change you made. Continue to press U to undo the change before that, and the one before that.
✦
— If you decide you didn’t want to undo the previous command, use
Ctrl+R for Redo. Essentially, this command undoes your undo.
✦
— Beware of hitting Caps Lock by mistake. Everything you type in vi has a different meaning when the letters are capitalized. You don’t get a warning that you are typing capitals — things just start acting weird.
✦
— You can run a command while you are in vi using :!
followed by a command name. For example, type
to see the current date and time, type
to see what your current directory is, or type
to see if you have any jobs running in the background. When the command completes, press Enter and you are back to editing the file. You could even do that with a shell ( :!bash
) to run a few commands from the shell, then type
to return to vi. (I recommend doing a save before escaping to the shell, just in case you forget to go back to vi.)
✦
— When you are in insert mode, the word INSERT appears at the bottom of the screen.
✦
— If you forget what you are editing, pressing these keys displays the name of the file that you are editing and the current line that you are on at the bottom of the screen. It also displays the total number of lines in the file, the percentage of how far you are through the file, and the column number the cursor is on. This just helps you get your bearings after you’ve stopped for a cup of coffee at 3 a.m.
Besides the few movement commands described earlier, there are other ways of moving around a vi file. To try these out, open a large file that you can’t do much damage to. (Try copying /var/log/messages are some movement commands you can use: to /tmp and opening it in vi.) Here
07_579495 ch02.qxd 12/27/04 9:51 PM Page 73
Chapter 2
✦
Running Commands from the Shell
73
✦
— Page ahead, one page at a time.
✦
— Page back, one page at a time.
✦
— Page ahead 1/2 page at a time.
✦
— Page back 1/2 page at a time.
✦
— Go to the last line of the file.
✦
— Go to the first line of the file. (Use any number to go to that line in the file.)
To search for the next occurrence of text in the file, use either the slash (/) or the question mark (?) character. Follow the slash or question mark with a pattern
(string of text) to search forward or backward, respectively, for that pattern. Within the search, you can also use metacharacters. Here are some examples:
✦
/hello — Searches forward for the word
hello.
✦
?goodbye
— Searches backward for the word
goodbye.
✦
/The.*foot — Searches forward for a line that has the word
The
in it and also, after that at some point, the word
foot.
✦
?[pP]rint — Searches backward for either
or
Print.
Remember that case matters in Linux, so make use of brackets to search for words that could have different capitalization.
The vi editor was originally based on the ex editor, which didn’t let you work in full-screen mode. However, it did enable you to run commands that let you find and change text on one or more lines at a time. When you type a colon and the cursor goes to the bottom of the screen, you are essentially in ex mode. Here is an example of some of those ex commands for searching for and changing text. (I chose the words Local and
Remote to search for, but you can use any appropriate words.)
✦
:g/Local
— Searches for the word
Local and prints every occurrence of that line from the file. (If there is more than a screenful, the output is piped to the more command.)
✦
:s/Local/Remote — Substitutes Remote for the word Local on the current line.
✦
:g/Local/s//Remote — Substitutes the first occurrence of the word Local on every line of the file with the word
Remote
.
✦
:g/Local/s//Remote/g — Substitutes every occurrence of the word Local with the word Remote in the entire file.
✦
:g/Local/s//Remote/gp
— Substitutes every occurrence of the word
Local with the word Remote in the entire file and then prints each line so that you can see the changes (piping it through more if output fills more than one page).
07_579495 ch02.qxd 12/27/04 9:51 PM Page 74
74
Part I ✦
Linux First Steps
Dozens of text editors are available to use with Linux. Here are a few that might be in your
Linux distribution that you can try out if you find vi to be too taxing:
Text Editor
gedit jed joe kate kedit mcedit nedit
Description
The GNOME text editor that runs in the GUI.
This screen-oriented editor was made for programmers. Using colors, jed can highlight code you create so you can easily read the code and spot syntax errors. Use the Alt key to select menus to manipulate your text.
The joe editor is similar to many PC text editors. Use control and arrow keys to move around. Type Ctrl+C to exit with no save or Ctrl+X to save and exit.
A nice-looking editor that comes in the kdebase package. It has lots of bells and whistles, such as highlighting for different types of programming languages and controls for managing word wrap.
A GUI-based text editor that comes with the KDE desktop.
With mcedit, function keys help you get around, save, copy, move, and delete text. Like jed and joe, mcedit is screen-oriented.
An excellent programmer’s editor. You need to install the optional nedit package to get this editor.
If you use ssh to log in to other Linux computers on your network, you can use any editor to edit files. A GUI-based editor will pop up on your screen. When no GUI is available, you will need a text editor that runs in the shell, such as vi, jed, or joe.
You can precede most vi commands with numbers to have the command repeated that number of times. This is a handy way to deal with several lines, words, or characters at a time. Here are some examples:
Command
3dw
5cl
12j
Description
Deletes the next three words.
Changes the next five letters (that is, removes the letters and enters input mode).
Moves down 12 lines.
07_579495 ch02.qxd 12/27/04 9:51 PM Page 75
Chapter 2
✦
Running Commands from the Shell
75
Note
Putting a number in front of most commands just repeats those commands. At this point, you should be fairly proficient at using the vi command.
When you invoke vi in many Linux systems, you’re actually invoking the vim text editor, which runs in vi compatibility mode. Those who do a lot of programming might prefer vim because it shows different levels of code in different colors. vim has other useful features, such as the capability to open a document with the cursor at the same place where it was when you last exited that file.
Working from a shell command line within Linux may not be as simple as using a GUI, but it offers many powerful and flexible features. This chapter explains how to find your way around the shell in Linux and provides examples of running commands, including recalling commands from a history list, completing commands, and joining commands.
The chapter describes how shell environment variables can be used to store and recall important pieces of information. It also teaches you how to modify shell configuration files to tailor the shell to suit your needs. Finally, this chapter shows you how to use the Linux file system to create files and directories, use permissions, and work with files (moving, copying, and removing them), and how to edit text files from the shell using the vi command.
✦ ✦ ✦
07_579495 ch02.qxd 12/27/04 9:51 PM Page 76
08_579495 ch03.qxd 12/27/04 9:55 PM Page 77
I
n the past few years, graphical user interfaces (GUIs) available for Linux have become as easy to use as those on the Apple Mac or Microsoft Windows systems. With these improvements, even a novice computer user can start using
Linux without needing to have an expert standing by.
You don’t need to understand the underlying framework of the X Window System, window managers, widgets, and whatnots to get going with a Linux desktop system. That’s why I start by explaining how to use the two most popular desktop environments: KDE (K desktop environment) and GNOME.
After that, if you want to dig deeper, I tell you how you can put together your own desktop by discussing how to choose your own X-based window manager to run in Linux.
When you install Linux distributions such as Fedora Core,
SUSE, and Mandrakelinux, you have the option to choose a desktop environment. Distributions such as Gentoo and
Debian GNU/Linux give you the option to go out and get whatever desktop environment you want (without particularly prompting you for it). When you are given the opportunity to select a desktop during installation, your choices usually include one or more of the following:
✦
( www.kde.org
) — In addition to all the features you would expect to find in a complete desktop environment (window managers, toolbars, panels, menus, keybindings, icons, and so on), KDE has many bells and whistles available. Applications for graphics, multimedia, office productivity, games, system administration, and many other features have been integrated to work smoothly with KDE, which is the default desktop environment for SUSE, KNOPPIX, and various other Linux distributions.
✦ ✦ ✦ ✦
In This Chapter
Understanding yourdesktop
Using the K desktop environment
Using the GNOME desktop environment
Configuring your own desktop
✦ ✦ ✦ ✦
08_579495 ch03.qxd 12/27/04 9:55 PM Page 78
78
Part I ✦
Linux First Steps
✦
( www.gnome.org
) — GNOME is a more streamlined desktop environment. It includes a smaller feature set than KDE and runs faster in many lower-memory systems. Some think of GNOME as a more business-oriented desktop. It’s the default desktop for Red Hat Linux systems such as Fedora and RHEL.
✦
( X.org
or XFree86.org
+ WM) — You don’t need a full-blown desktop environment to operate Linux from a GUI. The most basic, reasonable way of using Linux is to simply start the X Window System server and a window manager of your choice (there are dozens to choose from). Many advanced users go this route because it can offer more flexibility in how they set up their desktops.
The truth is that most X applications run in any of the desktop environments just described (provided that proper libraries are included with your Linux distribution).
So you can choose a Linux desktop based on the performance, customization tools, and controls that best suit you. Each of those three types of desktop environments are described in this chapter.
Because the way that you start a desktop in Linux is completely configurable, different distributions offer different ways of starting up the desktop. Once your Linux distribution is installed, it may just boot to the desktop, offer a graphical login, or offer a text-based login. Bootable Linux systems (which don’t have to be installed at all) typically just boot to the desktop.
Some bootable Linux systems boot right to a desktop without requiring you to log in, so that you can immediately start working with Linux. KNOPPIX is an example of a distribution that boots straight to a Linux desktop from a CD. That desktop system usually runs as a particular username (such as knoppix, in the case of the KNOPPIX distribution). To perform system administration, you have to switch to the administrator’s account temporarily (using the su or sudo command).
Note
Most desktop Linux systems that are installed on your hard disk boot up to a graphical login screen. Although the X display manager (xdm) is the basic display manager that comes with the X Window System, KDE and GNOME each have their own graphical display managers that are used as login screens (kdm and gdm, respectively). So chances are that you will see the login screen associated with
KDE or GNOME (depending on which is the default on your Linux).
When Linux starts up, it enters into what is referred to as a run level or system state. Typically, a system set to start at run level 5 boots to a graphical login prompt. A system set to run level 3 boots to a text prompt. The run level is set by the initdefault line in the /etc/inittab file. Change the number on the
08_579495 ch03.qxd 12/27/04 9:55 PM Page 79
Chapter 3
✦
Getting into the Desktop
79 initdefault line as you please between 3 and 5 (don’t use other number unless you know what you are doing, and never use 0 or 6).
Because graphical login screens are designed to be configurable, you often find that the distribution has its own logo or other graphical elements on the login screen.
For example, Figure 3-1 shows a basic graphical login panel displayed by the kdm graphical display manager.
Figure 3-1:
A simple KDE display manager
(kdm) login screen includes a clock, login name list, and a few menu selections.
With Red Hat’s Fedora Core Linux, the default login screen is based on the GNOME display manager (gdm). Figure 3-2 shows the Fedora Core graphical login screen.
Figure 3-2:
The Fedora Project login screen is based on gdm.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 80
80
Part I ✦
Linux First Steps
You can just enter your login (username) and password to start up your personal desktop environment. Your selected desktop environment — KDE or GNOME — comes up ready for you to use. Although the system defines a desktop environment by default, you can typically change desktop environments on those Linux systems, such as Fedora, that offer both KDE and GNOME.
X display managers can enable you to do a lot more than just get to your desktop.
Although different graphical login screens offer different options, here are some you may encounter:
✦
— Look for a Session button on the login screen (such as the one that comes with Fedora). From there, you can choose to start your login session with a GNOME, KDE, or Failsafe environment. (Failsafe simply opens a Terminal window so, presumably, you can make a quick fix to the system without starting up a whole desktop environment.)
✦
— Linux systems that are configured to start multiple languages may give you the opportunity to choose a language (other than the default language) to boot into. For this to work, however, you must have installed support for the language you choose.
✦
— There’s no need to log in if all you want to do is turn off or restart your computer. Most graphical login screens offer you the option of rebooting or shutting down the machine from that screen.
If you don’t like the way the graphical login screen looks, or just want to assert greater control over how it works, there are many ways of configuring and securing
X graphical login screens. Later, once you are logged in, you can use the following tools (as root user) to configure the login screen:
✦
— From the KDE control center, you can modify your KDE display manager using the Login Manager screen (from KDE control center, select System Administration
➪
Login Manager). You can change logos, backgrounds, color schemes, and other features related to the look-and-feel of the login screen.
✦
— The GNOME display manager (gdm) comes with a
Login Screen Setup utility (from the desktop run the gdmconfig command as root user). From the Login Screen Setup window, you can select the Graphical
Greeter tab and choose a whole different theme for the login manager. On the
Security tab, you may notice that all TCP connections to the X server are disallowed. Don’t change this selection because no processes other than those handled directly by your display manager should be allowed to connect to the login screen.
After your login and password have been accepted, the desktop environment configured for your user account starts up. Users can modify their desktop environments to suit their tastes (even to the point of changing the entire desktop environment used).
08_579495 ch03.qxd 12/27/04 9:55 PM Page 81
Chapter 3
✦
Getting into the Desktop
81
Instead of a nice graphical screen with pictures and colors, you might see a login prompt that looks like this:
Welcome to XYZ Linux yourcomputer login:
This is the way all UNIX and older Linux systems used to appear on the screen when they booted up. Now this is the login prompt that is typical for a system that is installed as a server or, for some reason, was configured not to start an
X display manager for you to log in. Run level 3 boots to a plain-text login prompt in multiuser mode.
Just because you have a text prompt doesn’t necessarily mean you can start a desktop environment. Many Linux experts boot to a text prompt because they only want to use the GUI on occasion. However, if X and the necessary other desktop components are installed on your computer, you can typically start the desktop after you log in by typing the following command:
$
startx
Note
The default desktop environment starts up, and you should be ready to go. What you do next depends on whether you have a KDE, GNOME, or some sort of homespun desktop environment.
In most cases, the GUI configuration you do during installation for your video card and monitor gets you to a working desktop environment. If, for some reason, the screen is unusable when you start the desktop, you need to do some additional configuration. The “Configuring Your Own Desktop” section later in this chapter describes some tools you can use to get your desktop working.
The KDE was created to bring a high-quality desktop environment to UNIX (and now Linux) workstations. Integrated within KDE are tools for managing files, windows, multiple desktops, and applications. If you can work a mouse, you can learn to navigate the KDE desktop.
The lack of an integrated, standardized desktop environment once held back Linux and other UNIX systems from acceptance on the desktop. While individual applications ran well, you mostly could not drag-and-drop files or other items between applications. Likewise, you couldn’t open a file and expect the machine to launch the correct application to deal with it or save your windows from one login session
08_579495 ch03.qxd 12/27/04 9:55 PM Page 82
82
Part I ✦
Linux First Steps
to the next. With KDE, you can do all those things and much more. For example, you can:
✦
Drag-and-drop a document from a folder window (Konqueror) to the Trash icon
(to get rid of it) or on a OpenOffice.org Writer icon (to open it for editing).
✦
Right-click an image file (JPEG, PNG, etc.), and the OpenWith menu lets you choose to open the file using an image viewer (KView), editor (GIMP), slide show viewer (Kuickshow), or other application.
To make more applications available to you in the future, KDE provides a platform for developers to create programs that easily share information and detect how to deal with different data types. The things you can do with KDE grow every day.
KDE is the default desktop environment for SUSE, KNOPPIX, and several other Linux systems. It is available with Red Hat Enterprise Linux and Fedora Core but is not installed by default when they are installed as desktop systems (you need to do an
Everything install or to select to add KDE specifically in those cases). KDE also has a different look-and-feel in Red Hat systems than it does from implementation on other systems that deliver KDE desktops.
Note
The following section describes how to get started with KDE. This includes using the KDE Setup wizard, maneuvering around the desktop, managing files, and adding application launchers.
In this chapter, KNOPPIX is the reference model for the KDE descriptions. Because
KDE is very configurable, there may be some differences in these descriptions for
KDE in other Linux systems.
KDE as it’s delivered with KNOPPIX uses a lot of the design elements that come from the KDE project, so it’s pretty easy to distinguish from other desktop environments.
The look-and-feel has similarities to both Windows and Macintosh systems. Figure 3-3 shows an example of the KDE desktop in KNOPPIX:
Some of the key elements of the KDE desktop include:
✦
— The KDE panel (shown along the bottom of the screen) includes items that enable you to launch applications and to see minimized representations of active windows, applets, and virtual desktops. A “K” icon on the left side of the panel is used to represent the main menu on a KDE desktop. In KNOPPIX, that icon is followed by a KNOPPIX-specific menu (it looks like a squished penguin) and other icons to launch common applications (the file manager, Terminal window, Web browser, and office applications). Four virtual desktops (shown in little boxes numbered 1, 2, 3, and 4) are available by clicking on the number of the virtual desktop you want to display. Applets (on the right side of the panel) in KNOPPIX let you change your keyboard, set screen resolution, adjust audio controls, and view the time.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 83
Chapter 3
✦
Getting into the Desktop
83
✦
— The icons on the desktop are usually, by default, those that enable you to access removable media (CD, floppy disk, etc.), throw out files
(trash icon), and visit your home directory. In KNOPPIX, the KDE desktop also has a nice feature that lets you access your hard disk partitions directly from icons on the desktop.
✦
— Konqueror is the file manager window used with
KDE desktops. It not only can be used to manage files but also to display Web pages. Konqueror is described in detail later in this chapter.
✦
— Right-click the desktop to see a menu of common actions to take. The menu provides a quick way to access your bookmarks; create new folders, files, or devices (with devices, you’re actually choosing to mount a device on a particular part of the file system); straighten up your windows or icons; configure the desktop; and log out of your KDE session.
To navigate the KDE desktop, you can use the mouse or key combinations. The responses from the desktop to your mouse depend on which button you click and where the mouse pointer is located. Table 3-1 shows the results of clicking each mouse button with the mouse pointer placed in different locations. (You can change any of these behaviors from the Windows Behavior panel on the KDE
Control Center. From the KDE menu, select Settings
➪
Control Center, and then choose the Window Behavior selection under the Desktop heading.)
Figure 3-3:
The KDE desktop includes a panel, desktop icons, and menus.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 84
84
Part I ✦
Linux First Steps
Pointer Position
Window title bar or frame
(current window active)
Window title bar or frame
(current window active)
Window title bar or frame
(current window active)
Window title bar or frame
(current window not active)
Window title bar or frame
(current window not active)
Window title bar or frame
(current window not active)
Inner window (current window not active)
Inner window (current window not active)
Any part of a window
Any part of a window
On the desktop area
On the desktop area
Table 3-1
Mouse Button
Left
Result
Raises current window
Middle
Right
Left
Middle
Right
Left
Middle or
Right
Middle (plus hold Alt key)
Right (plus hold Alt key)
Left (hold and drag)
Right
Lowers current window
Opens operations menu
Activates current window and raises it to the top
Activates current window and lowers it
Opens operations menu without changing position
Activates current window, raises it to the top, and passes the click to the window
Activates current window and passes the click to the window
Toggles between raising and lowering the window
Resizes the window
Selects a group of icons
Opens system pop-up menu
Click a desktop icon to open it. Double-clicking a window title bar results in a window-shade action, where the window scrolls up and down into the title bar.
If you don’t happen to have a mouse or you just like to keep your hands on the keyboard, there are several keystroke sequences you can use to navigate the desktop.
Table 3-2 shows some examples.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 85
Chapter 3
✦
Getting into the Desktop
85
Key Result
Combination
Ctrl+Tab Step through the virtual desktops
Table 3-2
Directions
Alt+Tab
Alt+F2
Alt+F4
Ctrl+Alt+Esc
Ctrl+F1, F2,
F3 or F4 key
Alt+F3
Step through windows
Open Run Command box
Close current window
Close another window
Switch virtual desktops
Open window operation menu
To go from one virtual desktop to the next, hold down the Ctrl key and press the Tab key until you see the desktop that you want to make current. Then release the Ctrl key to select that desktop.
To step through each of the windows that are running on the current desktop, hold down the
Alt key and press the Tab key until you see the one you want. Then release the Alt key to select it.
To open a box on the desktop that lets you type in a command and run it, hold the Alt key and press F2. Next, type the command in the box and press Enter to run it. You can also type a URL into this box to view a Web page.
To close the current window, press Alt+F4.
To close an open window on the desktop, press
Ctrl+Alt+Esc. When a skull and crossbones appears as the pointer, move the pointer over the window you want to close and click the left mouse button. (This is a good technique for killing a window that has no borders or menu.)
Go directly to a particular virtual desktop by pressing and holding the Ctrl key and pressing one of the following: F1, F2, F3, or F4. These actions take you directly to desktops one, two, three, and four, respectively. You could do this for up to eight desktops, if you have that many configured.
To open the operations menu for the active window, press Alt+F3. When the menu appears, move the arrow keys to select an action (Move,
Size, Minimize, Maximize, and so on), and then press Enter to select it.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 86
86
Part I ✦
Linux First Steps
The Konqueror file manager helps elevate the KDE environment from just another
X window manager to an integrated desktop that competes with GUIs from Apple
Computing or Microsoft. The features in Konqueror rival those that are offered by those user-friendly desktop systems. Figure 3-4 shows an example of the Konqueror file manager window in Fedora Core.
Figure 3-4:
Konqueror provides a network-ready tool for managing files.
Tip
Some of Konqueror’s greatest strengths over earlier file managers are the following:
✦
— If your computer is connected to the Internet or a LAN, features built into Konqueror enable you to create links to files (using FTP) and Web pages (using HTTP) on the network and open them in the Konqueror window. Those links can appear as file icons in a Konqueror window or on the desktop. Konqueror also supports WebDAV, which can be configured to allow local read and write access to remote folders (which is a great tool if you are maintaining a Web server).
✦
— The Konqueror interface works like Mozilla, Internet
Explorer, or other Web browsers in the way you select files, directories, and
Web content. Because Konqueror is based on a browser model, a single click opens a file, a link to a network resource, or an application program. You can also open content by typing Web-style addresses in the Location box.
Web pages that contain Java and JavaScript content run by default in Konqueror. To check that Java and JavaScript support are turned on, choose Settings ➪ Configure
Konqueror. From the Settings window, click Java & JavaScript and select the Java tab. To enable Java, click the Enable Java Globally box and click Apply. Repeat for the JavaScript tab.
✦
— If you want a particular type of file to always be launched by a particular application, you can configure that file yourself. KDE already has dozens of MIME types defined so that particular file and data
08_579495 ch03.qxd 12/27/04 9:55 PM Page 87
Chapter 3
✦
Getting into the Desktop
87 types can be automatically detected and opened in the correct application.
There are MIME types defined for audio, image, text, video, and a variety of other content.
Of course, you can also perform many standard file manager functions with
Konqueror. For example, you can manipulate files by using features such as select, move, cut, paste, and delete; search directories for files; create new items (files, folders, and links, to name a few); view histories of the files and Web sites you have opened; and create bookmarks.
Because most of the ways of working with files in Konqueror are quite intuitive (by intention), here’s a quick rundown of how to do basic file manipulation:
To
Open a file
Open a file with a specific application
Delete a file
Copy a file
Paste a file
Link a file
Move a file
Copy a file
Create a link to a file
Do This
Double-click the file. It will open right in the Konqueror window, if possible, or in the default application set for the file type. You also can open directories, applications, and links by doubleclicking them.
Right-click a data file, choose Open With from the pop-up menu, and then select one of the available applications to open the file.
The applications listed are those that are set up to open the file.
Right-click the file and select Delete. You are asked if you really want to delete the file. Click Yes to permanently delete it.
Right-click the file and select Copy. This copies the file to your clipboard. After that, you can paste it to another folder. Click the
Klipper (clipboard) icon in the panel to see a list of copied files.
Klipper holds the seven most recent copied files, by default. Click the Klipper icon and select Configure Klipper to change the number of copied files Klipper will remember.
Right-click (an open area of a folder) and select Paste. A copy of the file you copied previously is pasted in the current folder.
Drag-and-drop a file from one folder to another. When the menu appears, click Link Here. (A linked file lets you access a file from a new location without having to make a copy of the original file.
When you open the link, a pointer to the original file causes it to open.)
With the original folder and target folder both open on the desktop, click and hold the left mouse button on the file you want to move, drag the file to an open area of the new folder, and release the mouse button. From the menu that appears, click Move. (You also can use this menu to copy or create a link to the file.)
08_579495 ch03.qxd 12/27/04 9:55 PM Page 88
88
Part I ✦
Linux First Steps
There are also several features for viewing information about the files and folders in your Konqueror windows:
✦
— Positioning the mouse pointer over the file displays information such as its file name, size, and type in the window footer.
✦
— Selecting View
➪
Show Hidden Files enables you to see files that begin with a dot ( .
). Dot files tend to be used for configuration and don’t generally need to be viewed in your daily work.
✦
— Selecting View
➪
View Mode
➪
Tree View provides a tree view of your folder, displaying folders above the current folder in the file system. You can click a folder in the tree view to jump directly to that folder.
There are also Multicolumn, Detailed List, and Text views available.
✦
— Select View
➪
Icon Size, and then choose Large, Medium, or
Small to set the size of the icons that are displayed in the window. You can also choose Default Size to return to the default icon size (which is medium, unless you have changed the default through the Configure Konqueror window).
To act on a group of files at the same time, there are a couple of actions you can take. Choose Edit
➪
Selection
➪
Select. A pop-up window lets you match all (*) or any group of documents indicated by typing letters, numbers, and wildcard characters. Or, you can select a group of files by clicking in an open area of the folder and dragging the pointer across the files you want to select. All files within the box will be highlighted. When files are highlighted, you can move, copy, or delete the files as described earlier.
If you are looking for a particular file or folder, you can use the Konqueror Find feature. To open a Find window to search for a file, open a local folder (such as
/home/chris ) and choose Tools
➪
Find File; the Find box will appear in your
Konqueror window. You could also start the kfind window by typing
from a
Terminal window.
Figure 3-5 shows the kfind window.
Simply type the name of the file you want to search for (in the Named text box) and the folder, including all subfolders, you want to search in (in the Look in text box).
Then click the Find button. Use metacharacters, if you like, with your search. For example, search for *.rpm
to find all files that end in .rpm
or z*.doc
to find all files that begin with z and end with .doc
. You can also select to have the search be casesensitive or click the Help button to get more information on searching.
To further limit your search, you can click the Date Range tab and then enter a date range (between), a number of months before today (during the previous
x
or the number of days before today (during the previous
x
months), days). Select the
Advanced tab to choose to limit the search to files of a particular type (of Type), files that include text that you enter (Containing Text), or that are of a certain size
(Size is) in kilobytes.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 89
Chapter 3
✦
Getting into the Desktop
89
Figure 3-5:
Search for files and folders from the kfind window.
You can create a variety of file types when using the Konqueror window. Choose
Edit
➪
Create New, and select Folder (to create a new folder) or one of several different types under the File or Device submenu. Depending on which version of
Konqueror you are using, you might be able to create some or all of the file types that follow:
✦
— Opens a dialog box that lets you type the name of an HTML file to create.
✦
— Opens a dialog box that lets you create a document in kontour format (an illustration). Type the document name you want to create and click OK. The document should have a to automatically open in kontour.
.kil
extension if you want it
✦
— Opens a window that lets you type the name of an application. Click the Permissions tab to set file permissions (Exec must be on if you want to run the file as an application). Click the Execute tab and type the name of the program to run (in the field: Execute on click) and a title to appear in the title bar of the application (in the field: Window Title). If it is a text-based command, select the Run in terminal check box. Click the check box to Run as a different user and add the user name. Click the Application tab to assign the application to handle files of particular MIME types. Click OK.
✦
— Selecting this menu item opens a dialog box that lets you create a link to a Web address. Type a name to represent the address and type the name of the URL (Web address) for the site. (Be sure to add the http:// , ftp:// , or other prefix.)
✦
— Opens a dialog box to create a document in kpresenter format (a presentation). Type the document name you want to create and click OK. The document should have a
.kpr
or
.kpt
extension if you want it to automatically open in kpresenter.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 90
90
Part I ✦
Linux First Steps
✦
— Opens a dialog box that lets you create a document in kspread format (a spreadsheet). Type the document name you want to create and click OK. The document should have a want it to automatically open in kspread.
.ksp
extension if you
✦
— Opens a dialog box that enables you to create a text document in KWord. Type a filename for the text file and click OK. The document should have a .txt
, .kwd
, or .kwt
extension if you want it to open automatically in KWord.
✦
— Opens a dialog box that lets you create a document in text format and place it in the Konqueror window. Type the name of the text document to create and click OK.
Under the Device submenu, you can make the following selections:
✦
— Opens a dialog box that lets you type a new CD-ROM device name. Click the Device tab and type the device name ( /dev/cdrom ), the mount point (such as
/mnt/cdrom or
/media/cdrom
), and the file system type (you can use iso9660 for the standard CD-ROM file system, ext2 for Linux, or msdos for DOS). When the icon appears, you can open it to mount the
CD-ROM and display its contents.
✦
— From the window that opens, enter the device name of your CD writer.
✦
— Opens a dialog box that lets you type a new CD-ROM or
DVD-ROM device name. Click the Device tab and type the device name
( /dev/cdrom ), the mount point (such as /mnt/cdrom or /media/cdrecorder ), and the file system type (you can use iso9660 for the standard CD-ROM file system, ext2 for Linux, or msdos for DOS). When the icon appears, you can open it to mount the CD-ROM or DVD-ROM and display its contents.
✦
— In the dialog box that opens, identify the device name for the camera devices that provides access to your digital camera.
✦
— Opens a dialog box in which you type a new floppy name.
Click the Device tab and type the device name ( /dev/fd0 ), the mount point
(such as
/mnt/floppy
), and the file system type (you can use auto to autodetect the contents, ext2 for Linux, or msdos for DOS). When the icon appears, open it to mount the floppy and display its contents.
✦
— Opens a dialog box that lets you type the name of a new hard disk or hard-disk partition. Click the Device tab and type the device
( /dev/hda1 ), the mount point (such as /mnt/win ), and the file system type
(you can use auto to autodetect the contents, ext2 or ext3 for Linux, or vfat for a Windows file system). When the icon appears, you can open it to mount the file system and display its contents.
Creating MIME types and applications is described later in this chapter.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 91
Chapter 3
✦
Getting into the Desktop
91
Because Konqueror performs like a Web browser as well as a file manager, it includes several other browser features. For example, the bookmarks feature enables you to keep a bookmark list of Web sites you have visited. Click Bookmarks, and a dropdown menu of the sites you have bookmarked appears. Select from that list to return to a site. There are several ways to add and change your bookmarks list:
✦
— To add the address of the page that is currently being displayed to your bookmark list, choose Bookmarks
➪
Add Bookmark. The next time you click Bookmarks, you will see the bookmark you just added on the
Bookmarks menu. In addition to Web addresses, you can also bookmark any file or folder.
✦
— Select Bookmarks
➪
Edit Bookmarks to open a tree view of your bookmarks. From the Bookmark Editor window that appears, you can change the URLs, the icon, or other features of the bookmark. There is also a nice feature that lets you check the status of the bookmark (that is, the address available).
✦
— You can add a new folder of bookmarks to your
Konqueror bookmarks list. To create a bookmarks folder, choose
Bookmarks
➪
New Folder. Then type a name for the new Bookmarks folder, and click OK. The new bookmark folder appears on your bookmarks menu. You can add the current location to that folder by clicking on the folder name and selecting Add Bookmark.
You can change many of the visual attributes of the Konqueror window, including which menu bars and toolbars appear. You can have any of the following bars appear on the Konqueror window: Menubar, Toolbar, Extra Toolbar, Location
Toolbar, Bookmark Toolbar. Select Settings, and then click the bar you want to have appear (or not appear). The bar appears when the check mark is shown next to it.
You can modify a variety of options for Konqueror by choosing Settings
➪
Configure
Konqueror. The Konqueror Settings window appears, offering the following options:
✦
— Change file manager behavior.
✦
— Change file manager fonts and colors.
✦
— An icon in a Konqueror folder can be made to resemble the contents of the file it represents. For example, if the file is a JPEG image, the icon representing the file could be a small version of that image. Using the
Previews features, you can limit the size of the file used (1MB is the default) because many massive files could take too long to refresh on the screen. You can also choose to have any thumbnail embedded in a file to be used as the icon or have the size of the icon reflect the shape of the image used.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 92
92
Part I ✦
Linux First Steps
✦
— Describes which programs to launch for each file type.
✦
— Click the Behavior (Browser) button to open a window to configure the Web browser features of Konqueror. By enabling Form Completion,
Konqueror can save form data you type and, at a later time, fill that information into other forms. If your computer has limited resources, you can speed up page display by clearing the Automatically Load Images check box or by disabling animations.
✦
— Enable or disable Java and JavaScript content contained in Web pages in your Konqueror window.
✦
— Choose which fonts to use, by default, for various fonts needed on
Web pages (standard font, fixed font, serif font, sans serif font, cursive font, and fantasy font). The serif fonts are typically used in body text, while sans serif fonts are often used in headlines. You can also set the Minimum and
Medium font sizes.
✦
— Display a list of keyword shortcuts you can use to go to different Internet sites. For example, follow the word “ask” with a search string to search the Ask Jeeves ( www.ask.com
) Web site. (This feature doesn’t appear to be working at the moment.)
✦
— Modify the behavior of the list of sites you have visited
(the history). By default, the most recent 500 URLs are stored, and after 500 days (KNOPPIX) or 90 days (Fedora), a URL is dropped from the list. There’s also a button to clear your history. (To view your history list in Konqueror, open the left side panel, then click the tiny scroll icon.)
✦
— Choose whether cookies are enabled in Konqueror. By default, you are asked to confirm that it is okay each time a Web site tries to create or modify a cookie. You can change that to either accept or reject all cookies.
You can also set policies for acceptance or rejection of cookies based on host and domain names.
✦
— Indicate how much space on your hard disk can be used to store the sites you have visited (based on the value in the Disk Cache Size field).
✦
— Click Proxy to configure Konqueror to access the Internet through a proxy server (by default, Konqueror tries to connect there directly). You need to enter the address and port number of the computer providing HTTP and/or
FTP proxy services. Alternatively, you can have Konqueror try to automatically detect the proxy configuration.
✦
Choose whether to use the default stylesheet, a user-defined stylesheet, or a custom stylesheet. The stylesheet sets the font family, font sizes, and colors that are applied to Web pages. (This won’t change particular font requests made by the Web page.) If you select a custom stylesheet, click the Customize tab to customize your own fonts and colors.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 93
Chapter 3
✦
Getting into the Desktop
93
✦
— Display a list of secure certificates that can be accepted by the
Konqueror browser. By default, Secure Socket Layer (SSL) versions 2 and 3 certificates are accepted, as is TLS support (if supported by the server). You can also choose to be notified when you are entering or leaving a secure Web site.
✦
— Set how Konqueror identifies itself when it accesses a Web site. By default, Konqueror tells the Web site that it is the Mozilla Web browser. You can select Konqueror to appear as different Web browsers to specific sites. You must sometimes do this when a site denies you access because you do not have a specific type of browser (even though Konqueror may be fully capable of displaying the content).
✦
— Display a list of directories that Konqueror will search to find plugins. Konqueror can also scan your computer to find plug-ins that are installed for other browsers in other locations.
✦
— Display configuration settings that can be used to improve
Konqueror performance. You can preload an instance after KDE startup or minimize memory usage.
If you have a lot of windows open at the same time, tips for organizing and managing the windows on your desktop are very helpful. KDE helps you out by maintaining window lists you can work with and shortcuts for keeping the windows in order.
When you open a window, a button representing the window appears in the taskbar at the bottom of the screen. Here is how you can manage windows from the taskbar:
✦
— Left-click any running task in the taskbar to toggle between opening the window and minimizing it.
✦
— Move a window from the current desktop to any other virtual desktop. Right-click any task in the taskbar, select To Desktop, and then select any desktop number. The window moves to that desktop.
All the windows that are running, regardless of which virtual desktop you are on, appear in the taskbar. If there are multiple windows of the same type shown as a single task, you can right-click that task; then, select All to Desktop to move all related windows to the desktop you pick.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 94
94
Part I ✦
Linux First Steps
There’s a neat feature in Konqueror that lets you create a quick image gallery. The feature takes a directory of images, creates thumbnails for each one, and generates an HTML (Web) page. The HTML page includes a title you choose, all image thumbnails arranged on a page, and links to the larger images. Here’s how you do it:
1.
Add images you want in your gallery to any folder (for example,
/home/jake/images
).
Make sure they are sized, rotated, and cropped the way you like before beginning. (Try
The Gimp for manipulating your images by typing gimp& from a Terminal.)
2.
Open the folder in Konqueror (for example, type /home/knoppix/images in the
Location box).
3.
Click Tools
➪
Create Image Gallery. The Create Image Gallery window appears.
4.
Type a title for the image gallery into the Page Title box. You can also select other attributes of the gallery, such as the number of rows, information about the image to appear on the page (name, size, and dimension), the fonts, and the colors to use.
5.
Click OK.
Konqueror generates the thumbnails and adds them to the thumbs directory. The image gallery page itself opens and is saved to the images.html
file. (Select the Folders button to save the gallery under a different name. You can also have Konqueror create galleries in recursive subfolders to a depth you choose.) You can now copy the entire contents of this directory to a Web server and publish your pictures on the Internet. Here’s an example of a
Konqueror image gallery:
08_579495 ch03.qxd 12/27/04 9:55 PM Page 95
Chapter 3
✦
Getting into the Desktop
95
If your windows are scattered willy-nilly all over the desktop, here are a couple of ways you can make your desktop’s appearance a little neater:
✦
— Right-click the desktop, and then click Windows
➪
Unclutter Windows on the menu. All windows that are currently displayed on the desktop are lined up along the left side of the screen (or aligned with other windows), from the top down.
✦
— Right-click the desktop, and then click Windows
➪
Cascade windows on the menu. The windows are aligned as they are with the
Unclutter selection, except that the windows are each indented starting from the upper-left corner.
The easiest way to move a window from one location to another is to place the cursor on the window’s title bar, hold down the mouse button and drag the window to a new location, and release the mouse button to drop the window. Another way to do it is to click the window menu button (top-left corner of the title bar), select
Move, move the mouse to relocate the window, and then click again to place it.
If somehow the window gets stuck in a location where the title bar is off the screen, you can move it back to where you want it by holding down the Alt key and clicking the left mouse button in the inner window. Then move the window where you want it and release.
To resize a window, grab anywhere on the outer edge of the window border, and then move the mouse until the window is the size you want. Grab a corner to resize vertically and horizontally at the same time. Grab a side to resize in only one direction.
You can also resize a window by clicking the window menu button (top-left corner of the title bar) and selecting Size. Move the mouse until the window is resized and click to leave it there.
You can set a window to always stay on top of all other windows or always stay under them. Keeping a window on top can be useful for a small window that you want to always refer to (such as a clock or a small TV viewing window). To pin a window on top of the desktop, click in the window title bar. From the menu that appears, select Advanced
➪
Keep Above Others. Likewise, to keep the window on the bottom, select Advanced
➪
Keep Below Others.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 96
96
Part I ✦
Linux First Steps
To give you more space to run applications than will fit on your physical screen,
KDE gives you access to several virtual desktops at the same time. Using the 1, 2, 3, and 4 buttons on the panel, you can easily move between the different desktops.
Just click the one you want.
If you want to move an application from one desktop to another, you can do so from the window menu. Click the window menu button for the window you want to move, click To Desktop, and then select Desktop 1, 2, 3, or 4. The window will disappear from the current desktop and move to the one you selected.
If you want to change the look, feel, or behavior of your KDE desktop, the best place to start is the KDE Control Center. The Control Center window (Figure 3-6) lets you configure dozens of attributes associated with colors, fonts, backgrounds, and screen savers. You can also change attributes relating to how you work with windows and files.
To open the KDE Control Center from the desktop, select Settings
➪
Control Center from the K menu or open a Terminal window and type
.
Figure 3-6:
Manage your KDE desktop from the KDE
Control Center.
Click the plus (+) sign next to the topic you want to configure, and then select the particular item you want to configure. The following sections describe some of the features you can configure from the Control Center.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 97
Chapter 3
✦
Getting into the Desktop
97
You can change a lot of the look-and-feel of your desktop display. Under the
Appearance & Themes topic (click the plus sign), you can change Background,
Colors, Fonts, Icons, Launch Feedback, Panel, Screen Saver, Style, Theme Manager, and Window Decoration.
Tip
Tip
Here are a few of the desktop features you may want to change:
✦
— Under the Appearance & Themes heading in the KDE Control
Center, select Background. By default, all of your virtual desktops use the same background. To have different backgrounds for each virtual desktop, select the box next to the Setting for Desktop heading, choose any of the four desktops, and then choose the background you want for the current desktop.
For each desktop, select Picture, Slideshow, or No Picture. For a Picture, there are several backgrounds you can choose from the pull-down menu, or you can browse your file system for a picture. To do a slide show, click Slideshow and select Setup (to choose your pictures and define how often they change).
Click Apply to apply your selections.
✦
— Under the Appearance & Themes heading, select Screen Saver.
From the window that appears, select from a list of screen savers. KNOPPIX only includes a blank screen saver. However, Fedora Core comes with about
160 different screen savers. My favorite is Slideshow, where you can have a slide show of images for your screen saver. Click Setup to identify an image directory or otherwise modify the behavior of the screen saver. Under settings, select how many minutes of inactivity before the screen saver turns on.
You can also choose Require Password to require that a password be entered before you can access your display after the screen saver has come on.
If you are working in a place where you want your desktop to be secure, be sure to turn on the Require Password feature. This prevents others from gaining access to your computer when you forget to lock it or shut it off. If you have any virtual terminals open, switch to them and type vlock to lock each of them as well. (You need to install the vlock package if the vlock command isn’t available.)
✦
— You can assign different fonts to different places in which fonts appear on the desktop. Under the Appearance & Themes heading, select
Fonts. Select one of the categories of fonts (General, Fixed width, Toolbar,
Menu, Window title, Taskbar, and Desktop fonts). Then click the Choose check box to select a font from the Select Font list box that you want to assign to that category. If the font is available, an example of the text appears in the
Sample text box.
To use 100dpi fonts, you need to add an entry for 100dpi fonts to
/etc/X11/ xorg.conf
to take effect.
file. After you make that change, you need to restart the X server for it
08_579495 ch03.qxd 12/27/04 9:55 PM Page 98
98
Part I ✦
Linux First Steps
Other attributes you can change for the selected fonts are size (in points) and character set (to select an ISO standard character set). Select Apply to apply the changes.
✦
— Under the Appearance & Themes heading, select Colors. The window that appears lets you change the color of selected items on the desktop.
Select a whole color scheme from the Color Scheme list box. Or select an item from the Widget color box to change a particular item. Items you can change include text, backgrounds, links, buttons, and title bars.
For most people, the panel is the place where they select which desktop is active and which applications are run. You can change panel behavior from the Configure Panel window. Right-click any empty space on your panel, and then select Configure Panel.
You can change these features from the Settings window that appears:
✦
— Change the location of the panel by clicking Top, Left, Bottom, or Right in the Panel Location list box. The Panel Style selection lets you change the size of the Panel from Medium to Tiny, Small, or Large.
✦
— Certain selections enable you to autohide the panel or use hide buttons. Under the Hide Mode heading, choose whether to hide only when a panel hiding button is clicked or to hide automatically after a set number of seconds when the cursor is not in the panel area. You can also show or not show hiding buttons. Sliders let you select the delay and speed at which panels and buttons are hidden.
✦
— Unlike with the GNOME main menu, you have the capability to manipulate the main menu from the GUI in KDE. Click the Edit K Menu button.
The KDE Menu editor that appears lets you cut, copy, paste, remove, and modify submenus and applications from your main menu.
You want to be able to quickly access the applications that you use most often. One of the best ways to make that possible is to add icons to the panel or the desktop that can launch the applications you need with a single click. Procedures for adding applications to the panel and desktop are described in the following sections.
You can add any KDE application to the KDE panel quite easily. Here’s how:
Right-click an open space on the panel.
Choose Add
➪
Application Button.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 99
Chapter 3
✦
Getting into the Desktop
99
Select one of the categories of applications.
Select any application from that category (or select Add This Menu To Add the Whole Menu of Applications).
An icon representing the application immediately appears on the panel. (If the panel seems a bit crowded, you might want to remove some applications you don’t use.)
If you decide later that you no longer want this application to be available on the panel, right-click the edge of the icon and click the Remove button. To move it to a different location on the panel, right-click it, click Move, move it to where you want it on the panel, and click again.
To add an application to the desktop, use the desktop menu. Here’s how:
Right-click an open area of the desktop.
Select Create New
➪
File
➪
Link to Application from the menu.
On the Properties window that appears, click the General tab and replace Link to Application with the name you want to appear for the application on the desktop. On that same tab, click the gear icon and select one icon from the list to represent your application.
Click the Application tab and add a description of the application and a comment. Then in the Command box, type the command you want to run or browse your file system (click the Browse button) to find the command to run.
Click OK, and the icon for the new application launcher appears on the desktop.
If you decide later that you no longer want this application to be available on the desktop, right-click the icon and click Delete or Move to Trash.
GNOME (pronounced
guh-nome
) provides the desktop environment that you get by default when you install Fedora Core and other Red Hat Linux systems. This desktop environment provides the software that is between your X Window System framework and the look-and-feel provided by the window manager. GNOME is a stable and reliable desktop environment, with a few cool features in it.
The new GNOME 2.8 desktop comes with the most recent version of Fedora Core.
For GNOME 2.8, enhancements include a new volume manager (for managing removable media), keyring manager (for managing keys), and remote desktop
08_579495 ch03.qxd 12/27/04 9:55 PM Page 100
100
Part I ✦
Linux First Steps
preferences. To use your GNOME desktop, you should become familiar with the following components:
✦
— The default window manager for GNOME in
Fedora is Metacity. It provides such things as themes, and window borders and controls.
✦
— When you open a folder (by double-clicking the Home icon on your desktop, for example), the Nautilus window opens and displays the contents of the selected folder. Nautilus can also display other types of content, such as shared folders from Windows computers on the network (using SMB).
✦
— This panel, which lines the bottom of your screen, is designed to make it convenient for you to launch the applications you use, manage running applications, and work with multiple virtual desktops. By default, the panel contains the main menu (represented by a red hat in Red Hat Linux or a footprint icon in others), desktop application launchers (Evolution e-mail and a set of OpenOffice.org applications), a workspace switcher (for managing four virtual desktops), window list, and a clock. It also has an icon to alert you when you need software updates.
✦
— The windows and icons you use are arranged on the desktop area, which supports such things a drag-and-drop between applications, a desktop menu (right-click to see it), and icons for launching applications.
There is a Computer icon which consolidates CD drives, floppy drives, the file system, and shared network resources in one place.
GNOME also includes a set of Preferences windows that enable you to configure different aspects of your desktop. You can change backgrounds, colors, fonts, keyboard shortcuts, and other features relating to the look and behavior of the desktop. Figure 3-7 shows how the GNOME desktop environment appears the first time you log in, with a few windows added to the screen.
The following sections provide details on using the GNOME desktop.
The Metacity window manager seems to have been chosen as the default window manager for GNOME in Red Hat Linux because of its simplicity. The creator of
Metacity refers to it as a “boring window manager for the adult in you” — then goes on to compare other window managers to colorful, sugary cereal, while Metacity is characterized as Cheerios.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 101
Chapter 3
✦
Getting into the Desktop
101
Desktop icons
Nautilus file manager
Desktop area Preferences window
Panel
Red Hat main menu
E-mail Impress
Writer
Print manager
Window list Red Hat network alert notification
Web browser
Calc Workspace switcher
Clock
Figure 3-7:
In the GNOME desktop environment, you can manage applications from the panel.
There really isn’t much you can do with Metacity (except get your work done efficiently). Assigning new themes to Metacity and changing colors and window decorations is done through the GNOME preferences (and is described later). A few
Metacity themes exist, but expect the number to grow.
Basic Metacity functions that might interest you are keyboard shortcuts and the workspace switcher. Table 3-3 shows keyboard shortcuts to get around the
Metacity window manager.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 102
102
Part I ✦
Linux First Steps
Actions
Window focus
Panel focus
Workspace focus
Show window menu
Close menu
Table 3-3
Keystrokes
Cycle forward, with pop-up icons
Cycle backward, with pop-up icons
Cycle forward, without pop-up icons
Cycle backward, without pop-up icons
Cycle forward among panels
Cycle backward among panels
Move to workspace to the right
Move to workspace to the left
Move to upper workspace
Move to lower workspace
Minimize/maximize all windows
Alt-Space bar
Esc
Alt+Tab
Alt+Shift+Tab
Alt+Esc
Alt+Shift+Esc
Alt+Ctrl+Tab
Alt+Ctrl+Shift+Tab
Ctrl+Alt+right arrow
Ctrl+Alt+left arrow
Ctrl+Alt+up arrow
Ctrl+Alt+down arrow
Ctrl+Alt+D
Another Metacity feature of interest is the workspace switcher. Four virtual workspaces appear in the workspace switcher on the GNOME panel. Here are some things to do with the workspace switcher:
✦
Four virtual workspaces appear in the workspace switcher. Click any of the four virtual workspaces to make it your current workspace.
✦
— Click any window, each represented by a tiny rectangle in a workspace, to drag-and-drop it to another workspace.
✦
— Right-click the workspace switcher, and select
Preferences. You can add workspaces (up to 32).
✦
— Right-click the workspace switcher and select
Preferences. Click in the Workspaces pane to change names of workspaces to any names you choose.
You can view and change information about Metacity controls and settings using the gconf-editor window (type
from a Terminal window). As the window says, it is not the recommended way of changing preferences, so when possible, you should change the desktop through GNOME preferences. However, gconf-editor is a good way to see descriptions of each Metacity feature.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 103
Chapter 3
✦
Getting into the Desktop
103
From the gconf-editor window, select apps
➪ metacity, and then choose from general, global_keybindings, keybindings_commands, window_keybindings, and workspace_names. Click each key to see its value, along with short and long descriptions of the key.
The GNOME panel is the place from which you manage your desktop. From this panel you can start applications (from buttons or menus), see what programs are active, and monitor how your system is running. There are also many ways to change the panel — by adding applications or monitors, or by changing the placement or behavior of the panel, for example.
Right-click any open space on the panel to see the Panel menu (see Figure 3-8).
Figure 3-8:
The GNOME panel menu.
From GNOME’s Panel menu, you can perform a variety of functions, including:
✦
The main menu (represented by a red hat in Red Hat systems) displays most of the applications and system tools you will use from the desktop.
✦
Add an applet, menu, launcher, drawer, or button.
✦
Delete the current panel.
✦
Change the panel’s position, size, and background properties.
✦
Add panels to your desktop in different styles and locations.
You can also work with items on a panel. For example, you can:
✦
Move items on a panel simply by dragging and dropping them to new positions.
✦
Some elements, such as the Window List, can be resized by clicking an edge and dragging it to the new size.
✦
Tasks running on the desktop appear in the Window
List area. Click a task to minimize or maximize it.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 104
104
Part I ✦
Linux First Steps
The following sections describe some things you can do with the GNOME panel.
Click the main menu icon on the panel, and you see categories of applications and system tools that you can select. Click the application you want to launch. To add an item to launch from the panel — and to view its properties — right-click it. There is currently no way to add or remove applications to or from this menu from the
GUI in GNOME. However, you can manually add items to your GNOME menus.
To add to the main menu, create a
.desktop
file in the
/usr/share/applications directory. The easiest way to do that is to copy an existing .desktop
file that is on the menu you want and modify it. For example, to add a video player to the Sound
& Video menu, you could do the following (as root user):
#
cd /usr/share/applications
#
cp gnome-cd.desktop vidplay.desktop
Next use any text editor to change the contents of the vidplay.desktop
file you created by adding a comment, file to execute, icon to display, and application name.
After you save the changes, the new item immediately appears on the menu (no need to restart anything).
There are several small applications, called
applets,
that you can run directly on the
GNOME panel. These applications can show information you may want to see on an ongoing basis or may just provide some amusement. To see what applets are available and to add applets that you want to your panel, perform the following steps:
Right-click an open space in the panel so that the panel menu appears.
Select Add to Panel. An Add to Panel window appears.
Select from among several dozen applets, including a clock, dictionary lookup, stock ticker, weather report, lock screen, log out, run application, take screen shot, fortune-telling fish, eyes that follow your mouse, e-mail Inbox monitor, and modem lights monitor. The applet appears on the panel, ready for you to use.
Figure 3-9 shows (from left to right) eyes, system monitor, CD player, stock ticker, e-mail Inbox monitor, and dictionary lookup applets.
Figure 3-9:
Placing applets on the Panel makes it easy to access them.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 105
Chapter 3
✦
Getting into the Desktop
105
After an applet is installed, right-click it on the panel to see what options are available. For example, select Preferences for the stock ticker, and you can add or delete stocks whose prices you want to monitor. If you don’t like the applet’s location, right-click it, click Move, slide the mouse until the applet is where you want it
(even to another panel), and click to set its location.
If you no longer want an applet to appear on the panel, right-click it, and then click
Remove From Panel. The icon representing the applet disappears. If you find that you have run out of room on your panel, you can add a new panel to another part of the screen, as described in the next section.
You can have several panels on your GNOME desktop. You can add panels that run along the entire bottom, top, or side of the screen. To add a panel, do the following:
Right-click an open space in the panel so that the Panel menu appears.
Select New Panel. A new panel appears at the top of the screen.
Right-click an open space in the new panel and select Properties.
From the Panel Properties, select where you want the panel from the
Orientation box (Top, Bottom, Left or Right).
After you’ve added a panel, you can add applets or application launchers to it as you did to the default panel. To remove a panel, right-click it and select Delete
This Panel.
Icons on your panel represent a Web browser and several office productivity applications. You can add your own icons to launch applications from the panel as well.
To add a new application launcher to the panel, do the following:
Right-click in an open space on the panel.
Select Add to Panel
➪
Application Launcher from the menu. All application categories from your main desktop menu (the one under the red hat or footprint icon) appear.
Select the arrow next to the category of application you want, and then select
Add. An icon representing the application appears.
To launch the application you just added, simply click the icon on the panel.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 106
106
Part I ✦
Linux First Steps
If the application you want to launch is not on your red hat menu, you can build a launcher yourself as follows:
Right-click in an open space on the panel.
Select Add to Panel
➪
Custom Application Launcher
➪
Add. The Create
Launcher window appears.
Provide the following information for the application that you want to add:
— A name to identify the application (this appears in the tool tip when your mouse is over the icon).
— A name to identify the type of application.
— A comment describing the application. It also appears when you later move your mouse over the launcher.
— The command line that is run when the application is launched. Use the full path name, plus any required options.
— Select Application (to launch an application). (Other selections include Link, to open a Web address in a browser, or FSDevice, to open a file system.)
— Click this box if the application is a character-based or ncurses application. (Applications written using the curses library run in a Terminal window but offer screen-oriented mouse and keyboard controls.)
Click the Icon box (it might say No Icon). Select one of the icons shown and click OK. Alternatively, you can browse the Linux file system to choose an icon.
Note
Icons available to represent your application are contained in the /usr/share/ pixmaps directory. These icons are either in
.png
or
.xpm
formats. If there isn’t an icon in the directory you want to use, create your own (in one of those two formats) and assign it to the application.
Click OK.
The application should now appear in the panel. Click it to start the application.
A drawer is an icon that you can click to display other icons representing menus, applets, and launchers; it behaves just like a panel. Essentially any item you can add to a panel you can add to a drawer. By adding a drawer to your GNOME panel, you can include several applets and launchers that together take up only the space of one icon. Click on the drawer to show the applets and launchers as though they were being pulled out of a drawer icon on the panel.
To add a drawer to your panel, right-click the panel and select Add to Panel
➪
Drawer.
A drawer appears on the panel. Right-click it, and add applets or launchers to it as you would to a panel. Click the icon again to retract the drawer.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 107
Chapter 3
✦
Getting into the Desktop
107
Figure 3-10 shows a portion of the panel with an open drawer that includes icons for launching a Terminal window, the GIMP, and the Ethereal window.
Figure 3-10:
Add launchers or applets to a drawer on your GNOME panel.
Tip
Panel properties you can change are limited to the orientation, size, hiding policy, and background. To open the Panel Properties window that applies to a specific panel, right-click on an open space on the panel and choose Properties. The Panel
Properties window that appears includes the following values:
✦
— Contains a name by which you identify this panel.
✦
— Move the panel to different locations on the screen by clicking on a new position.
✦
— Select the size of your panel by choosing its height in pixels (48 pixels by default).
✦
— Click this check box to have the panel expand to fill the entire side, or unselect the check box to make the panel only as wide as the applets it contains.
✦
— Select whether a panel is automatically hidden (appearing only when the mouse pointer is in the area).
✦
— Choose whether the Hide/Unhide buttons (with pixmap arrows on them) appear on the edges of the panel.
✦
— If you select Show Hide Buttons, you can choose to have arrows on those buttons.
✦
—From the Background tab, you can assign a color to the background of the panel, assign a pixmap image, or just leave the default (which is based on the current system theme). Click the Background Image check box if you want to select an Image for the background, and then select an image, such as a tile from /usr/share/backgrounds/tiles or other directory.
I usually turn on the AutoHide feature and turn off the Hide buttons. Using
AutoHide gives you more desktop space to work with. When you move your mouse to the edge where the panel is, the panel pops up — so you don’t need
Hide buttons.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 108
108
Part I ✦
Linux First Steps
At one time, file managers did little more than let you run applications, create data files, and open folders. These days, as the information a user needs expands beyond the local system, file managers are expected to also display Web pages, access FTP sites, and play multimedia content. The Nautilus file manager, which is the default GNOME file manager, is an example of just such a file manager.
When you open the Nautilus file manager window (from the GNOME main menu or by opening the Home icon or other folder on your desktop), you see the name of the location you are viewing (such as the folder name) and what that location contains (files, folders, and applications). Figure 3-11 is an example of the file manager window displaying the home directory of a user named chris ( /home/chris ).
Figure 3-11:
The Nautilus file manager enables you to move around the file system, open directories, launch applications, and open Samba folders.
In GNOME 2.8, the default Nautilus window has been greatly simplified to show fewer controls and provide more space for file and directory icons. Double-click a folder to open that folder in a new window. Select your folder name in the lower-left corner of the window to see the file system hierarchy above the current folder (as shown in Figure 3-11). Whatever size, location, and other setting you had for the folder the last time you closed it, GNOME remembers and returns it to that state the next time you open it.
To see more controls, right-click a folder and select Browse Folder to open it. Icons on the toolbar of the Nautilus window let you move forward and back among the directories and Web sites you visit. To move up the directory structure, click the up arrow. To refresh the view of the folder or Web page, click the Reload button. The
Home button takes you to your home page, and the Computer button lets you see the same type of information you would see from a My Computer icon on a Windows system (CD drive, floppy drive, hard disk file systems, and network folders).
08_579495 ch03.qxd 12/27/04 9:55 PM Page 109
Chapter 3
✦
Getting into the Desktop
109
Icons in Nautilus often indicate the type of data that a particular file contains. The contents or file extension of each file can determine which application is used to work with the file, or you can right-click an icon to open the file it represents with a particular application or viewer.
Here are some of the more interesting features of Nautilus:
✦
— From the Browse Folder view described previously, select View
➪
Side Pane to have a sidebar appear in the left column of the screen. From the sidebar, you can click a pull-down menu that represents different types of information you can select one at a time.
The Tree tab, for example, shows a tree view of the directory structure, so you can easily traverse your directories. The Notes tab lets you add notes that become associated with the current Directory or Web page, and the
History tab displays a history of directories and Web sites you have visited, enabling you to click those items to return to the sites they represent. There is also an Emblems tab that lets you drag-and-drop emblems on files or folders to indicate something about the file or folder (emblems include icons representing drafts, urgent, bug, and multimedia).
✦
— If your computer is connected to a LAN on which Windows computers are sharing files and printers, you can view those resources from Nautilus. Type
in the Open Location box (select
File
➪
Open Location to get there) to see available workgroups. Click a workgroup to see computers from that workgroup that are sharing files and printers. Figure 3-12 shows an example of Nautilus displaying icons representing
Windows computers in a workgroup called estreet ( smb://estreet ).
Figure 3-12:
Display shared Windows file and printer servers
(SMB) in Nautilus.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 110
110
Part I ✦
Linux First Steps
✦
— To handle different types of content that may be encountered in the Nautilus window, you can set applications to respond based on MIME type and file type. With a folder being displayed, right-click a file for which you want to assign an application. Click either Open With an
Application or Open With a Viewer. If no application or viewer has been assigned for the file type, click Associate Application to be able to select an application. From the Add File Types window, you can add an application based on the file extension and MIME type representing the file.
✦
— You can use drag-and-drop within the Nautilus window, between the Nautilus and the desktop, or among multiple Nautilus windows.
As other GNOME-compliant applications become available, they are expected to also support the drag-and-drop feature.
If you would like more information on the Nautilus file manager, visit the GNOME
Web site ( www.gnome.org/nautilus ).
There are many ways to change the behavior, look, and feel of your GNOME desktop.
Most GNOME preferences can be modified from the Preferences window. The easiest way to access that is to type
in the Nautilus Open Location box.
Unlike earlier versions of GNOME for Fedora Core and Red Hat Linux, boundaries between preferences relating to the window manager (Metacity), file manager
(Nautilus), and the GNOME desktop itself have been blurred. Preferences for all of these features are in the Preferences window. Figure 3-13 shows the Preferences window, with icons that represent features you can change.
Figure 3-13:
Change the look-and-feel of your desktop from the
Preferences window.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 111
Chapter 3
✦
Getting into the Desktop
111
The following items highlight some of the preferences you might want to change:
✦
— If you have difficulty operating a mouse or keyboard, the
Keyboard Accessibility Preferences (AccessX) window lets you adapt mouse and keyboard settings to make it easier for you to operate your computer.
From the Preferences window, open Accessibility.
✦
— From Desktop Background Preferences, you can choose a solid color or an image to use as wallpaper. If you choose to use a solid color (by selecting No Wallpaper), click the Color box, select a color from the palette, and click OK.
To use wallpaper for your background, open the folder containing the image you want to use, and then drag the image into the Desktop Wallpaper pane on the Desktop Preferences window. You can choose from a variety of images in the /usr/share/nautilus/patterns and /usr/share/backgrounds/tiles directories. Then choose to have the wallpaper image tiled (repeated pattern), centered, scaled (in proportion), or stretched (using any proportion to fill the screen).
✦
— Even if you don’t change CD properties, it is important to know what happens when you insert a CD or DVD. (These properties are associated with a feature called magicdev, which is a bit controversial.
You’ll learn more about magicdev in Chapter 19.)
• For data CDs, the CD is mounted when it is inserted, any autorun program on the CD is run, and a file manager window opens for the CD. If you would rather mount and open the CD as you choose, you can turn off any or all of these preferences.
• For audio CDs, the gnome-cd player is launched and the CD begins playing. You can type in a different CD player, if you like, or clear the Run
Command When CD Is Inserted check box so that you can choose which player to use later.
• For blank CDs, a CD-burning utility is launched through the Nautilus window. After that, you can burn audio files or data to the blank CD.
• For DVD (video), the DVD is not set to play automatically. If you have a player installed that can play the content of DVDs that you have, turn on this feature and add the command to run the player into the Command box. For a data DVD, such as the one that comes with this book, you can simply mount it to access the data.
✦
— The File Types and Programs preferences can help you understand the different types of data files that GNOME knows about. Double-click this icon to see data types (audio, documents, images, information, and so on) that have definitions in GNOME. Then choose a particular data type (such as Audio, ogg audio).
From the Edit File Type window that appears, you can see the information assigned to the file type. For example, when data that ends with an .ogg
08_579495 ch03.qxd 12/27/04 9:55 PM Page 112
112
Part I ✦
Linux First Steps
extension appears in a Nautilus window, you can see the icon that will represent the file, the mime type assigned to the file, and the action (if any) that’s taken when you open the file.
You can modify any file type that appears in these preferences windows. You can choose what applications are run and what icons represent data of that type. You can even create your own data types.
✦
— Choose from dozens of screensavers from the Screensaver window. Select Random Screensaver to have your screen saver chosen randomly from those you mark with a check, or select one that you like from the list to use all the time. Next, choose how long your screen must be idle before the screensaver starts (default is 10 minutes). For random screen savers, you can select how long before cycling to the next screen saver. You can also choose to require a password or to enable power management to shut down your monitor after a set number of minutes (Advanced Tab). Figure 3-14 shows the Screensaver Preferences dialog box.
Figure 3-14:
Select specific or random screen savers from the
Screensaver Preferences dialog box.
✦
— Choose an entire theme of elements to be used on your desktop, if you like. A desktop theme affects not only the background but also the way that many buttons and menu selections appear. There are only a few themes available for the window manager (Metacity) in the Fedora Core
08_579495 ch03.qxd 12/27/04 9:55 PM Page 113
Chapter 3
✦
Getting into the Desktop
113 distribution, but you can get a bunch of other themes from themes.
freshmeat.net
(click on Metacity).
Click Install theme, and then click the Window Border tab to select from different themes that change the title bar and other borders of your windows. Click the Icons tab to choose different icons to represent items on your desktop.
Themes change immediately as you click or when you drag a theme name on the desktop.
When you are done with your work, you can either log out from your current session or shut down your computer completely. To exit from GNOME, do the following:
Tip
Click the red hat menu button.
Select Log Out from the menu. A pop-up window appears, asking if you want to Log Out, Shut Down, or Restart the computer.
At this point, you can also choose to save your session by clicking Save Current
Setup. This is a great way to have the applications that you use all the time restart the next time you log in. Make sure you save your data before you exit, however.
Most applications do not yet support the data-saving feature.
Select Log Out from the pop-up menu. This logs you out and returns you to either the graphical login screen or to your shell login prompt. (If you select
Shut Down, the system shuts down, and if you select Reboot, the system restarts.)
Select OK to finish exiting from GNOME.
If you are unable to get to the Log Out button (if, for example, your Panel crashed), there are two other exit methods. Try one of these two ways, depending on how you started the desktop:
✦
If you started the desktop by typing
from your login shell, press
Ctrl+Alt+F1 to return to your login shell. Then press Ctrl+C to kill the desktop.
✦
If you started the desktop from a graphical login screen, first open a Terminal window (right-click the desktop and select New Terminal). In the Terminal window, type
to see a list of running processes. Look for a command named gnome-session and determine its number under the PID column. Then type
, where
PID
is replaced by the PID number. You should see the graphical login screen.
Although these are not the most graceful ways to exit the desktop, they work. You should be able to log in again and restart the desktop.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 114
114
Part I ✦
Linux First Steps
Today’s modern desktop computer systems are made to spoon-feed you your operating system. In the name of ease of use, some desktop environments spend a lot of resources on fancy panels, complex control centers, and busy applets. In short, they can become bloated.
Many technically inclined people want a more streamlined desktop — or at least want to choose their own bells and whistles. They don’t want to have to wait for windows to redraw or menus to come up. Linux enables those people to forget the complete desktop environments and configure:
✦
— The X Window System provides the framework of choice for Linux and most UNIX systems. When you configure X yourself, you can choose the video driver, monitor settings, mouse configuration, and other basic features needed to get your display working properly.
✦
— Dozens of window managers are available to use with X on a Linux system. Window managers add borders and buttons to otherwise bare X windows. They add colors and graphics to backgrounds, menus, and windows. Window managers also define how you can use keyboard and mouse combinations to operate your desktop.
You only need to configure X directly if your desktop isn’t working (the desktop may appear scrambled or just plain crash). You may choose to configure X if you want to tune it to give you higher resolutions or more colors than you get by default.
Still to come in this chapter: examining tools for tuning X and, in particular, working with the xorg.conf
file. You’ll also explore a few popular window managers that you might want to try out. Slackware Linux is used to illustrate how to choose and configure a window manager because Slackware users tend to like simple, direct ways of working with the desktop (when they need a desktop at all).
Note
Before 2004, most Linux distributions used the X server from the XFree86 project
( www.xfree86.org
). Because of licensing issues, many of the major Linux vendors
(including Red Hat, SUSE, and Slackware) changed to the X server from X.org
( www.X.org
). The descriptions of how to get X going on your machine assume you are using the X.org X server.
To determine which X server is installed on your system, from a Terminal window type man Xorg and man XFree86. If you only have one X server installed on your computer (which you probably do) only the one installed will show a man page.
While you are there, press the space bar to page through the features of your X server.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 115
Chapter 3
✦
Getting into the Desktop
115
It’s possible that you already did some configuration when you installed Linux. If you are able to start a desktop successfully and your mouse, keyboard, and screen all seem to be behaving, you may not have to do anything more to configure X.
However, if you can’t start the desktop or you want to adjust some basic features
(such as screen resolution or number of colors supported), let’s look at some ideas on how to go about doing those things.
If your desktop crashes immediately or only shows garbled text, try to create a new
X configuration file. With the X.org X server, that file is /etc/X11/xorg.conf
.
Note
In XFree86, the configuration file, which has basically the same format, is
/etc/X11/XF86Config
.
To have X try to create a sane xorg.conf
file for you to use, do the following from a
Terminal window as root user:
If Linux booted to a command prompt, go to the next step. However, if it tried to start X automatically, you might have an illegible screen. In that case, press these keys together: Ctrl+Alt+Backspace. It should kill your X server and get you back to a command prompt. If X tries to restart (and is still messed up), press Ctrl+Alt+F2. When you see the command prompt, log in as root and type
. This will temporarily bring you down to a nongraphical state.
To have X probe your video hardware and create a new configuration file, type:
#
Xorg -configure
The file x.org.conf.new
should appear in your home directory. To test if this new configuration file works, type the following to start the X server:
#
X -xf86config /root/xorg.conf.new
A gray background with an X in the middle should appear. Move the mouse to move the X pointer. If that succeeds, you have a working xorg.conf
file to use.
Press Ctrl+Alt+Backspace to exit the X server.
Copy the new configuration file to where it is picked up the next time X starts.
#
cp /root/xorg.conf.new /etc/X11/xorg.conf
Chances are that you have a very basic X configuration that you may want to tune further.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 116
116
Part I ✦
Linux First Steps
Working video drivers are available with most video cards you can purchase today.
However, to get some advanced features from your video cards (such as 3D acceleration) you may need to get proprietary drivers directly from the video manufacturers. In particular, you may want to get drivers from NVIDIA and ATI.
To get new drivers for video cards or chipsets from NVIDIA, go to the NVIDIA site
( www.nvidia.com
) and select the Download Drivers button. Follow the link to
Linux and FreeBSD drivers. Links from the page that appears will take you to a Web page from which you can download the new driver and get instructions for installing it.
For ATI video cards and chipsets, go to www.ati.com
and select Drivers & Software.
Follow the links to Linux drivers and related installation instructions.
The xorg.conf
file might look a bit complicated when you first start working with it. However, chances are that there are only a few key elements you will need to change in it. As root user, open the /etc/X11/xorg.conf
file in any text editor.
Here are some things you can look for:
✦
— Look for an InputDevice section with a Mouse0 or Mouse1 identifier.
That section for a simple two-button, PS2 mouse might look as follows:
Section “InputDevice”
Identifier “Mouse0”
Driver “mouse”
Option “Protocol” “PS/2”
Option “Device” “/dev/psaux”
EndSection
If you are unable to use some feature of the mouse, such as a middle wheel, you might be able to get it working with an entry that looks more like the following:
Section “InputDevice”
Identifier “Mouse0”
Driver “mouse”
Option “Protocol” “IMPS/2”
Option “Device” “/dev/psaux”
Option “ZAxisMapping” “4 5”
EndSection
Don’t change the mouse identifier, but you can change the protocol and add the ZAxisMapping line to enable your wheel mouse. Try restarting X and trying your mouse wheel on something like a Web page to see if you can scroll up and down with it.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 117
Chapter 3
✦
Getting into the Desktop
117
Your mouse might be connected in a different way (such as a bus or serial mouse) or may have different buttons to enable. Tools for configuring your mouse are distribution-specific. Try mouseconfig , mouseadmin , or systemconfig-mouse to reconfigure your mouse from the command line.
✦
— The monitor section defines attributes of your monitor. There are generic settings you can use if you don’t exactly know the model of your monitor. Changing the Horizontal Sync and Vertical Refresh rates without checking your monitor’s technical specifications is not recommended; you could damage the monitor. Here’s an example of an entry that will work on many LCD panels:
Section “Monitor”
Identifier “Monitor0”
VendorName “Monitor Vendor”
ModelName “LCD Panel 1024x768”
HorizSync 31.5 - 48.5
VertRefresh 40.0 - 70.0
EndSection
Here’s an entry for a generic CRT monitor that will work on many CRTs:
Section “Monitor”
Identifier “Monitor0”
VendorName “Monitor Vendor”
ModelName “Generic Monitor, 1280x1024 @ 74 Hz”
HorizSync 31.5 - 79.0
VertRefresh 50.0 - 90.0
EndSection
If there is a tool available to select your monitor model directly, that would be the best way to go. For example, in Red Hat systems, you would run systemconfig-xfree86 to change monitor settings.
✦
— The Device section is where you identify the driver to use with your video driver and any options to use with it. It’s important to get this section right. The Xorg command described earlier usually does a good job detecting the driver. If you want to change to a different one, this is where to do so. Here’s an example of the Device section after I added a video driver from NVIDIA to my system (the driver name is nv):
Section “Device”
Identifier “Card0”
Driver “nv”
VendorName “nVidia Corporation”
BoardName “Unknown Board”
BusID “PCI:1:0:0”
EndSection
08_579495 ch03.qxd 12/27/04 9:55 PM Page 118
118
Part I ✦
Linux First Steps
✦
— The last major piece of information you may want to add is the screen resolution and color depth. There will be a screen resolution associated with each video card installed on your computer. The Screen section defines default color depths (such as 8, 16, or 24) and modes (such as
1024x768, 800x600, or 640x480). Set the DefaultDepth to the number of bits representing color depth for your system, and then add a
Modes line to set the screen resolution.
To read more about how to set options in your xorg.conf
If your X server is XFree86, type
.
file, type
.
Fully integrated desktop environments have become somewhat unfriendly to changing out window managers. However, you can completely bypass KDE or GNOME, if you like, and start your desktop simply with X and a window manager of your choice.
Although I’m using Slackware as the reference distribution for describing how to change window managers, the concept is the same on other Linux systems. In general, if no desktop environment is running in Linux, you can start it by typing:
$
startx
This command starts up your desktop environment or window manager, depending on how your system is configured. Although a variety of configuration files are read and commands are run, essentially which desktop you get depends on the contents of two files:
✦
/etc/X11/xinit/xinitrc — If a user doesn’t specifically request a particular desktop environment or window manager, the default desktop settings will come from the contents of this file. The xinitrc file is the system-wide X configuration file. Different Linux systems use different xinitrc files.
✦
$HOME/.xinitrc
— The .xinitrc
file is used to let individual users set up their own desktop startup information. Any user can add a .xinitrc file to his or her own home directory. The result is that the contents of that file will override any system-wide settings. If you do create your own .xinitrc
file, it should have as its last line exec
windowmanager
, where
windowmanager
is the name of your window manager; for example: exec /usr/X1R6/bin/blackbox
Slackware has at least seven different window managers from which you can choose, making it a good place to try out a few. It also includes a tool called xwmconfig , which lets you change the window manager system-wide (in the
/etc/X11/xinit/xinitrc
file). To use that tool, as the root user simply type from any shell on a Slackware system. Figure 3-15 shows an example of that screen.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 119
Chapter 3
✦
Getting into the Desktop
119
Figure 3-15:
In Slackware, you can change window managers using the xwmconfig command.
Select the window manager you want to try from that screen and select OK. That window manager will start the next time you run startx (provided you don’t override it by creating your own .xinitrc
file). Here are your choices:
✦
www.xfce.org
— The xfce window manager is designed to be lightweight and fast.
✦
www.blackboxwm.sourceforge.net
— Another lightweight window manager that strives to require few library dependencies so it can run in many environments. Offers many features for setting colors and styles
✦
http://fluxbox.sourceforge.net
— Based on Blackbox
(0.61.1)
FluxBox adds nice features such as window tabs (where you can join together multiple windows so they appear as multiple tabs on a single window). It also includes an icon bar and adds some useful mouse features (such as using your mouse wheel to change workspaces).
✦
www.windowmaker.org
— Window Maker is a clone of the
NEXTSTEP graphical interface, a popular UNIX workstation of the 1980s and
1990s. It is a particularly attractive window manager, with support for themes, various window decorations, and features for changing backgrounds, animations, and adding applets (called docapps).
✦
www.fvwm.org
— This window manager supports full internationalization, window manager hints, and improved font features. Interesting features include window shading in all directions (even diagonal) and side titles
(including text displayed vertically).
✦
http://fvwm95.sourceforge.net
— A version of FVWM that was created to look and feel like Windows 95.
08_579495 ch03.qxd 12/27/04 9:55 PM Page 120
120
Part I ✦
Linux First Steps
✦
— Although no longer actively maintained, some people still use twm when they want a truly bare-bones desktop. Until you click the left mouse button in twm, there’s nothing on the screen. Use the menu that pops up to open and close windows.
There are many other window managers available for Linux as well. To check out some more, visit the Xwinman Web site ( www.plig.org/xwinman ).
Once the system default is set for your window manager, users can set their own window manager to override that decision. The follow section describes how to do that.
Simply adding an exec line with the name of the window manager you want to use to your own .xinitrc
file in your home directory causes startx to start that window manager for you. Here is an example of the contents of a
.xinitrc
to start the
Window Maker window manager: exec /usr/bin/wmaker
Make sure that the file is executable ( chmod 755 $HOME/.xinitrc
). The Window
Maker window manager should start the next time you start your desktop. Other window managers you can choose include Blackbox (
/usr/X11R6/bin/blackbox
),
FluxBox ( /usr/X11R6/bin/fluxbox ), FVWM ( /usr/X11R6/bin/fluxbox ), FVWM-
95 (
/usr/X11R6/bin/fvwm95
), and twm (
/usr/X11R6/bin/twm
).
If you tried configuring X and you still have a server that crashes or has a garbled display, your video card may either be unsupported or may require special configuration. Here are a couple of locations you can check for further information:
✦
( www.x.org
) — The latest information about the X servers that come with Fedora Core is available from the X.Org Web site. X.Org is the freeware version of X recently used by many major Linux distributions to replace the
XFree86 X server.
✦
— README files that are specific to different types of video cards are delivered with the X.Org X server. Visit the X doc directory
( /usr/X11R6/lib/X11/doc ) for a README file specific to the type of video card (or more specifically, the video chipset) you are using. A lot of good information can also be found on the xorg.conf
man page (type
).
08_579495 ch03.qxd 12/27/04 9:55 PM Page 121
Chapter 3
✦
Getting into the Desktop
121
Complete desktop environments that run in Linux can rival desktop systems from any operating system. KDE and GNOME are the most popular desktop environments available today for Linux. For people who want a sleeker, more lightweight desktop environment, a variety of simple window managers (Blackbox, FVWM, twm,
FluxBox, and many others) are available to use in Linux as well.
The KDE desktop is well known for its large set of integrated applications (office productivity tools, games, multimedia, and other applications). GNOME has the reputation of being a more basic, business-oriented desktop. Most Linux distributions such as Slackware and Gentoo offer GNOME and KDE desktops that aren’t changed much from how they are delivered from those desktop projects. Other Linux systems (such as Red Hat) put their own look-and-feel over GNOME and KDE desktops.
While the latest Windows systems won’t run on many older 486 and Pentium machines, you can use an efficient Linux system like Slackware, add a lightweight window manager, and get reasonably good performance with your desktop system on those machines.
✦ ✦ ✦
08_579495 ch03.qxd 12/27/04 9:55 PM Page 122
09_579495 pt02.qxd 12/27/04 9:53 PM Page 123
P A R T
✦ ✦ ✦
In This Part
Chapter 4
Learning Basic
Administration
Chapter 5
Getting on the
Internet
Chapter 6
Securing Linux
✦ ✦ ✦
✦
✦
09_579495 pt02.qxd 12/27/04 9:53 PM Page 124
10_579495 ch04.qxd 12/27/04 9:53 PM Page 125
L
inux, like other UNIX systems, was intended for use by more than one person at a time. Multiuser features enable many people to have accounts on a single Linux system, with their data kept secure from others. Multitasking enables many people to run programs on the computer at the same time. Sophisticated networking protocols and applications make it possible for a Linux system to extend its capabilities to network users and computers around the world. The person assigned to manage all of this stuff is called the
system administrator.
Even if you are the only person using a Linux system, system administration is still set up to be separate from other computer use. To do most administrative tasks, you need to be logged in as the root user (also called the
superuser
) or temporarily get root permission. Users other than root cannot change, or in some cases even see, some of the configuration information for a Linux system. In particular, security features such as stored passwords are protected from general view.
This chapter describes the general principles of Linux system administration. In particular, this chapter examines some of the basic tools you need to administer your Linux system. It also helps teach you how to work with file systems and monitor the setup and performance of your Linux system.
Many Linux systems come with simplified graphical tools for administering Linux. If you are a casual user, these tools often let you do everything you need to administer your system without editing configuration files or running shell commands.
Let’s examine some of the Web-based administration tools that are available to use with most Linux systems.
✦ ✦ ✦ ✦
In This Chapter
Doing graphical administration
Using the root login
Understanding administrative commands, config files, and log files
Creating user accounts
Configuring hardware
Managing file systems and disk space
Monitoring system performance
✦ ✦ ✦ ✦
10_579495 ch04.qxd 12/27/04 9:53 PM Page 126
126
Part II ✦
Running the Show
Web-based administration tools are available with many open source projects to make those projects more accessible to casual users. Often all you need to use those tools is a Web browser (such as Mozilla), the port number of the service, and the root password. Projects such as Samba and CUPS come with their own
Web administration tools. Webmin is a general-purpose tool for administering a variety of Linux system services from your Web browser.
Note
The advantages of Web-based administration tools are that you can operate them from a familiar interface (your Web browser) and you can access them remotely.
If the Linux distribution you are using comes with its own set of graphical administration tools (such as SUSE’s YaST or Red Hat’s system-config tools), you should generally use those instead of any Web-based interface that comes with a project because a distribution’s own tools better integrate with its tools for starting and stopping services.
Several major open source projects come with Web-based interfaces for configuring those projects. Regardless of which Linux you are using, you can use your Web browser to configure the following projects:
✦
— To set up Samba for doing file and printer sharing with Microsoft
Windows systems on your LAN, use the Samba SWAT Web-based administration tools from any Web browser. With SWAT installed and running, you can access your Samba server configuration from your Web browser by typing the following URL in the location box: http://localhost:901
The Samba project also offers other graphical tools for administering Samba.
You can check them out at http://samba.org/samba/GUI for descriptions of those tools. Samba is described in Chapters 25 and 26.
✦
— The Common UNIX Printing Service (CUPS) has its own Web administration tool. With CUPS installed and configured, you can typically use CUPS
Web administration by typing the following URL in your Web browser’s location box: http://localhost:631
You use the CUPS administration tool to manage printers and classes and do a variety of administration tasks. CUPS is described in Chapter 25.
Samba and CUPS are included with many Linux distributions. Other projects that offer Web-based administration that may or may not be in your Linux distribution include SquirrelMail (a webmail interface) and Mailman (a mailing list facility).
10_579495 ch04.qxd 12/27/04 9:53 PM Page 127
Chapter 4
✦
Learning Basic Administration
127
The Webmin facility ( www.webmin.com
) offers more complete Web-based Linux and
UNIX administration features. Although Webmin isn’t delivered with some Linux systems that offer their own graphical administration tools (such as Red Hat’s Fedora and RHEL), the Webmin project has ported Webmin to run in many different Linux distributions. Those distributions include SUSE, Red Hat (Fedora and RHEL), Debian,
Slackware, Caldera OpenLinux, Mandrake, Yellow Dog, and others (see www.webmin.
com/support.html
for a complete list).
For Red Hat Fedora Linux 3, for example, I was able to download a Webmin RPM from Webmin.com. To start the Webmin interface, I just needed the root password after typing the following in my Web browser’s location box: http://localhost:10000
After you log in as root user, the main Webmin page displays, as shown in Figure 4-1.
Figure 4-1:
Webmin offers a Web browser interface for administering Linux.
Some people fear that once they’ve left the familiar confines of their Microsoft
Windows system for Linux, they’ll be stuck doing everything from a command line.
To gain a wider audience, commercial Linux distributions such as Red Hat Linux and SUSE created their own sets of graphical tools to provide an easy entry point for new Linux users. The following sections describe Red Hat’s system-config and
SUSE’s YaST graphical administration tools.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 128
128
Part II ✦
Running the Show
A set of graphical tools that comes with Red Hat Linux systems can be launched from the red hat menu (under the System tools and System Settings submenus) or the command line. Most of the Red Hat tools that launch from the command line begin with the system-config string (such as system-config-network ).
Note
In Fedora Core 1 and previous versions of Red Hat Linux, the GUI administrations tools all began with redhat-
, such as redhat-config-network and redhatlogviewer . Starting with Fedora Core 2, those names have all changed to system-
, resulting in names like system-config-network and systemlogviewer .
These administrative tasks require root permission; if you are logged in as a regular user, you must enter the root password before the GUI application’s window opens.
After you’ve entered that password, most of the system configuration tools will open without requiring you to retype the password during this login session. Look for a “keys” icon in the lower-right corner of the panel, indicating that you have root authorization. Click the keys to open a pop-up window that enables you remove authorization. Otherwise, authorization goes away when you close the GUI window.
The following list describes many of the GUI-based windows you can use to administer your Fedora or Red Hat Linux system. Start these windows from the System
Settings or System Tools submenus on your red hat menu:
✦
Access the following server configuration windows:
Create and configure zones if your computer is acting as a DNS server.
Configure your computer as an Apache Web server.
Set up directories from your system to be shared with other computers on your network using the NFS service.
Configure Windows (SMB) file sharing. (To configure other
Samba features, you can use the SWAT window.)
Display and change which services are running on your
Fedora system at different run levels from this Service Configuration window (see Figure 4-2).
✦
Manage software packages in the Fedora distribution.
✦
— Change how users are authenticated on your system. Usually,
Shadow Passwords and MD5 Passwords are selected. However, if your network supports LDAP, Kerberos, SMB, NIS, or Hesiod authentication, you can select to use any of those authentication types.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 129
Chapter 4
✦
Learning Basic Administration
129
Figure 4-2:
See services that start from each run level in the Service Configuration window.
✦
If you have multiple operating systems on your computer, or multiple Linux kernels available to boot in Linux, you can use the Boot
Configuration screen to choose which to boot by default. For example, you might have Fedora Linux, SUSE, and Windows XP all on the same hard disk.
You could choose which would start automatically (after a set number of seconds), if one wasn’t selected explicitly.
✦
— Set the date and time or choose to have an NTP server keep system time in sync.
✦
Mount and format removable media, such as CDs and floppy disks.
✦
Change the settings for your X desktop, including color depth and resolution for your display. You can also choose settings for your video card and monitor.
✦
— View information about your computer’s hardware.
✦
— Create initial configurations for connecting to the Internet via Ethernet, ISDN, modem, and other types of network equipment.
✦
Choose the type of keyboard you are using, based on language.
✦
Create a kickstart configuration file that can be used to install multiple Fedora systems without user interaction.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 130
130
Part II ✦
Running the Show
✦
— Select the default language used for the system.
✦
Control how your login screen appears and behaves.
✦
Manage your current network interfaces; add interfaces as well.
✦
— Display the active profile for network devices.
✦
Configure local and network printers.
✦
— Register your computer with the Red Hat
Network to get free software updates.
✦
Change the root password.
✦
Configure your firewall to allow or deny services to computers from the network.
✦
Try to detect and configure your sound card.
✦
View system log files, and search them for keywords.
✦
— View information about running processes and resource usage.
✦
— Schedule tasks to be run at set times.
✦
Add, display, and change user and group accounts for your
Fedora system.
The YaST administrative interface is one of the strongest features of SUSE Linux.
From a SUSE desktop, open the YaST Control Center by selecting System
➪
YaST from the main menu. Figure 4-3 shows an example of the YaST Control Center that appears.
YaST has some useful tools in its Hardware section that enable you to probe your computer hardware.
On my system, for example, I could see that the CD-ROM drive that YaST detected was available through device /dev/hdc and that it supported CD-R, CD-RW, and
DVD media. I could also see detailed information about my CPU, network card, PCI devices, sound card, and various storage media.
YaST also offers interfaces for configuring and starting network devices, as well as a variety of services to run on those devices. In addition, you can use YaST to configure your computer as a client for file sharing (Samba and NFS), e-mail (sendmail), and a variety of network services.
SUSE Linux Enterprise Server comes with a wider range of configuration tools that are specifically geared toward server setup, including tools for configuring a mail server, VPN tunnels, and full Samba 3.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 131
Chapter 4
✦
Learning Basic Administration
131
Figure 4-3:
Use the YaST Control Center to administer SUSE systems.
Every Linux system starts out with at least one administrative user account (the root user) and possibly one or more regular user accounts (given a name that you choose, or a name assigned by Linux). In most cases, you log in as a regular user and become the root user to do an administrative task.
The root user has complete control of the operation of your Linux system. That user can open any file or run any program. The root user also installs software packages and adds accounts for other people who use the system.
When you first install most Linux systems, you add a password for the root user. You must remember and protect this password — you will need it to log in as root or to obtain root permission while you are logged in as some other user. Other Linux systems (such as KNOPPIX) start you with a blank root password, so you may want to add one when you first start up by typing the following from a Terminal window or other shell:
#
passwd root
Changing password for user root.
New UNIX password:
********
Retype new UNIX password:
********
10_579495 ch04.qxd 12/27/04 9:53 PM Page 132
132
Part II ✦
Running the Show
Note
Some Linux distributions, such as Damn Small Linux, give you (as a regular user) the power to run commands as root. You simply have to ask for the privilege using the sudo command. For example, from a Terminal window, to open a shell as root, you would type:
$
#
sudo su -
You’ll find out more about the sudo command later in this chapter.
The home directory for the root user is typically /root . The home directory and other information associated with the root user account are located in the
/etc/passwd file. Here’s what the root entry looks like in the /etc/passwd file: root:x:0:0:root:/root:/bin/bash
This shows that for the user named root the user ID is set to 0 (root user), the group
ID is set to 0 (root group), the home directory is /root , and the shell for that user is /bin/bash . (We’re using a shadow password file to store encrypted password data, so the password field here contains an
x
.) You can change the home directory or the shell used by editing the values in this file. A better way to change these values, however, is to use the useradd command (described later in this chapter).
Although you can become the superuser by logging in as root, sometimes that is not convenient. For example, you may be logged in to a regular user account and just want to make a quick administrative change to your system without having to log out and log back in. Or, you may need to log in over the network to make a change to a Linux system but find that the system doesn’t allow root users in from over the network (a common practice in the days before secure shells were available).
The solution is to use the su can simply type command. From any Terminal window or shell, you
$
su
Password:
******
#
When you are prompted, type in the root user’s password. The prompt for the regular user ( $ ) changes to the superuser prompt ( # ). At this point, you have full permission to run any command and use any file on the system. However, one thing that the su command doesn’t do when used this way is read in the root user’s environment. As a result, you may type a command that you know is available and get the message
“Command Not Found.” To fix this problem, use the su command with the dash ( ) option instead, like this:
$
su -
Password:
******
#
10_579495 ch04.qxd 12/27/04 9:53 PM Page 133
Chapter 4
✦
Learning Basic Administration
133
You still need to type the password, but after that, everything that normally happens at login for the root user happens after the su command is completed. Your current directory will be root’s home directory (probably /root ), and things like the root user’s
PATH variable will be used. If you become the root user by just typing su , rather than su , you won’t change directories or the environment of the current login session.
You can also use the su command to become a user other than root. This is useful for troubleshooting a problem that is being experienced by a particular user, but not by others on the computer (such as an inability to print or send e-mail). For example, to have the permissions of a user named jsmith, you’d type the following:
$
su - jsmith
Even if you were root user before you typed this command, afterward you would only have the permissions to open files and run programs that are available to jsmith. As root user, however, after you type the su command to become another user, you don’t need a password to continue. If you type that command as a regular user, you must type the new user’s password.
When you are finished using superuser permissions, return to the previous shell by exiting the current shell. Do this by pressing Ctrl+D or by typing
. If you are the administrator for a computer that is accessible to multiple users, don’t leave a root shell open on someone else’s screen (unless you want to let that person do anything he wants to the computer)!
As mentioned earlier, when you run GUI tools as a regular user (from Red Hat Linux,
SUSE, or some other Linux systems), you are prompted for the root password before you are able to access the tool. By entering the root password, you are given root privilege for that one task, without being root user for every task you do from that desktop session.
A particular user can also be given administrative permissions for particular tasks without being given the root password. For example, a system administrator can add a user to particular groups, such as modem, disk, users, cdrom, ftp, mail, or www, and then open group permission to use those services. Or, an administrator could add a user to the wheel group and add entries to the /etc/sudoers file to allow that user to use the sudo command to run individual commands as root. (See the description of sudo later in this chapter.)
A fairly new feature being added to some Linux distributions that are used in highly secure environments is Security Enhanced Linux (SELinux). With SELinux, instead of one all-powerful root user account, multiple roles can be defined to protect selected files and services. In that way, for example, if someone hacks into your Web server, he would not automatically have access to your mail server, user passwords, or other services running on the computer.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 134
134
Part II ✦
Running the Show
You can expect to find many commands, configuration files, and log files in the same places in the file system, regardless of which Linux distribution you are using.
The following sections give you some pointers on where to look for these important elements.
Only the root user is intended to use many administrative commands. When you log in as root (or use su from the shell to become root), your $PATH variable is set to include some directories that contain commands for the root user. These include the following:
✦
/sbin — Contains commands for modifying your disk partitions (such as fdisk ), checking file systems ( fsck ), and changing system states ( init ).
✦
/usr/sbin — Contains commands for managing user accounts (such as useradd ) and adding mount points for automounting file systems
( automount ). Commands that run as daemon processes are also contained in this directory. (Look for commands that end in d , such as sshd , pppd , and cupsd .)
Some administrative commands are contained in regular user directories (such as
/bin and /usr/bin ). This is especially true of commands that have some options available to everyone. An example is the /bin/mount command, which anyone can use to list mounted file systems, but only root can use to mount file systems.
(Some desktops, however, are configured to let regular users use
CDs, DVDs, or other removable media.) mount to mount
To find commands that are intended primarily for the system administrator, check out the section 8 manual pages (usually in /usr/share/man/man8 ). They contain descriptions and options for most Linux administrative commands.
Some third-party applications will add administrative commands to directories that are not in your PATH . For example, an application may put commands in
/usr/local/bin , /opt/bin , or /usr/local/sbin . In those cases, you may need to add those directories to your PATH .
Configuration files are another mainstay of Linux administration. Almost everything you set up for your particular computer — user accounts, network addresses, or
GUI preferences — is stored in plain-text files. This has some advantages and some disadvantages.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 135
Chapter 4
✦
Learning Basic Administration
135
The advantage of plain-text files is that it’s easy to read and change them. Any text editor will do. The downside, however, is that as you edit configuration files, no error checking is going on. You have to run the program that reads these files (such as a network daemon or the X desktop) to find out whether you set up the files correctly.
A comma or a quote in the wrong place can sometimes cause a whole interface to fail.
Throughout this book you’ll find descriptions of the configuration files you need to set up the different features that make up Linux systems. The two major locations of configuration files are your home directory (where your personal configuration files are kept) and the /etc directory (which holds system-wide configuration files).
Following are descriptions of directories (and subdirectories) that contain useful configuration files. (Refer to Table 4-1 for some individual configuration files in
/etc that are of particular interest.) Viewing the contents of Linux configuration files can teach you a lot about administering Linux systems.
✦
$HOME — All users store information in their home directories that directs how their login accounts behave. Most configuration files in
$HOME begin with a dot ( .
), so they don’t appear as a user’s directory when you use a standard ls command (you need to type ls -a to see them). There are dot files that define how each user’s shell behaves, the desktop look-and-feel, and options used with your text editor. There are even files such as
.ssh/* and
.rhosts
that configure network permissions for each user. (To see the name of your home directory, type echo $HOME from a shell.)
✦
/etc — This directory contains most of the basic Linux system-configuration files. Table 4-1 shows some /etc configuration files of interest.
✦
/etc/cron*
— Directories in this set contain files that define how the crond utility runs applications on a daily ( cron.daily
), hourly ( cron.hourly
), monthly ( cron.monthly
), or weekly ( cron.weekly
) schedule.
✦
/etc/cups — Contains files that are used to configure the CUPS printing service.
✦
/etc/default
— Contains files that set default values for various utilities.
For example, the file for the useradd command defines the default group number, home directory, password expiration date, shell, and skeleton directory ( /etc/skel ) that are used when creating a new user account.
✦
/etc/httpd — Contains a variety of files used to configure the behavior of your
Apache Web server (specifically, the httpd daemon process). (On some Linux systems, /etc/apache is used instead.)
✦
/etc/init.d
— Contains the permanent copies of System V–style run-level scripts. These scripts are often linked to files in the /etc/rc?.d
directories to have each service associated with a script started or stopped for the particular run level. The ?
is replaced by the run-level number ( 0 through 6 ).
(Slackware puts its run-level scripts in the
/etc/rc.d
directory.)
✦
/etc/mail — Contains files used to configure your sendmail mail service.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 136
136
Part II ✦
Running the Show
✦
/etc/pcmcia — Contains configuration files that allow you to have a variety of
PCMCIA cards configured for your computer. (PCMCIA slots are those openings on your laptop that enable you to have credit card–sized cards attached to your computer. You can attach such devices as modems and external CD-ROMs.)
✦
/etc/postfix — Contains configuration files for the postfix mail transport agent.
✦
/etc/ppp
— Contains several configuration files used to set up Point-to-Point
Protocol (PPP) so that you can have your computer dial out to the Internet.
✦
/etc/rc?.d
state: rc0.d
— There is a separate
(shutdown state), rc?.d
rc1.d
directory for each valid system
(single-user state), rc2.d
(multiuser state), rc3.d
rc5.d
(multiuser plus networking state), rc4.d
(user-defined state),
(multiuser, networking, plus GUI login state), and rc6.d
(reboot state).
✦
/etc/security — Contains files that set a variety of default security conditions for your computer. These files are part of the pam (pluggable authentication modules) package.
✦
/etc/skel — Any files contained in this directory are automatically copied to a user’s home directory when that user is added to the system. By default, most of these files are dot ( .
) files, such as .kde
defaults) and .bashrc
(a directory for setting KDE desktop
(for setting default values used with the bash shell).
✦
/etc/sysconfig — Contains important system configuration files that are created and maintained by various services (including iptables
, samba
, and most networking services). These files are critical for Linux distributions that use GUI administration tools but not used on other Linux systems at all.
✦
/etc/xinetd.d
— Contains a set of files, each of which defines a network service that the xinetd daemon listens for on a particular port. When the xinetd daemon process receives a request for a service, it uses the information in these files to determine which daemon processes to start to handle the request.
File
aliases bashrc crontab csh.cshrc
(or cshrc) exports
Table 4-1
Description
Can contain distribution lists used by the Linux mail service. (This file may be located in
/etc/mail
.)
Sets system-wide defaults for bash shell users. (This may be called bash.bashrc
on some Linux distributions.)
Sets cron environment and times for running automated tasks.
Sets system-wide defaults for csh (C shell) users.
Contains a list of local directories that are available to be shared by remote computers using the Network File System (NFS).
10_579495 ch04.qxd 12/27/04 9:53 PM Page 137
Chapter 4
✦
Learning Basic Administration
137
File
fstab group gshadow host.conf
hosts hosts.allow
hosts.deny
inittab lilo.conf
modules.conf
mtab mtools.conf
named.conf
ntp.conf
passwd
Description
Identifies the devices for common storage media (hard disk, floppy,
CD-ROM, and so on) and locations where they are mounted in the
Linux system. This is used by the mount command to choose which file systems to mount when the system first boots.
Identifies group names and group IDs (GIDs) that are defined on the systems. Group permissions in Linux are defined by the second of three sets of rwx (read, write, execute) bits associated with each file and directory.
Contains shadow passwords for groups.
Sets the locations in which domain names (for example, redhat.com) are searched for on TCP/IP networks (such as the Internet). By default, the local hosts file is searched and then any name server entries in resolv.conf
.
Contains IP addresses and host names that you can reach from your computer. (Usually this file is used just to store names of computers on your LAN or small private network.)
Lists host computers that are allowed to use certain TCP/IP services from the local computer.
Lists host computers that are not allowed to use certain TCP/IP services from the local computer (doesn’t exist by default).
Contains information that defines which programs start and stop when Linux boots, shuts down, or goes into different states in between. This is the most basic configuration file for starting Linux.
Sets Linux boot loader (lilo) parameters to boot the computer.
In particular, it lists information about bootable partitions on your computer. (If your distribution uses the GRUB boot loader, you may not see this file.)
Contains aliases and options related to loadable kernel modules used by your computer.
Contains a list of file systems that are currently mounted.
Contains settings used by DOS tools in Linux.
Contains DNS settings if you are running your own DNS server.
Includes information needed to run the Network Time Protocol (NTP).
Stores account information for all valid users for the system. Also includes other information, such as the home directory and default shell. (Rarely includes the user passwords themselves, which are typically stored in the /etc/shadow file.)
Continued
10_579495 ch04.qxd 12/27/04 9:53 PM Page 138
138
Part II ✦
Running the Show
File
printcap profile protocols resolv.conf
rpc services shadow shells sudoers syslog.conf
termcap xinetd.conf
Table 4-1 (continued)
Description
Contains definitions for the printers configured for your computer.
(If the printcap
/etc/cups file doesn’t exist, look for printer information in the directory.)
Sets system-wide environment and startup programs for all users. This file is read when the user logs in.
Sets protocol numbers and names for a variety of Internet services.
Identifies the locations of DNS name server computers that are used by TCP/IP to translate Internet host.domain names into IP addresses.
(When a Web browser or mail client looks for an Internet site, it checks servers listed in this file to locate the site.)
Defines remote procedure call names and numbers.
Defines TCP/IP services and their port assignments.
Contains encrypted passwords for users who are defined in the passwd file. (This is viewed as a more secure way to store passwords than the original encrypted password in the passwd file. The passwd file needs to be publicly readable, whereas the unreadable by all but the root user.) shadow file can be
Lists the shell command-line interpreters ( bash
, sh
, csh
, and so on) that are available on the system, as well as their locations.
Sets commands that can be run by users, who may not otherwise have permission to run the command, using the sudo command. In particular, this file is used to provide selected users with root permission.
Defines what logging messages are gathered by the syslogd daemon and what files they are stored in. (Typically, log messages are stored in files contained in the /var/log directory.)
Lists definitions for character terminals, so that character-based applications know what features are supported by a given terminal. Graphical terminals and applications have made this file obsolete to most people.
(Termcap was the BSD UNIX way of storing terminal information;
UNIX System V used definitions in /usr/share/terminfo files.)
Contains simple configuration information used by the xinetd daemon process. This file mostly points to the
/etc/xinetd.d
directory for information about individual services. (Some systems use the inetd.conf
file and the inetd daemon instead.)
10_579495 ch04.qxd 12/27/04 9:53 PM Page 139
Chapter 4
✦
Learning Basic Administration
139
Note
Another directory, /etc/X11 , includes subdirectories that each contain systemwide configuration files used by X and different X window managers available for
Linux. The xorg.conf
file (which makes your computer and monitor usable with X) and configuration directories containing files used by xdm and xinit to start X are in here.
Directories relating to window managers contain files that include the default values that a user will get if that user starts one of these window managers on your system. Window managers that may have system-wide configuration files in these directories include GNOME ( gdm
) and Twm ( twm
).
Some files and directories in
/etc/X11 directory.
are linked to locations in the
/usr/X11R6
One of the things that Linux does well is keep track of itself. This is a good thing, when you consider how much is going on in a complex operating system. Sometimes you are trying to get a new facility to work and it fails without giving you the foggiest reason why. Other times you want to monitor your system to see if people are trying to access your computer illegally. In any of those cases, you can use log files to help track down the problem.
The main utilities for logging error and debugging messages for Linux are the syslogd and klogd daemons. General system logging is done by syslogd. Logging that is specific to kernel activity is done by klogd. Logging is done according to information in the /etc/syslog.conf
are usually in the /var/log file. Messages are typically directed to log files that directory. Here are a few common log files:
✦ boot.log
— Contains boot messages about services as they start up.
✦ messages — Contains many general informational messages about the system.
✦ secure
— Contains security-related messages, such as login activity.
✦
XFree86.0.log
or Xorg.0.log
— Depending on which X server you are using, contains messages about your video card, mouse, and monitor configuration.
If you are using a Fedora or other Red Hat Linux system, the System Logs utility is a good way to step through your system’s log files. From the red hat menu, select
System Tools
➪
System Logs. You not only can view boot, kernel, mail, security, and other system logs, but you can also use the filter box to search for particular terms
(such as a model number of a piece of hardware that’s not working).
10_579495 ch04.qxd 12/27/04 9:53 PM Page 140
140
Part II ✦
Running the Show
You don’t hear much about other administrative logins (besides root) being used with Linux. It was a fairly common practice in UNIX systems to have several different administrative logins that allowed administrative tasks to be split among several users. For example, a person sitting near a printer could have lp permissions to move print jobs to another printer if he knew a printer wasn’t working.
In any case, administrative logins are available with Linux, so you may want to look into using them. Here are some examples:
✦
— User can control some printing features. Having a separate lp administrator allows someone other than the superuser to do such things as move or remove lp logs and print spool files. The home directory for lp is /var/spool/lpd .
✦
— User can work with administrative e-mail features. The mail group has group permissions to use mail files in /var/spool/mail (which is also the mail user’s home directory).
✦
— User owns various uucp commands (once used as the primary method for dial-up serial communications) as well as log files in /var/log/uucp , spool files in /var/spool , administrative commands (such as uuchk , uucico , uuconv , and uuxqt ) in /usr/sbin , and user commands ( uucp , cu , uuname , uustat , and uux ) in /usr/bin . The home directory for uucp is /var/spool/uucp .
✦
— User owns many commands in /bin in traditional UNIX systems. This is not the case in some Linux systems (such as Red Hat and Gentoo) because root owns most executable files. The home directory of bin is /bin .
✦
— User could do administration of Internet news services, depending on how you set permission for /var/spool/news and other news-related resources. The home directory for news is /etc/news .
One way to give full or limited root privileges to any nonroot user is to set up the sudo facility, which simply entails adding the user to /etc/sudoers and defining what privilege you want that user to have. Then the user can run any command he or she is privileged to use by preceding that command with the sudo command.
Here’s an example of how to use the sudo facility to cause any users that are added to the wheel group to have full root privileges:
As the root user, edit the /etc/sudoers file by running the visudo command:
# /usr/sbin/visudo
By default, the file opens in vi, unless your EDITOR variable happens to be set to some other editor acceptable to visudo (for example, export EDITOR=gedit ).
The reason for using visudo is that the command locks the /etc/sudoers file and does some basic sanity checking of the file to ensure it’s been edited correctly.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 141
Chapter 4
✦
Learning Basic Administration
141
Note
If you are stuck here, refer to the vi tutorial in Chapter 2 for information on using the vi editor.
Uncomment the following line to allow users in the wheel group to have full root privileges on the computer:
%wheel ALL=(ALL) ALL
This line causes each user to provide a password to be allowed to use administrative commands. To allow users in the wheel group to have that privilege without using a password, uncomment the following line instead:
%wheel ALL=(ALL) NOPASSWD: ALL
Save the changes to the /etc/sudoers file (in vi, type
).
Still as root user, open the /etc/group wheel file in any text editor and add to the line any users you want to have root privilege. For example, if you were to add the users mary and jake to the wheel group, the line would appear as follows: wheel:x:10:root,mary,jake
Now users mary and jake can run the sudo command to run commands, or parts of commands, that are normally restricted to the root user. The following is an example of a session by the user jake after he has been assigned sudo privileges:
[jake]$
sudo umount /mnt/win
We trust you have received the usual lecture from the local System Administrator. It usually boils down to these two things:
#1) Respect the privacy of others.
#2) Think before you type.
Password:
*********
[jake]$
umount /mnt/win
mount: only root can mount /dev/hda1 on /mnt/win
[jake]$
sudo umount /mnt/win
[jake]$
In this session, the user jake runs the sudo command to unmount the /mnt/win system (using the umount command). He is given a warning and asked to provide file his password (this is jake’s password,
not
the root password).
Even after jake has given the password, he must still use the sudo command to run subsequent administrative commands as root (the umount fails, but the sudo umount succeeds). Notice that he is not prompted for a password for the second sudo . That’s because after entering his password successfully, he can enter as many sudo commands as he wants for the next five minutes without having to enter it again. (You can change the timeout value from five minutes to however long you want by setting the passwd_timeout value in the /etc/sudoers file.)
10_579495 ch04.qxd 12/27/04 9:53 PM Page 142
142
Part II ✦
Running the Show
The preceding example grants a simple all-or-nothing administrative privilege to everyone you put in the wheel group. However, the
/etc/sudoers file gives you an incredible amount of flexibility in permitting individual users and groups to use individual applications or groups of applications. Refer to the sudoers and sudo man pages for information about how to tune your sudo facility.
Your system administrator duties don’t end after you have installed Linux. If multiple people are using your Linux system, you, as administrator, must give each person his own login account. You’ll use useradd and related commands to add, modify, and delete user accounts.
Note
Configuring hardware is also on your duty list. When you add hardware to your
Linux computer, that hardware is usually detected and configured automatically. In some cases, though, the hardware may not have been set up properly, and you will use commands such as lsmod
, modprobe
, insmod
, and rmmod to configure the right modules to get the hardware working.
A device driver is the code that is permanently built into the kernel to allow application programs to talk to a particular piece of hardware. A module is like a driver, but it is loaded on demand. The “Configuring Hardware” section later in this chapter includes information about using these commands to configure modules.
Managing file systems and disk space is your responsibility, too. You must keep track of the disk space being consumed, especially if your Linux system is shared by multiple users. At some point, you may need to add a hard disk or track down what is eating up your disk space (you use commands like find to do this).
Your duties also include monitoring system performance. You may have a runaway process on your system or you may just be experiencing slow performance. Tools that come with Linux can help you determine how much of your CPU and memory are being consumed.
These tasks are explored in the rest of this chapter.
Every person who uses your Linux system should have a separate user account.
Having a user account provides each person with an area in which to securely store files as well as a means of tailoring his or her user interface (GUI, path, environment variables, and so on) to suit the way that he or she uses the computer.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 143
Chapter 4
✦
Learning Basic Administration
143
You can add user accounts to most Linux systems in several ways — Red Hat systems use the redhat-config-users utility, for example, and SUSE offers a user setup module in YaST. This chapter describes how to add user accounts from the command line with useradd because most Linux systems include that command.
The most straightforward method for creating a new user from the shell is with the useradd command. After opening a Terminal window with root permission, you simply invoke useradd at the command prompt, with details of the new account as parameters.
The only required parameter is the login name of the user, but you probably want to include some additional information ahead of it. Each item of account information is preceded by a single letter option code with a dash in front of it. Table 4-2 lists the options that are available with useradd .
Option
-c
-c
comment
“comment here”
-d
home_dir
-D
-e expire_date
-f -1
Table 4-2
Description
Provide a description of the new user account. Often the person’s full name. Replace
comment
with the name of the user account (
-c jake
). Use quotes to enter multiple words
(
-c “jake jackson”
).
Set the home directory to use for the account. The default is to name it the same as the login name and to place it in
/home
.
Replace
home_dir
with the directory name to use (for example,
-d /mnt/homes/jake
).
Rather than create a new account, save the supplied information as the new default settings for any new accounts that are created.
Assign the expiration date for the account in MM/DD/YYYY format. Replace expire_date
(
-e 05/06/2005
).
with a date you want to use
Set the number of days after a password expires until the account is permanently disabled. The default, -1, disables the option. Setting this to
0 disables the account immediately after the password has expired. Replace
-1 with the number to use.
Continued
10_579495 ch04.qxd 12/27/04 9:53 PM Page 144
144
Part II ✦
Running the Show
-m
-M
-n
Option
-g
group
-G
grouplist
-k
skel_dir
-o
-p
passwd
-s
shell
-u
user_id
Table 4-2 (continued)
Description
Set the primary group (as listed in the
/etc/group new user will be in. Replace
(
-g wheel
).
group
file) the with the group name
Add the new user to the supplied comma-separated list of groups ( -G wheel,sales,tech,lunch ).
Set the skeleton directory containing initial configuration files and login scripts that should be copied to a new user’s home directory. This parameter can only be used in conjunction with the
-m option. Replace
skel_dir
with the directory name to use. (Without this option, the /etc/skel directory is used.)
Automatically create the user’s home directory and copy the files in the skeleton directory (
/etc/skel
) to it.
Do not create the new user’s home directory, even if the default behavior is set to create it.
Turn off the default behavior of creating a new group that matches the name and user ID of the new user. This option is available with Red Hat Linux systems. Other Linux systems often assign a new user to the group named users instead.
Use with
-u
uid
to create a user account that has the same
UID as another username. (This effectively lets you have two different usernames with authority over the same set of files and directories.)
Enter a password for the account you are adding. This must be an encrypted password. Instead of adding an encrypted password here, you can simply use the passwd later to add a password for
user
.
user
command
Specify the command shell to use for this account. Replace
shell
with the command shell ( -s bash ).
Specify the user ID number for the account ( -u 474 ). Without the
-u option, the default behavior is to automatically assign the next available number. Replace
user_id
with the ID number (
-u
).
For example, let’s create an account for a new user named Mary Smith with a login name of mary. First, log in as root, and then type the following command:
#
useradd -c “Mary Smith” mary
10_579495 ch04.qxd 12/27/04 9:53 PM Page 145
Chapter 4
✦
Learning Basic Administration
145
Tip
When you choose a username, don’t begin with a number (for example, 06jsmith).
Also, it’s best to use all lowercase letters, no control characters or spaces, and a maximum of eight characters. The useradd command allows up to 32 characters, but some applications can’t deal with usernames that long. Tools such as ps display
UIDs instead of names if names are too long. Having users named Jsmith and jsmith can cause confusion with programs (such as sendmail) that don’t distinguish case.
Next, set Mary’s initial password using the passwd command. You’re prompted to type the password twice:
#
passwd mary
Changing password for user mary.
New password:
*******
Retype new password:
*******
(Asterisks in this example represent the password you type. Nothing is actually displayed when you type the password.)
In creating the account for Mary, the useradd command performs several actions:
✦
Reads the /etc/login.defs
accounts.
file to get default values to use when creating
✦
Checks command-line parameters to find out which default values to override.
✦
Creates a new user entry in the /etc/passwd and /etc/shadow files based on the default values and command-line parameters.
✦
Creates any new group entries in the /etc/group file. (Red Hat creates a group using the new user’s name; Gentoo adds the user to the users group; and SUSE adds it to every group you set for new users, such as dialout, audio, video, and other services.)
✦
Creates a home directory, based on the user’s name, in the /home directory.
✦
Copies any files located within the /etc/skel directory to the new home directory. This usually includes login and application startup scripts.
The preceding example uses only a few of the available useradd options. Most account settings are assigned using default values. You can set more values explicitly, if you want to; here’s an example that uses a few more options to do so:
#
useradd -g users -G wheel,sales -s /bin/tcsh -c “Mary Smith” mary
In this case, useradd is told to make users the primary group mary belongs to ( -g ), add her to the wheel and sales groups, and assign tcsh as her primary command shell ( -s ). A home directory in /home under the user’s name ( /home/mary ) is created by default. This command line results in a line similar to the following being added to the /etc/passwd file: mary:x:502:100:Mary Smith:/home/mary:/bin/tcsh
10_579495 ch04.qxd 12/27/04 9:53 PM Page 146
146
Part II ✦
Running the Show
Each line in the /etc/passwd file represents a single user account record. Each field is separated from the next by a colon (
:
) character. The field’s position in the sequence determines what it is. As you can see, the login name is first. Again, the password field contains an
x
because we are using a shadow password file to store encrypted password data. The user ID selected by useradd is 502. The primary group ID is 100, which corresponds to the users group in the
/etc/group file. The comment field was correctly set to Mary Smith, the home directory was automatically assigned as
/home/mary
, and the command shell was assigned as
/bin/tcsh
, exactly as specified with the useradd options.
By leaving out many of the options (as I did in the first useradd example), defaults are assigned in most cases. For example, by not using
-g users or
-G wheel,sales
, in Red Hat Linux a group named mary would have been created and assigned to the new user. Likewise, excluding
-s /bin/tcsh causes
/bin/bash to be assigned as the default shell.
The /etc/group file holds information about the different groups on your Linux system and the users who belong to them. Groups are useful for enabling multiple users to share access to the same files while denying access to others. Peek at the
/etc/group file, and you find something similar to this: bin:x:1:root,bin,daemon daemon:x:2:root,bin,daemon sys:x:3:root,bin,adm adm:x:4:root,adm,daemon tty:x:5: disk:x:6:root lp:x:7:daemon,lp mem:x:8: kmem:x:9: wheel:x:10:root,joe,mary
.
.
.
nobody:x:99: users:x:100: chris:x:500 sheree:x:501 sales:x:601:bob,jane,joe,mary
Each line in the group file contains the name of a group, the group ID number associated with it, and a list of users in that group. By default, each user is added to his or her own group, beginning with GID 500. Note that mary was added to the wheel and sales groups instead of having her own group.
It is actually rather significant that mary was added to the wheel group. By doing this, you grant her the capability to use the sudo the root user (provided that sudo command to run commands as is configured as described later in this chapter).
10_579495 ch04.qxd 12/27/04 9:53 PM Page 147
Chapter 4
✦
Learning Basic Administration
147
The useradd command determines the default values for new accounts by reading the /etc/login.defs
file. You can modify those defaults by either editing that file manually with a standard text editor or by running the useradd command with the
-D option. Although login.defs
is different on different Linux systems, here is an example containing many of the settings you might find in a login.defs
file:
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7
UID_MIN 500
UID_MAX 60000
GID_MIN 500
GID_MAX 60000
CREATE_HOME yes
All uncommented lines contain keyword/value pairs. For example, the keyword
PASS_MIN_LEN is followed by some white space and the value 5 . This tells useradd that the user password must be at least five characters. Other lines let you customize the valid range of automatically assigned user ID numbers or group ID numbers.
(Red Hat starts at UID 500; other Linuxes start with UID 100.) A comment section that explains that keyword’s purpose precedes each keyword (which I edited out here to save space). Altering a default value is as simple as editing the value associated with a keyword and then saving the file.
If you want to view the defaults, type the useradd command with the -D follows: option, as
#
useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
You can also use the -D option to change defaults. When run with this flag, useradd refrains from actually creating a new user account; instead, it saves any additionally supplied options as the new default values in /etc/login.defs
. Not all useradd options can be used in conjunction with the -D option. You can use only the five options listed in Table 4-3.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 148
148
Part II ✦
Running the Show
Options
Table 4-3
-b
default_home
-e
default_expire_date
-f
default_inactive
-g
default_group
-s
default_shell
Description
Set the default directory in which user home directories are created. Replace
default_home
with the directory name to use (
-b garage
). Usually this is
/home
.
Set the default expiration date on which the user account is disabled. The
default_expire_date
value should be replaced with a date in the form MM/DD/YYYY
(-e 10/15/2005).
Set the number of days after a password has expired before the account is disabled. Replace
default_ inactive
with a number representing the number of days (
-f 7
).
Set the default group that new users will be placed in. Normally useradd creates a new group with the same name and ID number as the user. Replace
default_group
with the group name to use
(
-g bears
).
Set the default shell for new users. Normally this is
/bin/bash . Replace
default_shell
with the full path to the shell that you want as the default for new users ( -s /bin/ash ).
To set any of the defaults, give the -D option first, and then add the defaults you want to set. For example, to set the default home directory location to /home/ everyone and the default shell to /bin/tcsh , type the following:
#
useradd -D -b /home/everyone -s /bin/tcsh
Besides setting up user defaults, an administrator can create default files that are copied to each user’s home directory for use. These files can include login scripts and shell configuration files (such as .bashrc
).
Other commands exist that are useful for working with user accounts, including usermod (to modify settings for an existing account) and userdel (to delete an existing user account).
10_579495 ch04.qxd 12/27/04 9:53 PM Page 149
Chapter 4
✦
Learning Basic Administration
149
In a perfect world, after installing and booting Linux, all of your hardware is detected and available for access. Although many Linux systems are rapidly moving closer to that world, there are times when you must take special steps to get your computer hardware working.
Linux systems come with tools for configuring the drivers that stand between the programs you run (such as CD players and Web browsers) and the hardware they use (such as CD-ROM drives and network cards). The intention is to have the drivers your system needs most often built into the kernel; these are called
resident drivers.
Drivers that are added dynamically as needed are referred to as
loadable modules.
If you have installed the Linux kernel source code, source code files for available drivers are stored in subdirectories of the /usr/src/linux*/drivers
You can find information about these drivers in a couple of ways: directory.
✦
make xconfig
— With /usr/src/linux* as your current directory, type
from a Terminal window on the desktop. Select the category of module you want and then click Help next to the driver that interests you.
The help information that appears includes a description of the driver.
✦
— The /usr/src/linux*/Documentation directory contains lots of plain-text files describing different aspects of the kernel and related drivers.
After modules have been built, they are installed in the /lib/modules/ subdirectories. The name of the directory is based on the current release number of the kernel.
Modules that are in that directory can then be loaded and unloaded as they are needed.
Note
To see which modules are currently loaded into the running kernel on your computer, use the lsmod command. Here’s an example:
If you don’t have a Linux system installed yet, try booting KNOPPIX and using lsmod to list your loaded modules. If all your hardware is working properly, write down this list of modules. Later, when you permanently install Fedora or some other
Linux system, if your CD drive, modem, video card, or other hardware doesn’t work properly, you can use your list of modules to determine which module should have been used and load it, as described in the next section.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 150
150
Part II ✦
Running the Show
#
lsmod
Module Size Used by snd_seq_oss 38912 0 snd_seq_midi_event 9344 1 snd_seq_oss
.
.
snd_seq 67728 4 snd_seq_oss,snd_seq_midi_event snd_seq_device 8328 2 snd_seq_oss,snd_seq
.
autofs 16512 0 ne2k_pci 9056 0
8390 13568 1 ne2k_pci ohci1394 41860 0 ieee1394 284464 1 ohci1394 floppy 65712 0 sg 36120 0 scsi_mod 124600 1 sg parport_pc 39724 0 parport 47336 1 parport_pc ext3 128424 2 jbd 86040 1 ext3
This output shows a variety of modules that have been loaded on a Linux system, including several to support the ALSA sound system, some of which provide OSS compatibility ( snd_seq_oss
).
To find information about any of the loaded modules, use the modinfo command.
For example, you could type the following:
#
modinfo -d snd-seq-oss
“OSS-compatible sequencer module”
Not all modules have descriptions available. In this case, however, the snd-seq-oss module is described as an OSS-compatible sequencer module. You can also use the
-a option to see the author of the module, or
-n to see the object file representing the module. The author information often has the e-mail address of the driver’s creator, so you can contact the author if you have problems or questions about it.
You can load any module that has been compiled and installed (to the /lib/modules directory) into your running kernel using the modprobe command. A common reason for loading a module is to use a feature temporarily (such as loading a module to support a special file system on a floppy you want to access). Another reason is to identify a module that will be used by a particular piece of hardware that could not be autodetected.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 151
Chapter 4
✦
Learning Basic Administration
151
Here is an example of the modprobe command being used to load the parport module, which provides the core functions to share parallel ports with multiple devices:
#
modprobe parport
After parport is loaded, you can load the parport_pc module to define the PC-style ports available through the interface. The parport_pc module lets you optionally define the addresses and IRQ numbers associated with each device sharing the parallel port. For example:
#
modprobe parport_pc io=0x3bc irq=auto
Note
In this example, a device is identified as having an address of 0x3bc, and the IRQ for the device is autodetected.
The modprobe command loads modules temporarily — they disappear at the next reboot. To permanently add the module to your system, add the modprobe command line to one of the startup scripts that are run at boot time.
An alternative to using modprobe is the insmod command. The advantage of using modprobe
, however, is that insmod loads only the module you request, whereas modprobe tries to load other modules that the one you requested is dependent on.
Use the rmmod command to remove a module from a running kernel. For example, to remove the module parport_pc from the current kernel, type the following:
#
rmmod parport_pc
If it is not currently busy, the parport_pc module is removed from the running kernel.
If it is busy, try killing any process that might be using the device. Then run rmmod again.
File systems in Linux are organized in a hierarchy, beginning from root (
/
) and continuing downward in a structure of directories and subdirectories. As an administrator of a Linux system, it’s your duty to make sure that all the disk drives that represent your file system are available to the users of the computer. It is also your job to make sure there is enough disk space in the right places in the file system for users to store what they need.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 152
152
Part II ✦
Running the Show
File systems are organized differently in Linux than they are in Microsoft Windows operating systems. Instead of drive letters (for example,
A:
,
B:
,
C:
) for each local disk, network file system, CD-ROM, or other type of storage medium, everything fits neatly into the directory structure. It is up to an administrator to create a mount point in the file system and then connect the disk to that point in the file system.
The organization of your file system begins when you install Linux. Part of the installation process is to divide your hard disk (or disks) into partitions. Those partitions can then be assigned to:
✦
A part of the Linux file system
✦
Swap space for Linux, or
✦
Other file system types (perhaps containing other bootable operating systems)
This chapter focuses on partitions that are used for the Linux file system. To see what partitions are currently set up on your hard disk, use the fdisk command:
#
fdisk –l
Disk /dev/hda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4825 cylinders
Units = cylinders of 16065 * 512 bytes = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104 b Win95 FAT32
/dev/hda2 84 89 48195 83 Linux
/dev/hda3 90 522 3478072+ 83 Linux
/dev/hda4 523 554 257040 5 Extended
/dev/hda5 523 554 257008+ 82 Linux swap
This output shows the disk partitioning for a computer capable of running both
Linux and Microsoft Windows. You can see that the Linux partition on
/dev/hda3 has most of the space available for data. There is a Windows partition ( /dev/hda1 ) and a Linux swap partition (
/dev/hda5
). There is also a small
/boot partition
(46MB) on /dev/hda2 . In this case, the root partition for Linux has 3.3GB of disk space and resides on
/dev/hda3
.
Next use the mount command (with no options) to see what partitions are actually being used for your Linux system (which available disk partitions are actually mounted and where they are mounted):
#
mount
/dev/hda3 on / type ext3 (rw)
/dev/hda2 on /boot type ext3 (rw)
/dev/hda1 on /mnt/win type vfat (rw) none on /proc type proc (rw) none on /sys type sysfs (rw) none on /dev/pts type devpts (rw,gid=5,mode=620)
10_579495 ch04.qxd 12/27/04 9:53 PM Page 153
Chapter 4
✦
Learning Basic Administration
153 none on /dev/shm type tmpfs (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/cdrom on /mnt/cdrom type iso9660 (ro,nosuid,nodev)
Note
You may notice that
/proc
,
/sys
,
/dev/pts
,
/proc/sys/fs/binfmt_misc
,
/dev/shm
, and other entries not relating to a partition are shown as file systems.
This is because they represent different file system types ( proc and devpts
, and so on). The word none
, however, indicates that they are not associated with a separate physical partition.
The mounted Linux partitions in this case are
/dev/hda2
, which provides space for the /boot directory (contains data for booting Linux), and /dev/hda3 , which provides space for the rest of the Linux file system beginning from the root directory
( / ). This particular system also contains a Windows partition that was mounted in the
/mnt/win directory and a CD that was mounted in its standard place:
/mnt/ cdrom . (With most GUI interfaces, the CD is typically mounted automatically when you insert it.)
After the word type
, you can see the type of file system contained on the device.
(See the description of different file system types later in this chapter.) Particularly on larger Linux systems, you may have multiple partitions for several reasons:
✦
— You may have several hard disks available to your users. In that case you would have to mount each disk (and possibly several partitions from each disk) in different locations in your file system.
✦
— If the users on a system consume all of the file system space, the entire system can fail. For example, there may be no place for temporary files to be copied (so the programs writing to temporary files fail), and incoming mail may fail to be written to mail boxes.
With multiple mounted partitions, if one partition runs out of space, the others can continue to work.
✦
— Some fast ways exist to back up data from your computer that involve copying the entire image of a disk or partition. If you want to restore that partition later, you can simply copy it back (bit by bit) to a hard disk.
With smaller partitions, this approach can be done fairly efficiently.
✦
— If one disk (or part of one disk) fails, having multiple partitions mounted on your file system may enable you to continue working and just fix the one disk that fails.
When a disk partition is mounted on the file system, all directories and subdirectories below that mount point are stored on that partition. So, for example, if you were to mount one partition on / and one on /usr , everything below the /usr mount point would be stored on the second partition while everything else would be stored on the first partition. If you then mounted another partition on /usr/local , everything below that mount point would be on the third partition, while everything else below /usr would be on the second partition.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 154
154
Part II ✦
Running the Show
Tip
What happens if a remote file system is unmounted from your computer, and you go to save a file in that mount point directory? You will write the file to that directory and it will be stored on your local hard disk. When the remote file system is remounted, however, the file you saved will seem to disappear. To get the file back, you’ll have to unmount the remote file system (causing the file to reappear), move the file to another location, remount the file system, and copy the file back there.
Mount points that are often mentioned as being candidates for separate partitions include / , /boot , /home , /usr , and /var . The root file system ( / ) is the catchall for directories that aren’t in other mount points. The root file system’s mount point ( / ) is the only one that is required. The /boot boot the operating system. The /home directory holds the images needed to file system is where all the user accounts are typically stored. Applications and documentation are stored in /usr . Below the /var mount point is where log files, temporary files, server files (Web, FTP, and so on), and lock files are stored (that is, items that need disk space for your computer’s applications to keep running).
The fact that multiple partitions are mounted on your file system is invisible to people using your Linux system. The only times they care is when a partition runs out of space or if they need to save or use information from a particular device (such as a floppy disk or remote file system) that isn’t mounted. Of course, any user can check this by typing the mount command.
Most of your hard disks are mounted automatically for you. When you install Fedora,
SUSE, and other Linux systems, you are asked to create partitions and indicate the mount points for those partitions. (Other Linux installation procedures will expect you to know that you have to partition before beginning.) When you boot Linux, all
Linux partitions residing on hard disk that are listed in your /etc/fstab file are typically mounted. For that reason, this section focuses mostly on how to mount other types of devices so that they become part of your Linux file system.
The mount command is used not only to mount devices but also to mount other kinds of file systems on your Linux system. This means that you can store files from other operating systems or use file systems that are appropriate for certain kinds of activities (such as writing large block sizes). The most common use of this feature for the average Linux user, however, is to enable that user to obtain and work with files from floppy disks, CD-ROMs, or other removable media.
To see file system types that are currently available to be used on your system, type
. Table 4-4 shows the file system types that are supported in
Linux, although they may not be in use at the moment or they may not be built into your current kernel (so they may need to be loaded as modules).
10_579495 ch04.qxd 12/27/04 9:53 PM Page 155
Chapter 4
✦
Learning Basic Administration
155
Type
adfs befs cifs ext3 ext2 ext iso9660 kafs minix msdos vfat umsdos proc reiserfs swap
Table 4-4
Description
Acorn disk file system, which is the standard file system used on RiscOS operating systems.
File system used by the BeOS operating system.
Common Internet File System (CIFS), the virtual file system used to access servers that comply with the SNIA CIFS specification. CIFS is an attempt to refine and standardize the SMB protocol used by Samba and Windows file sharing.
Ext file systems are the most common in Red Hat and many other Linux systems.
The ext3 file system, also called the Third Extended file system, includes journaling features that, compared to ext2, improve a file system’s capability to recover from crashes.
The default file system type for earlier Linux systems. Features are the same as ext3, except that ext2 doesn’t include journaling features.
This is the first version of ext3. It is not used very often anymore.
Evolved from the High Sierra file system (the original standard for CD-ROMs). Extensions to the High Sierra standard (called Rock Ridge extensions) allow iso9660 file systems to support long filenames and UNIX-style information (such as file permissions, ownership, and links). Data CD-ROMs typically use this file system type.
AFS client file system. Used in distributed computing environments to share files with Linux, Windows, and Macintosh clients.
Minix file system type, used originally with the Minix version of UNIX. It supports filenames of up to only 30 characters.
An MS-DOS file system. You can use this type to mount floppy disks that come from Microsoft operating systems.
Microsoft extended FAT (VFAT) file system.
An MS-DOS file system with extensions to allow features that are similar to UNIX
(including long filenames).
Not a real file system, but rather a file-system interface to the Linux kernel. You probably won’t do anything special to set up a proc file system. However, the
/proc mount point should be a proc file system. Many utilities rely on
/proc gain access to Linux kernel information.
to
ReiserFS journaled file system. ReiserFS and ext3 are the most common file system types used with Linux today.
Used for swap partitions. Swap areas are used to hold data temporarily when
RAM is currently used up. Data is swapped to the swap area and then returned to
RAM when it is needed again.
Continued
10_579495 ch04.qxd 12/27/04 9:53 PM Page 156
156
Part II ✦
Running the Show
Type
nfs hpfs ncpfs ntfs affs ufs
Table 8-1 (continued)
Description
Network File System (NFS) type of file system. NFS is used to mount file systems on other Linux or UNIX computers.
File system is used to do read-only mounts of an OS/2 HPFS file system.
This relates to Novell NetWare file systems. NetWare file systems can be mounted over a network.
Windows NT file system. It is supported as a read-only file system (so that you can mount and copy files from it). Read-write support is available but considered unreliable (some say dangerous).
File system is used with Amiga computers.
File system popular on Sun Microsystems operating systems (that is, Solaris and
SunOS).
The hard disks on your local computer and the remote file systems you use every day are probably set up to automatically mount when you boot Linux. The definitions for which of these file systems are mounted are contained in the
Here’s an example of an /etc/fstab file:
/etc/fstab file.
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2 none /dev/pts devpts gid=5,mode=620 0 0 none /dev/shm tmpfs defaults 0 0 none /proc proc defaults 0 0
/dev/hda5 swap swap defaults 0 0
/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/hda1 /mnt/win vfat noauto 0 0
/dev/fd0 /mnt/floppy auto noauto,owner 0 0
All file systems listed in this file are mounted at boot time, except for those set to noauto in the fourth field. In this example, the root ( / ) and boot ( /boot ) hard disk partitions are mounted at boot time, along with the /dev/pts , /dev/shm , and
/proc file systems (which are not associated with particular devices). The CD-ROM
( /dev/cdrom ) and floppy disk ( /dev/fd0 ) drives are not mounted at boot time.
Definitions are put in the fstab file for floppy and CD-ROM drives so that they can be mounted in the future (as described later).
I also added one line for /dev/hda1 , which enables me to mount the Windows (vfat) partition on my computer so I don’t have to always boot Windows to get at the files on my Windows partition.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 157
Chapter 4
✦
Learning Basic Administration
157
Note
To access my Windows partition, I must first create the mount point (by typing
mkdir /mnt/win). Then I can mount it when I choose by typing (as root) mount
/mnt/win.
Different Linux distributions will set up their fstab labels and many others don’t use a separate /boot file differently. Some don’t use partition by default. They will just have a swap partition and have all user data under the root partition ( / ).
Tip
Here is what’s in each field of the fstab file:
✦
— The name of the device representing the file system. The word none is often placed in this field for file systems (such as /proc and /dev/pts ) that are not associated with special devices. This field can include the LABEL option, with which you can indicate a universally unique identifier (UUID) or volume label instead of a device name. The advantage to this approach is that because the partition is identified by volume name, you can move a volume to a different device name and not have to change the fstab file.
✦
— The mount point in the file system. The file system contains all data from the mount point down the directory tree structure unless another file system is mounted at some point beneath it.
✦
— The file system type. Valid file system types are described in the
“Supported File Systems” section earlier in this chapter.
✦
— Options to the mount command. In the preceding example, the noauto option prevents the indicated file system from being mounted at boot time, and ro says to mount the file system read-only (which is reasonable for a CD-ROM drive). Commas must separate options. See the mount manual page (under the
-o command option) for information on other supported options.
Normally, only the root user is allowed to mount a file system using the mount command. However, to allow any user to mount a file system (such as a file system on a floppy disk), you could add the user option to Field 4 of
/etc/fstab
. In
SUSE, read/write permissions are given to specific devices (such as disk or audio devices) by specific groups (such as the disk or audio group) so that users assigned to those groups can mount or otherwise access those devices. Choose the Security and Users selection in the YaST Control Center and look for “Secondary Groups set for New User Defaults” to see how new users are assigned to groups.
✦
— The number in this field indicates whether the indicated file system needs to be dumped (that is, have its data backed up). A 1 means that the file system needs to be dumped, and a 2 means that it doesn’t. (I don’t think this field is useful anymore because many Linux systems no longer include the dump command. Most often, a 0 is used.)
✦
— The number in this field indicates whether the indicated file system needs to be checked with fsck : 1 means it needs to be checked, and 2 means it doesn’t.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 158
158
Part II ✦
Running the Show
If you want to add an additional local disk or partition, you can create an entry for it in the
/etc/fstab file. See Chapter 26 for information on mounting Samba, NFS, and other remount file systems from /etc/fstab.
Linux systems automatically run mount -a
(mount all file systems) each time you boot. For that reason, you generally use the mount command only for special situations. In particular, the average user or administrator uses mount in two ways:
✦
To display the disks, partitions, and remote file systems that are currently mounted.
✦
To temporarily mount a file system.
Any user can type
(with no options) to see what file systems are currently mounted on the local Linux system. The following is an example of the mount command. It shows a single hard disk partition ( /dev/hda1 ) containing the root ( / ) file system, and proc and devpts file system types mounted on /proc and /dev , respectively. The last entry shows a floppy disk, formatted with a standard Linux file system
(ext3) mounted on the /mnt/floppy directory.
$
mount
/dev/hda3 on / type ext3 (rw) none on /proc type proc (rw) none on /sys type sysfs (rw) none on /dev/shm type tmpfs (rw)
/dev/hda2 on /boot type ext3 (rw) none on /dev/pts type devpts (rw,gid=5,mode=0620)
/dev/fd0 on /mnt/floppy type ext3 (rw)
The most common devices to mount by hand are your floppy disk and your CD-ROM.
However, depending on the type of desktop you are using, CD-ROMs and floppy disks may be mounted for you automatically when you insert them. (In some cases, the autorun program may also run automatically. For example, autorun may start a
CD music player or software package installer to handle the data on the medium.)
Mounting Removable Media
If you want to mount a file system manually, the /etc/fstab file helps make it simple to mount a floppy disk or a CD-ROM. In some cases, you can use the mount command with a single option to indicate what you want to mount, and information is taken from the /etc/fstab file to fill in the other options. There are probably already entries in your /etc/fstab file to let you do these quick mounts in the following two cases:
✦
— If you are mounting a CD-ROM that is in the standard ISO 9960 format (as most software CD-ROMs are), you can mount that CD-ROM by placing it in your CD-ROM drive and typing the following:
#
mount /mnt/cdrom
10_579495 ch04.qxd 12/27/04 9:53 PM Page 159
Chapter 4
✦
Learning Basic Administration
159
Note
By default, your CD-ROM is mounted on the /mnt/cdrom directory. (The file system type, device name, and other options are filled in automatically.) To see the contents, type
,and then type
. Files from the CD-ROM’s root directory will be displayed.
✦
— If you want to mount a floppy in the Linux ext3 file system format (ext3), or in some cases a format that can be autodetected, mount that floppy disk by inserting it in your floppy drive and typing the following:
#
mount /mnt/floppy
The file system type (ext3), device (/dev/fd0), and mount options are filled in from the /etc/fstab file. You should be able to change to the floppy disk directory (cd /mnt/floppy) and list the contents of the floppy’s top directory (ls).
In both of the these cases, you could give the device name ( /dev/cdrom or /dev/ fd0
, respectively) instead of the mount point directory to get the same results.
Of course, it is possible that you may get floppy disks you want to use that are in all formats. Someone may give you a floppy containing files from a Microsoft operating system (in MS-DOS format). Or you may get a file from another UNIX system. In those cases, you can fill in your own options instead of relying on options from the
/etc/fstab file. In some cases, Linux autodetects that the floppy disk contains an
MS-DOS (or Windows vfat) file system and mounts it properly without additional arguments. If it doesn’t, here’s an example of how to mount a floppy containing
MS-DOS files:
#
mount -t msdos /dev/fd0 /mnt/floppy
This shows the basic format of the mount disk. You can change msdos command you would use to mount a floppy to any other supported file system type (described earlier in this chapter) to mount a floppy of that type. Instead of using floppy drive
A: ( /dev/fd0 ), you could use drive B: ( /dev/fd1 ) or any other accessible drive.
Instead of mounting on /mnt/floppy , you could create any other directory and mount the floppy there.
Here are some other useful options you could add to the mount command:
✦
-t auto — If you aren’t sure exactly what type of file system is contained on the floppy disk (or other medium you are mounting), use this option to indicate the file system type. The mount command will query the disk to try to ascertain what type of file system it contains.
✦
-r
— If you don’t want to make changes to the mounted file system (or can’t because it is a read-only medium), use this option to mount it read-only.
✦
-w
This mounts the file system with read/write permission.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 160
160
Part II ✦
Running the Show
Mounting a Disk Image in Loopback
Another valuable way to use the mount command has to do with disk images. If you download a CD or floppy disk image from the Internet and you want to see what it contains, you can do so without burning it to CD or floppy. With the image on your hard disk, create a mount point and use the -o loop option to mount it locally.
Here’s an example:
#
mkdir /mnt/mycdimage
#
mount -o loop whatever-i386-disc1.iso /mnt/mycdimage
In this example, the /mnt/mycdimage directory is created, and then the disk image file ( whatever-i386-disc1.iso
) residing in the current directory is mounted on it. I can now cd to that directory, view the contents of it, and copy or use any of its contents. This is useful for downloaded CD images from which you want to install software without having to burn the image to CD. When you are done, just type
to unmount it.
Other options to mount mount are available only for specific file system types. See the manual page for those and other useful options.
When you are done using a temporary file system, or you want to unmount a permanent file system temporarily, use the umount command. This command detaches the file system from its mount point in your Linux file system. To use umount , you can give it either a directory name or a device name. For example:
#
umount /mnt/floppy
This unmounts the device (probably /dev/fd0 ) from the mount point
/mnt/floppy . You can also unmount using the form
#
umount /dev/fd0
In general, it’s better to use the directory name ( /mnt/floppy ) because the umount command will fail if the device is mounted in more than one location. (Device names all begin with /dev .)
If you get the message device is busy , the umount request has failed. The reason is that either a process has a file open on the device or that you have a shell open with a directory on the device as a current directory. Stop the processes or change to a directory outside the device you are trying to unmount for the umount request to succeed.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 161
Chapter 4
✦
Learning Basic Administration
161
Tip
An alternative for unmounting a busy device is the -l option. With umount -l (a lazy unmount), the unmount happens as soon as the device is no longer busy. To unmount a remote NFS file system that’s no longer available (for example, the server went down), you can use the umount -f option to forcibly unmount the NFS file system.
A really useful tool for discovering what’s holding open a device you want to unmount is the lsof command. Type lsof with the name of the partition you want to unmount (such as lsof /mnt/floppy
). The output shows you what commands are holding open files on that partition.
You can create a file system for any supported file system type on a disk or partition that you choose. You do so with the mkfs command. While this is most useful for creating file systems on hard-disk partitions, you can create file systems on floppy disks or re-writable CDs as well.
Here is an example of using mkfs to create a file system on a floppy disk:
#
mkfs -t ext3 /dev/fd0
mke2fs 1.34, (25-Jul-2003)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
184 inodes, 1440 blocks
72 blocks (5.00%) reserved for the super user
First data block=1
1 block group
8192 blocks per group, 8192 fragments per group
184 inodes per group
Writing inode tables: done
Filesystem too small for a journal
Writing superblocks and filesystem accounting information: done
The filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
You can see the statistics that are output with the formatting done by the mkfs command. The number of inodes and blocks created are output, as are the number of blocks per group and fragments per group. You could now mount this file system
( mount /mnt/floppy ), change to it as your current directory ( cd /mnt/floppy ), and create files on it as you please.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 162
162
Part II ✦
Running the Show
Adding a new hard disk to your computer so that it can be used by Linux requires a combination of steps described in previous sections. Here’s the general procedure:
Install the new hard disk hardware.
Identify the partitions on the new disk.
Create the file systems on the new disk.
Mount the file systems.
Note
The easiest way to add a hard disk to Linux is to have the entire disk devoted to a single Linux partition. You can have multiple partitions, however, and assign them each to different types of file systems and different mount points, if you like. The following process takes you through adding a hard disk containing a single Linux partition. Along the way, it also notes which steps you need to repeat to have multiple file systems with multiple mount points.
This procedure assumes that Linux is already installed and working on the computer. If this is not the case, follow the instructions for adding a hard disk on your current operating system. Later, when you install Linux, you can identify this disk when you are asked to partition your hard disk(s).
Follow the manufacturer’s instructions for physically installing and connecting the new hard disk in your computer. If, presumably, this is a second hard disk, you may need to change jumpers on the hard disk unit itself to have it operate as a slave hard disk (if it’s on the same cable as your first hard disk).
You may also need to change the BIOS settings.
Boot your computer to Linux.
Determine the device name for the hard disk. As root user from a shell, type:
#
dmesg | less
From the output, look for an indication that the new disk was found. For example, if it’s a second IDE hard disk, you should see hdb: second SCSI drive, you’d see sdb: in the output. For a instead. Be sure you identify the correct disk, or you will erase all the data from disks you probably want to keep!
Use the fdisk command to create partitions on the new disk. For example, if you are formatting the second IDE disk (hdb), you could type the following:
#
fdisk /dev/hdb1
Now you are in fdisk command mode, where you can use the fdisk singleletter command set to work with your partitions. If the disk had existing partitions on it, you can change or delete those partitions now. Or, you can simply reformat the whole disk to blow everything away. Use p to view all partitions and d to delete a partition.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 163
Chapter 4
✦
Learning Basic Administration
163
Tip
To create a new partition, type the following:
n
Choose an extended (e) or primary partition (p). To choose a primary partition, type the following:
p
Type in the partition number. If you are creating the first partition (or for only one partition), type the number one:
1
Enter the first cylinder number (1 is the default). A range of cylinder numbers is displayed (for example, 1-4865 is the number of cylinders that appears for my 40GB hard drive).
To assign the new partition to begin at the first cylinder on the new hard disk, type the number
.
Enter the last cylinder number. If you are using the entire hard disk, use the last cylinder number shown. Otherwise, choose the ending cylinder number or indicate how many megabytes the partition should have.
To create more partitions on the hard disk, repeat steps 6 through 10 for each partition.
Type
to write changes to the hard disk and exit from the fdisk
At this point, you should be back at the shell.
command.
To create a file system on the new disk partition, use the mkfs command. By default, this command creates an ext2 file system, which is usable by Linux.
However, in most cases you will want to use a journaling file system (such as ext3 or reiserfs). To create an ext3 file system on the first partition of the second hard disk, type the following:
#
mkfs -t ext3 /dev/hdb1
If you created multiple partitions, repeat this step for each partition (such as
/dev/hdb2 , /dev/hdb3 , and so on).
If you don’t use
-t ext3
, an ext2 file system is created by default. Use other commands, or options to this command, to create other file system types. For example, use mkfs.vfat
reiserfs to create a VFAT file system, mkfs.msdos
for Reiser file system type. The tune2fs for DOS, or mkfs.
command, described later in this section, can be used to change an ext2 file system to an ext3 file system.
After the file system is created, you can have the partition permanently mounted by editing the /etc/fstab and adding the new partition. Here is an example of a line you might add to that file:
/dev/hdb1 /abc ext3 defaults 1 1
10_579495 ch04.qxd 12/27/04 9:53 PM Page 164
164
Part II ✦
Running the Show
In this example, the partition ( /dev/hdb1 ) is mounted on the /abc directory as an ext3 file system. The defaults keyword causes the partition to be mounted at boot time. The numbers 1 1 cause the disk to be checked for errors. Add one line like this example for each partition you created.
Create the mount point. For example, to mount the partition on /abc in the previous step), type the following:
(as shown
#
mkdir /abc
Create your other mount points if you created multiple partitions. The next time you boot Linux, the new partition(s) will be automatically mounted on the /abc directory.
After you have created the file systems on your partitions, a nice tool for adjusting those file systems is the tune2fs command. You can use it to change volume labels, how often the file system is checked, and error behavior. You can also use it to change an ext2 file system to an ext3 file system so the file system can use journaling. For example:
#
tune2fs -j /dev/hdb1
tune2fs 1.35-WIP, (07-Dec-2003)
Creating journal inode: done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
By adding the -j option to tune2fs , you can change either the journal size or attach the file system to an external journal block device (essentially turning a nonjournaling ext2 file system into a journaling ext3 file system). After you use tune2fs to change your file system type, you probably need to correct your include the file type change (from ext2 to ext3).
/etc/fstab file to
Running out of disk space on your computer is not a happy situation. You can use tools that come with Linux to keep track of how much disk space has been used on your computer, and you can keep an eye on users who consume a lot of disk space.
You can display the space available in your file systems using the df command. To see the amount of space available on all the mounted file systems on your Linux computer, type
with no options:
10_579495 ch04.qxd 12/27/04 9:53 PM Page 165
Chapter 4
✦
Learning Basic Administration
165
$
df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hda3 30645460 2958356 26130408 11% /
/dev/hda2 46668 8340 35919 19% /boot
/dev/fd0 1412 13 1327 1% /mnt/floppy
This example output shows the space available on the hard disk partition mounted on the / (root) partition ( /dev/hda1 ), /boot partition ( /dev/hda2 ), and the floppy disk mounted on the
/mnt/floppy directory (
/dev/fd0
). Disk space is shown in
1K blocks. To produce output in a more human-readable form, use the -h option:
$
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda3 29G 2.9G 24G 11% /
/dev/hda2 46M 8.2M 25M 19% /boot
/dev/fd0 1.4M 13k 1.2M 1% /mnt/floppy
With the df -h option, output appears in a friendlier megabyte or gigabyte listing.
Other options with df enable you to do the following:
✦
Print only file systems of a particular type ( -t type )
✦
Exclude file systems of a particular type ( -x type )
✦
Include file systems that have no space, such as
/proc and
/dev/pts
(
-a
)
✦
List only available and used inodes ( -i )
✦
Display disk space in certain block sizes ( --block-size=# )
To find out how much space is being consumed by a particular directory (and its subdirectories), use the du command. With no options, du lists all directories below the current directory, along with the space consumed by each directory. At the end, du produces total disk space used within that directory structure.
The du command is a good way to check how much space is being used by a particular user ( du /home/user1
) or in a particular file system partition ( du /var
).
By default, disk space is displayed in 1K block sizes. To make the output more friendly (in kilobytes, megabytes, and gigabytes), use the
-h option as follows:
$
du -h /home/jake
114k /home/jake/httpd/stuff
234k /home/jake/httpd
137k /home/jake/uucp/data
701k /home/jake/uucp
1.0M /home/jake
10_579495 ch04.qxd 12/27/04 9:53 PM Page 166
166
Part II ✦
Running the Show
The output shows the disk space used in each directory under the home directory of the user named jake (
/home/jake
). Disk space consumed is shown in kilobytes
( k ) and megabytes ( M ). The total space consumed by /home/jake is shown on the last line.
The find command is a great way to find file consumption of your hard disk using a variety of criteria. You can get a good idea of where disk space can be recovered by finding files that are over a certain size or were created by a particular person.
Note
You must be root user to run this command effectively, unless you are just checking your personal files. If you are not root user, there will be many places in the file system that you will not have permission to check. Regular users can usually check their own home directories but not those of others.
In the following example, the find command searches the root file system (
/
) for any files owned by the user named jake ( -user jake ) and prints the filenames. The output of the find command is organized in a long listing in size order ( ls -ldS
).
Finally that output is sent to the file /tmp/jake . When you view the file /tmp/jake
(for example, less /tmp/jake
), you will find all of the files that are owned by the user jake listed in size order. Here is the command line:
#
find / -user jake -print -xdev | xargs ls -ldS > /tmp/jake
Tip
The
-xdev option prevents file systems other than the selected file system from being searched. This is a good way to cut out a lot of junk that may be output from the
/proc file system. It could also keep large remotely mounted file systems from being searched.
Here’s another example, except that instead of looking for a user’s files, we’re looking for files larger than 100 kilobytes (
-size 100k
):
#
find / -size 100k -print -xdev | xargs ls -ldS > /tmp/size
You can save yourself a lot of disk space by just removing some of the largest files that are no longer needed. In this example you could see large files are sorted by size in the /tmp/size file.
If your Linux system is a multiuser computer, sharing the processing power of that computer can be a major issue. Likewise, anytime you can stop a runaway process or reduce the overhead of an unnecessary program running, your Linux server can do a better job serving files, Web pages, or e-mail to the people who rely on it.
10_579495 ch04.qxd 12/27/04 9:53 PM Page 167
Chapter 4
✦
Learning Basic Administration
167
Linux includes utilities that can help you monitor the performance of your Linux system. The kinds of features you want to monitor in Linux include CPU usage, memory usage (RAM and swap space), and overall load on the system. A popular tool for monitoring that information in Linux is the top command.
To start the top utility in a Terminal window, type
. The top command determines the largest CPU-consuming processes on your computer, displays them in descending order on your screen, and updates the list every five seconds.
By adding the
-S option to top
, the display shows you the cumulative CPU time for each process, as well as any child processes that may already have exited. If you want to change how often the screen is updated, you can add the
-d
secs
option, where
secs
is replaced by the number of seconds between updates.
By default, processes are sorted by CPU usage. You can sort processes numerically by PID (press N), by age (press A), by resident memory usage (press M), or by time
(press T). To return to CPU usage, press P. To terminate a process, type
and enter the PID of the process you want to kill (listed in the left column). Be careful to only kill processes you are sure you don’t need or want.
Although you may be using Linux as a single-user system, many of the tasks you must perform to keep your computer running are defined as administrator tasks. A special user account called the root user is needed to do many of the things necessary to keep Linux working as you would like it to. If you are administering a Linux system that is used by lots of people, the task of administration becomes even larger. You must be able to add and support users, maintain the file systems, and ensure that system performance serves your users well.
To help the administrator, Linux comes with a variety of command-line utilities and graphical windows for configuring and maintaining your system. Commands such as mkfs top and mount let you create and mount file systems, respectively. Tools like let you monitor system performance.
✦ ✦ ✦
10_579495 ch04.qxd 12/27/04 9:53 PM Page 168
11_579495 ch05.qxd 12/27/04 9:54 PM Page 169
Y
ou won’t tap into the real power of Linux until you have connected it to a network — in particular, the Internet.
Your computer probably has an Ethernet interface built in, so you can just plug a LAN (local area network) cable into it to connect to a LAN (hub or switch), DSL bridge or router, or cable modem. Some computers, particularly laptops, may have wireless Ethernet hardware built in.
Your computer also may have a dial-up modem. If you have an older computer that has no Ethernet card or you are in a situation in which you need to dial out over regular phone lines to reach your Internet service provider (ISP), you’d use this modem to get on the Internet.
This chapter describes how to connect your Linux system to the Internet. With broadband and wireless networks becoming more prevalent, Ethernet connections are turning out to be the most common means of connecting to the Internet. For dial-up connections, you’ll see how to use kppp (a dialer GUI that is often packaged with KDE desktops).
Sharing Internet connections with multiple desktop systems or even your own mail or Web server are not that difficult to do from a hardware perspective. However, there are some security and configuration issues to consider when you set out to expand how you use your Internet connection. Linux can be used as firewalls, routers, and a variety of server types to help you get this done.
✦ ✦ ✦ ✦
In This Chapter
Connecting to the Internet
Ethernet connections to the Internet
Dial-up connections to the Internet
✦ ✦ ✦ ✦
11_579495 ch05.qxd 12/27/04 9:54 PM Page 170
170
Part II ✦
Running the Show
Linux supports a wide range of wired and wireless network devices, as well as a dizzying array of network protocols to communicate over that media. As a home or small-office Linux user, you can start evaluating how to configure your connection to the Internet from Linux by considering the following:
✦
The type of Internet account you have with your ISP (dial-up or broadband)
✦
Whether you are connecting a single computer, a bunch of desktops, and/or one or more server machines to the Internet
Until recently, dial-up was the most common method for an individual to get onto the Internet. Many computers had dial-up modems built into the motherboard or had serial ports where a modem could easily be connected. Many computers today do not include modems, but serial or USB modems can be purchased for just a few dollars if you need to use dial-up.
Once you have a modem (56 Kbps speed is the standard today), the only other equipment you need is a regular telephone line. Essentially, you can use a dial-up modem anywhere you can connect to a phone line. Linux contains the tools you need to configure and complete a dial-up connection. Figure 5-1 shows the setup for the connection.
Serial port
Modem
Telephone jack
ISP
PPP connection to Internet
Linux workstation
Figure 5-1:
phone lines.
Connect a modem to a serial or USB port and dial out over regular
One difficulty with using modems in Linux is that many computers with built-in modems (especially laptops) come with what are referred to as
Winmodems.
With
Winmodems, some of the processing normally done on the modem is actually implemented within the Windows system. Winmodems don’t always look like real modems to Linux systems because without the code that’s inside Windows they don’t behave like real modems when they are connected to Linux systems.
11_579495 ch05.qxd 12/27/04 9:54 PM Page 171
Chapter 5
✦
Getting on the Internet
171
Note
Some Winmodems are supported in Linux, and those are sometimes referred to as
Linmodems.
If you find that Linux fails to detect your modem, check out the
Linmodems Support Page ( http://linmodems.technion.ac.il
). It can help you determine if you have a Winmodem and, if so, help you find the right Linmodem driver (if one is available).
If you find that you have a Winmodem, get a real modem instead. An inexpensive external serial modem can save you the trouble of getting and loading a Linmodem driver that may or may not work. Most external modems or internal PCI modems described as being “controller-based” work well in Linux.
Increasingly, individuals have the option of signing up for broadband Internet service with cable television providers or local telephone companies. These connections typically provide transmission speeds rated at least five times greater than you can get with a dial-up connection.
The equipment you need to make broadband connections from your home or small office is typically a cable modem or Digital Subscriber Line (DSL) modem. Cable modems share the bandwidth of the cable television line coming into your location.
DSL uses your house or office phone wires for both your Internet and phone services.
Because there are many ways that your ISP may be providing your Internet service, you should check with it to get the right hardware you need to connect. In particular, you should know that there are several incompatible DSL standards (ADSL, CDSL,
HDSL, SDSL, etc.), so you can’t just go out and buy DSL equipment without some guidance.
If you are using an external DSL or cable modem, chances are that a single connection from your Linux machine to that equipment requires only the following:
✦
An Ethernet port on your computer
✦
A LAN cable (often provided with the ISP equipment)
✦
The DSL router/bridge or cable modem (often provided by ISP)
Figure 5-2 illustrates a Linux computer connected to a broadband cable modem.
Broadband equipment often supplies a service called Dynamic Host Configuration
Protocol (DHCP). DHCP (which is discussed in Chapter 17) provides the Internet addresses and other information that a client computer needs to connect to the network. With the cable/DSL modem acting as a DHCP server, you can literally start using the Internet without doing any special configuration in Linux. Just plug in, boot Linux, and start browsing the Web.
11_579495 ch05.qxd 12/27/04 9:54 PM Page 172
172
Part II ✦
Running the Show
Firewall
(iptables)
Linux
DHCP
DSL router or cable modem
ISP
Linux Workstation
Broadband
Connection Route to Internet
Figure 5-2:
Connect an Ethernet card to broadband and start surfing.
Note
The DSL or cable modem often acts as a router between the ISP and your computer.
Alternatively, some broadband equipment operates in a “bridging mode,” in which it doesn’t do routing but simply passes data through as though your computer were on the same LAN as those of the ISP. In this setup, the public IP address is assigned to your computer instead of to the DSL or cable modem.
Instead of connecting your Linux computer directly to the cable modem or DSL equipment, you can join your machines together on a LAN, and then connect the
LAN to your ISP equipment so that everyone in the house or office can share the broadband connection. It’s fairly simple; you just connect your cable/DSL modem to your LAN instead of directly to your Linux box. In this configuration, though, you should consider adding a firewall/router as a buffer between your LAN and the outside world. That machine would perform such duties as:
✦
— A well-configured firewall blocks access to all ports except those that you need to access the Internet the way you want, thereby minimizing the risks of intruders getting into your LAN.
✦
— For the most part, you want the computers behind your firewall that are simply desktop systems to not be accessible to others from the Internet. By configuring your firewall to do NAT or IP Masquerading, your computers can be assigned private IP addresses. Your firewall then handles forwarding of messages between your LAN and the Internet. This is a good arrangement for several reasons. For one thing, the IP addresses of your private computers are not exposed to the outside world. Also, you can save the cost of paying your ISP for permanent IP addresses.
✦
— Many firewall systems can act as a DHCP server. Those private IP addresses you can use with a NAT firewall can be assigned from the
DHCP service running on your firewall system. When the client computer on your LAN starts up, besides its IP address, your DHCP service can tell the client the location of its DNS server, gateway to the Internet, or other information.
11_579495 ch05.qxd 12/27/04 9:54 PM Page 173
Chapter 5
✦
Getting on the Internet
173
Cross-
Reference
✦
— In the home and small-office LAN environment illustrated in Figure
5-3, the firewall computer often has two Ethernet interfaces: one connected to the LAN and the other to the DSL or cable modem that leads to the ISP. Because the Ethernet interfaces are viewed as being on separate subnetworks, the firewall/router must be configured to forward packets across the two interfaces.
It’s not a big deal, but it does require a separate step to tell the firewall system that you want it to forward packets between the two subnetworks.
Chapter 17 discusses setting up a firewall/router, using a Linux distribution designed specifically for the task.
Linux
Linux
Mac
Hub or switch
NAT
Linux firewall/router
Broadband connection
DHCP
ISP
Linux
Figure 5-3:
Windows
A firewall provides a safeguard between your LAN and the Internet.
In this example, the equipment you need includes:
✦
An Ethernet port on each computer
✦
A LAN cable for each computer
✦
A hub or a switch
✦
A low-end PC (as low as a 486 might do) running as a Linux firewall/router
✦
The DSL or cable modem
An alternative to this wired configuration is to replace the hub or switch with a wireless access point. Then each computer equipped with a wireless LAN card can get on the network without wires.
So far you’ve seen configurations that let one or more computers from your home or small business browse the Web. Letting someone from the Internet request services
(Web pages, file transfers, and so forth) from your computers requires some extra thought.
11_579495 ch05.qxd 12/27/04 9:54 PM Page 174
174
Part II ✦
Running the Show
Note
After you have TCP/IP (the primary set of protocols used on the Internet) configured to connect to your ISP, requests for data can pass in either direction between your computers and the Internet unless you use a firewall to restrict traffic. So the same connection you use for Internet browsing can be used to offer services to the
Internet, with a few caveats:
✦
— Each time you reboot your computer, your ISP’s
DHCP server dynamically assigns your DSL/cable modem’s IP address. For that reason, your IP address could change at each reboot. If you want your servers to be reachable on a permanent basis, you usually need at least one permanent IP address at which people can reach your servers. You will have to ask your ISP about a permanent IP address, and it might cost you extra money to have one.
A service called Dynamic DNS can be used in place of paying for a permanent IP address. With Dynamic DNS, you hire a service to constantly check whether your IP address has changed and assign your DNS host name to the new address if it does.
You can search the Web for “Dynamic DNS” to find companies that offer that service.
✦
— Check that you are allowed to have incoming connections. Some ISPs, especially for inexpensive, home-use broadband service, will block incoming connections to Web servers or mail servers.
✦
— Although typing an IP address into a browser location box works just fine, most people prefer to use names (such as www.linuxtrouble.
com ) to reach a server. That requires you to purchase a DNS domain name and have an entry set up in a DNS server to resolve the name to the IP address of your server.
Although there is nothing magical about setting up an Internet server, given the few issues just mentioned, creating a public server can be a lot like opening up the doors of your house so that strangers can wander in. You want some policies in place to restrict where the strangers can go and what they can do.
For home or small-office locations that have a single Internet connection (represented by one public IP address), servers can be more exposed to the Internet than desktop systems by keeping them in one area that’s referred to as the DMZ
(demilitarized zone). In this configuration (illustrated in Figure 5-4), servers are directly behind the outside firewall. Desktop systems (that aren’t to be accessible by people from the Internet), are behind a second, more restrictive firewall.
Whether you use Linux as your firewall machines or dedicated firewall devices, the outside firewall allows requests in for Web services (port 80), FTP services
(ports 20 and 21), simple mail transfer protocol (port 25), and possibly other services. The internal firewall blocks any requests for services from the outside and allows only Internet communications that were initiated from computers behind the inside firewall.
11_579495 ch05.qxd 12/27/04 9:54 PM Page 175
Chapter 5
✦
Getting on the Internet
175
Hub/switch
NAT
DHCP
Linux internal firewall/router
Servers
Switch
Linux external firewall/router
Broadband connection
ISP
Mail Web
FTP
Internal
Network
DM2
External
Network
Figure 5-4:
Add servers to a DMZ where they can be more publicly accessible than your desktop systems.
Cross-
Reference
Chapters 23 though 26 explain how to configure different server types, and Chapter 17 describes how to set up Linux as a router/firewall. Chapter 17 includes how to work with features such as IP Masquerading, NAT, and packet forwarding.
Although I’ve focused on basic Ethernet equipment and dial-up modems for configuring network connections, Linux supports many, many other types of network equipment as well as different protocols for communicating over that equipment.
Here are a few examples:
✦
— Integrated Services Digital Network (ISDN) lines were the preferred method of high-speed data lines to small businesses in the United States before DSL became widespread. It is still quite popular in Europe. ISDN4LINUX drivers and tools are available in many Linux systems for connecting to ISDN networks.
✦
— Support for token ring network cards is included in most Linux systems, although token rings are rarely used now. They were once popular at locations that had many IBM systems.
✦
— It’s possible to connect two computers from their parallel ports so that they can communicate using TCP/IP protocols. Parallel Line Internet Protocol
(PLIP) requires only a special cable; most Linux systems have built-in software that enables you to log in, transfer files, and perform other activities over that connection.
If your system has Linux source code installed, you can read about supported hardware devices in the documentation that comes with that source code. On Red Hat and some other Linux systems, the location of kernel documentation for various networking hardware is /usr/src/linux*/Documentation/networking .
11_579495 ch05.qxd 12/27/04 9:54 PM Page 176
176
Part II ✦
Running the Show
Here’s the general (default) way to bring up the network connection on a desktop system with Linux installed (or a bootable Linux launched):
Check whether you have an Ethernet card on your computer (most recent computers have one). If so, connect your Ethernet card to the equipment that gets you to the Internet (cable modem, DSL router/bridge, or network hub/switch). If not, you can purchase an Ethernet card at any retailer that sells computer hardware.
Ensure that appropriate drivers are available for the card and bring up the interface (typically, the first card is assigned to the eth0 interface). Usually, simply starting the computer causes the card to be detected and the appropriate driver loaded.
Get an IP address using DHCP if there is a DHCP server available through the interface. Most ISPs and businesses expect you to connect to their networks using DHCP, so they will have provided a DHCP server to the equipment where you connect your computer to the network.
As long as your desktop system is connected to a network that has a DHCP server willing to give it an IP address, you can be up and browsing the Web in no time.
If you find that the automatic method (DHCP) of connecting to your network doesn’t work, it gets a bit trickier to connect to the Internet. Different Linux distributions offer different tools for manually configuring your Internet connection. The following sections describe a few graphical tools and some command-line and configurationfile approaches to configuring wired and wireless network connections.
Many Linux install processes ask you if you want to configure your network connection for your Ethernet cards. This is typically just for your Ethernet cards and not for dial-up modems or other networking equipment. Information you’ll need for that process (IP address, gateway, DNS server, and so on) is explained in Chapter 7.
When you boot Linux, you can check whether you have access to the Internet by opening a Web browser (such as Mozilla or Konqueror) and typing in a Web address. If the Web site doesn’t appear in your browser, you’ll need to do some troubleshooting. The “Understanding Your Internet Connection” section later in this chapter provides information on how to track down problems with your Internet connection.
11_579495 ch05.qxd 12/27/04 9:54 PM Page 177
Chapter 5
✦
Getting on the Internet
177
Most major Linux distributions offer graphical tools for configuring network interfaces. These tools step you through the information you need to enter and then start up the network interface (if you choose) to begin browsing the Web.
Here is a list of tools for configuring network interfaces in a few different Linux distributions. Some of these are graphical tools, and some are menu-based:
✦
— The Network Configuration window lets you configure network connection using Ethernet, ISDN, modem, Token Ring, Wireless, and xDSL hardware. Start the Network Configuration window from the red hat menu by selecting System Settings
➪
Network or by typing
and entering the root password when prompted. (On older Red Hat Linux systems, the command was redhat-config-network .)
✦
— The YaST Control Center that comes with SUSE contains features for configuring your network. From the SUSE menu on the panel, select
System
➪
YaST, and then choose Network Devices. The YaST Control Center lets you configure a DSL, ISDN, Modem, or Network Card interface to the network. Select Network Card to configure your wired Ethernet Interface to the
Internet.
✦
— From a shell (as root user), type
to start a menu-driven interface to configure the network connection from your first
Ethernet card (eth0). The tool lets you have the interface try to start using
DHCP or use static address information that you provide yourself.
✦
— Select the squished penguin icon in the panel on the KNOPPIX desktop, and choose Networking/Internet from the menu. Select the Network card configuration menu entry to configure your network card. Or select from several other network equipment types instead (ADSL, GPRS, ISDN, Modem, or Wavelan).
Note
If you did not configure your LAN connection during installation of Fedora Linux, you can do so at any time using the Network Configuration window. The IP address and host names can be assigned statically to an Ethernet interface or retrieved dynamically at boot time from a DHCP server.
A computer can have more than one IP address because it can have multiple network interfaces. Each network interface must have an IP address (even if the address is assigned temporarily). So, if you have two Ethernet cards (eth0 and eth1),
11_579495 ch05.qxd 12/27/04 9:54 PM Page 178
178
Part II ✦
Running the Show
each needs its own IP address. Also, the address 127.0.0.1 represents the local host so that users on the local computer can access services in loopback.
Here’s how to define the IP address for your Ethernet interface in Fedora Linux:
From the red hat menu, choose System Settings
➪
Network or, as root user from a Terminal window, type
. (If prompted, type the root password.) The Network Configuration window appears.
Click the Devices tab. A listing of your existing network interfaces appears.
Double-click the eth0 interface (representing your first Ethernet card). A popup window titled Ethernet Device appears (see Figure 5-5), enabling you to configure your eth0 interface.
Figure 5-5:
Configure and activate Ethernet devices in Fedora.
Select your preferences:
Check here to have eth0 start at boot time.
users enable and disable the network interface.
Check to let non-root
Check here if you are connected to an IPV6 network. (Most networks are still IPV4.)
You also must choose whether to get your IP addresses from another computer at boot time or enter the addresses yourself:
11_579495 ch05.qxd 12/27/04 9:54 PM Page 179
Chapter 5
✦
Getting on the Internet
179
Select this box if you have a DHCP or BOOTP server on the network from which you can obtain your computer’s IP address, netmask, and gateway. DHCP is recommended if you have more than just a couple of computers on your
LAN. Optionally, you can set your own host name, which can be just a name (such as jukebox
) or a fully qualified domain name (such as jukebox.linuxtoys.net
).
If there is no DHCP or other boot server on your LAN, add necessary IP address information statically by selecting this option and:
Typing the IP address of the computer into the Address box. This number must be unique on your network. For your private LAN, you can use private IP addresses.
Entering the netmask (described later in this chapter) in the Subnet Mask box. The netmask indicates the part of the IP address that represents the network.
Typing the IP address of the computer into the Default Gateway Address box if a computer or router connected to your LAN provides routing functions to the Internet or other network. (Chapter 16 describes how to use NAT or IP Masquerading and how to use Fedora as a router.)
Click OK in the Ethernet Device window to save the configuration and close the window.
Click File
➪
Save to save the information you entered.
Click Activate in the Network Configuration window to start your connection to the LAN.
Each time you use a name to identify a computer, such as when browsing the Web or using an e-mail address, the computer name must be translated into an IP address.
To resolve names to IP addresses, Fedora goes through a search order (based on the contents of three files in /etc : resolv.conf
, nsswitch.conf
, and host.conf
). By default, it checks host names you add yourself (which end up in the /etc/hosts file), hosts available via NIS, and host names available via DNS.
You can use the Network Configuration window to add the following:
✦
You might do this to identify hosts on your LAN that are not configured on a DNS server.
✦
By adding domain names to a search path (such as linux toys.net
), you can browse to a site by its host name (such as jukebox
) and have Linux search the domains you added to the search path to find the host you are looking for (such as jukebox.linuxtoys.net
).
11_579495 ch05.qxd 12/27/04 9:54 PM Page 180
180
Part II ✦
Running the Show
Note
✦
A DNS server can resolve addresses for the domains it serves and contact other DNS servers to get addresses for all other DNS domains.
If you are configuring a DNS server, you can use that server to centrally store names and IP addresses for your LAN. This saves you the trouble of updating every computer’s
/etc/hosts file every time you add or change a computer on your LAN.
To add host names, IP addresses, search paths, and DNS servers, follow these steps:
Start the Network Configuration. As root user from a Terminal window, type
, or from the red hat menu, click System Settings
➪
Network. The Network Configuration window appears.
Click the Hosts tab. A list of IP addresses, host names, and aliases appears.
Click New. A pop-up window (see Figure 5-6) appears.
Figure 5-6:
and alias.
Add an IP address, host name,
Type in the IP address number, host name, and, optionally, the host alias.
Click OK.
Repeat this process until you have added every computer on your LAN that cannot be reached by DNS.
Click the DNS tab.
11_579495 ch05.qxd 12/27/04 9:54 PM Page 181
Chapter 5
✦
Getting on the Internet
181
Type the IP address of the computers that serve as your Primary and
Secondary DNS servers. (You get these IP addresses from your ISP, or if you created your own DNS server, you can enter that server’s IP address.)
Type the name of the domain (probably the name of your local domain) to be searched for host names into the DNS Search Path box.
Click File
➪
Save to save the changes.
Click File
➪
Quit to exit.
Now, when you use programs such as ftp, ssh, or other TCP/IP utilities, you can use any host name that is identified on your local computer, exists in your search path domain, or can be resolved from the public Internet DNS servers. (Strictly speaking, you don’t have to set up your /etc/hosts file. You could use IP addresses as arguments to TCP/IP commands, but names are easier to work with.)
If your Ethernet interface to the Internet is not working, there are ways to check what’s happening that will work on many Linux distributions. Use the following procedure to find out how your network interfaces are working:
Open a shell (if you are using a graphical interface, open a Terminal window).
Type the following right after you boot your computer to verify whether Linux found your card and installed the Ethernet interface properly:
dmesg | grep eth
The dmesg command lists all the messages that were output by Linux at boot time. The grep eth
eth
command causes only those lines that contain the word to be printed. Here are a couple of examples: eth0: NE2000 Compatible: port 0x300, irq3, hw_addr
00:80:C8:8C:8E:49 eth0: OEM i82557/i82558 10/100 Ethernet at 0xccc0,
00:90:27:4E:67:35, IRQ 17.
The first message appeared on my laptop computer with the Netgear card.
It shows that a card was found at IRQ3 with a port address of 0x300 and an Ethernet hardware address of
00:80:C8:8C:8E:49
. The second example is from my computer with the EtherExpress Pro/100 card. In it, the card is at
IRQ 17
, the port address is
0xccc0
, and the Ethernet address is
00:90:
27:4E:67:35 .
11_579495 ch05.qxd 12/27/04 9:54 PM Page 182
182
Part II ✦
Running the Show
Note
If the eth0 interface is not found, but you know that you have a supported
Ethernet card, type lspci -vv | grep -i eth to see if the Ethernet card is detected on the PCI bus. If it doesn’t appear, check that your Ethernet card is properly seated in its slot.
To view which network interfaces are up and running, type the following:
$
/sbin/ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:D0:B7:66:9A:46 inet addr:10.0.0.5 Bcast:10.0.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:326100 errors:0 dropped:0 overruns:0 frame:0
TX packets:215931 errors:0 dropped:0 overruns:0 carrier:0 collisions:5919
RX bytes:168378315 (160.5 Mb) TX bytes:40853243 (38.9 Mb) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:37435 errors:0 dropped:0 overruns:0 frame:0
TX packets:37435 errors:0 dropped:0 overruns:0 carrier:0 collisions:0
RX bytes:2353172 (2.2 Mb) TX bytes:2353172 (2.2 Mb)
The output shows a loopback interface (lo) and one Ethernet card (eth0). The
Ethernet interface (eth0) is assigned the IP address of 10.0.0.5. In this example, the eth0 has an IP address of 10.0.0.5.
Communicate with another computer on the LAN. The ping command can be used to send a packet to another computer and to ask for a packet in return.
You could give ping either a host name ( pine ) or an IP address ( 10.0.0.10
).
For example, to ping a computer on the network called pine
, type the following command:
# ping pine
If the computer can be reached, the output will look similar to the following:
PING pine (10.0.0.10): 56(84) data bytes
64 bytes from pine (10.0.0.10): icmp_seq=1 ttl=255 time=0.351 ms
64 bytes from pine (10.0.0.10): icmp_seq=2 ttl=255 time=0.445 ms
64 bytes from pine (10.0.0.10): icmp_seq=3 ttl=255 time=0.409 ms
64 bytes from pine (10.0.0.10): icmp_seq=4 ttl=255 time=0.457 ms
64 bytes from pine (10.0.0.10): icmp_seq=5 ttl=255 time=0.401 ms
64 bytes from pine (10.0.0.10): icmp_seq=6 ttl=255 time=0.405 ms
64 bytes from pine (10.0.0.10): icmp_seq=7 ttl=255 time=0.443 ms
64 bytes from pine (10.0.0.10): icmp_seq=8 ttl=255 time=0.384 ms
64 bytes from pine (10.0.0.10): icmp_seq=9 ttl=255 time=0.365 ms
11_579495 ch05.qxd 12/27/04 9:54 PM Page 183
Chapter 5
✦
Getting on the Internet
183
64 bytes from pine (10.0.0.10): icmp_seq=10 ttl=255 time=0.367 ms
--- pine ping statistics ---
10 packets transmitted, 10 packets received, 0% packet loss, time
9011ms rtt min/avg/max/mdev = 0.351/0.402/0.457/0.042 ms
A line of output is printed each time a packet is sent and received in return. It shows how much data was sent and how long it took for each package to be received. Watch this for a while, and then press Ctrl+C to stop ping ; you’ll see statistics on how many packets were transmitted, received, and lost.
If the output doesn’t show that packets have been received, then there’s no contact with the other computer. Verify that the names and addresses of the computers that you want to reach are in your
/etc/hosts file or that your
DNS server is accessible. Next, confirm that the names and IP addresses you have for the other computers you are trying to reach are correct (the IP addresses are the most critical).
If you are able to reach an IP address on your LAN with ping but are unable to ping a host computer by name, you may not be communicating with your DNS server. Repeat the ping command with the IP address of your DNS server to see if it is up and that you are able to communicate with it.
Check your DHCP information. If you obtained your IP address from a DHCP server, chances are your DHCP server fed your computer other information it needed to use the network as well. Look for a file that contains information about your DHCP lease. The lease includes information about the address that has been assigned to you as well as how long you can keep it. In Fedora, lease information is held in the
/var/lib/dhcp/dhclient-eth0.leases
file.
Here’s an example of information from that file: lease { interface “eth0”; fixed-address 10.0.0.204; option subnet-mask 255.255.255.0; option routers 10.0.0.1; option dhcp-lease-time 21600; option dhcp-message-type 5; option domain-name-servers 10.0.0.2; option domain-name-servers 10.0.0.3; option dhcp-server-identifier 10.0.0.5; option domain-name “linuxtrouble.com”; renew 3 2004/7/21 01:23:06; rebind 3 2004/7/21 04:22:48; expire 3 2004/7/21 05:07:48;
}
Here you can see that the IP address assigned to the machine is 10.0.0.204, with a subnet mask of 255.255.255.0. The machine acting as the router to the Internet
11_579495 ch05.qxd 12/27/04 9:54 PM Page 184
184
Part II ✦
Running the Show
(also called the
gateway
) is 10.0.0.1. The DNS servers are 10.0.0.2 and 10.0.0.3
(you can ping those numbers to see if you can reach your DNS servers).
Many individuals and even some small businesses that need to connect to the
Internet still do so using modems and telephone lines. The modem connects to a serial port (COM1, COM2, and so on) on your computer and then into a telephone jack. Your computer dials a modem at your Internet service provider or business that has a connection to the Internet.
The most common protocol for making dial-up connections to the Internet (or other
TCP/IP network) is Point-to-Point Protocol (PPP). Let’s look at how to use PPP protocol to connect to the Internet.
To establish a PPP connection, you need to get some information from the administrator of the network to which you are connecting. This is either your Internet service provider (ISP) when you sign up for Internet service, or the person in your workplace who wears a pocket protector and walks around carrying cables, two or more cellular phones, and a couple of beepers (when a network goes down, these people are in demand!). Here is the kind of information you need to set up your PPP connection:
✦
— Gives you access to the modem (or pool of modems) at the ISP. If it is a national ISP, make sure that you get a local or toll-free telephone number (otherwise, you’ll rack up long-distance fees on top of your ISP fees).
✦
— Used to verify that you have an Internet account with the ISP. This is an account name when you connect to Linux or other UNIX system but may be referred to as a system name when you connect to an NT server.
✦
— Most ISPs use dynamic IP numbers, which means that you are assigned an IP number temporarily when you are connected. Your ISP assigns a permanent IP number if it uses static IP addresses. If your computer or all the computers on your LAN need to have a more permanent presence on the network, you may be given one static IP number or a set of static IP addresses to use.
✦
— Your computer translates Internet host names to IP addresses by querying a Domain Name System (DNS) server. Your ISP should give you at least one IP address for a preferred (and possibly alternate)
DNS server.
✦
— You may need a PAP (Password Authentication
Protocol) ID or CHAP (Challenge Handshake Authentication Protocol) ID and a secret, instead of a username and password when connecting to a Windows
11_579495 ch05.qxd 12/27/04 9:54 PM Page 185
Chapter 5
✦
Getting on the Internet
185
NT system. These features are used with authentication on Microsoft and some other operating systems. Linux and other UNIX servers don’t typically use this type of authentication, although they support PAP and CHAP on the client side.
Your ISP will tell you if you are using PAP or CHAP.
Your ISP typically provides services such as news and mail servers for use with your
Internet connection. To configure these useful services, you need to acquire the following information:
✦
— If your ISP is providing you with an e-mail account, you must know the address of the mail server, the type of mail service (such as POP3 —
Post Office Protocol — or IMAP — Internet Message Access Protocol), and the authentication password for the mail server so you can get your e-mail.
✦
— If your ISP provides the name of a news server so that you can participate in newsgroups, the server may require you to log on, so you will need a password. The ISP provides that password, if required.
After you’ve gathered this information, you’re ready to set up your connection to the Internet. To configure Linux to connect to your ISP, read on.
PPP is used to create IP connections over serial lines. Most often, the serial connection is established over a modem; however, it also works over serial cables
(null modem cables) or digital lines (including ISDN and DSL).
Although one side must dial out and the other side must receive the call to create the PPP connection over a modem, after the connection is established, information can flow in both directions. For the sake of clarity, however, I refer to the computer placing the call as the client and the computer receiving the call as the server.
To simplify the process of configuring PPP (and other network interfaces), most
Linux systems include graphical tools to configure dial-up. Two such tools are:
✦
— From the main desktop menu in Fedora, choose System Tools
➪
Internet Configuration Wizard. The Select Device
Type window that appears enables you to configure and test your dial-up
PPP connection.
✦
— From the KDE desktop, select Internet
➪
KPPP, or from a Terminal window run the kppp command. From the KPPP window you can set up and launch a PPP dial-up connection.
Before you begin either of these procedures, physically connect your modem to your computer, plug it in, and connect it to your telephone line. If you have an inter-
11_579495 ch05.qxd 12/27/04 9:54 PM Page 186
186
Part II ✦
Running the Show
nal modem, you will probably see a telephone port on the back of your computer to which you need to connect. If your modem isn’t detected, you can reboot your computer or run it detected.
wvdialconf create (as described later in this chapter) to have
Use the Internet Configuration Wizard to set up dial-up networking in Fedora.
Here’s how:
Choose System Tools
➪
Internet Configuration Wizard from the main menu.
(Type the root password, if prompted.) A Select Device Type window appears
(see Figure 5-7).
Figure 5-7:
The Internet Configuration Wizard helps you set up a PPP Internet connection.
Select Modem connection and click Forward. The wizard searches for a modem, and then the Select Modem window appears.
Select the following modem properties:
— If the modem is connected to your first serial port
(COM1), you can select /dev/ttyS0 ; for the second serial port (COM2) choose /dev/ttyS1 . (By convention, the device is often linked to
/dev/modem . Type
to see if it is linked to /dev/ttyS0 ,
/dev/ttyS1 , or another tty device.)
— The rate at which the computer talks to the modem (which is typically considerably faster than the modem can talk over the phone
11_579495 ch05.qxd 12/27/04 9:54 PM Page 187
Chapter 5
✦
Getting on the Internet
187 lines). The default is 115200 bits per second, which is probably fine for dial-up connections.
— Check the modem documentation to see if the modem supports hardware flow control (CRTSCTS). If it doesn’t, select software flow control (XON/XOFF). Flow control prevents more data than the modem can handle from being sent to it.
— This is off by default because the noise can be annoying, but if you select medium while you’re setting up the modem, the sound can give you a sense of where things are stopping if you can’t get a connection. You can turn it off after everything’s working.
— Leave this check box on in most cases. If for some reason your phone system doesn’t support touch-tone dialing, you can turn it off.
Click Forward. The Select Provider window appears. Enter the following provider information:
— If you are using Internet service in any of the countries shown in the Internet Provider window, select the plus sign next to that country’s name. If your Internet service provider appears in the National list, select it. Information is automatically filled in for that provider. Otherwise, you need to fill in the rest of the dialog window.
— The telephone number of the ISP you want to dial in to. (An optional prefix is available in case you need to dial 9 or some other number to get an outside dial tone.)
— The name of the Internet service provider. In the current release of Fedora, there is a bug that causes the dial-up to fail if you use any provider name other than ppp0 . If that has not been fixed, please use ppp0 here as the provider name. (For multiple dial-up accounts, use ppp1 , ppp2 , and so on.)
— The login name assigned to you by the ISP. The ISP may have called the login name a login ID or something similar.
— The password associated with the login name.
Click Forward, and the IP Settings window appears. With a dial-up connection, you would typically select Automatically Obtain IP Address Settings. However, if the ISP has assigned a static IP address that you can use, click the Statically
Set IP Addresses check box, and then enter your IP address, subnet mask, and default gateway address in the appropriate fields. Click Forward to continue.
The Create Dialup Connection window appears, displaying the information you just entered. If all the information looks correct, click Apply (otherwise, click the Back button, correct your information, and click Forward again to return to this window).
After you click Apply, the Network Configuration window appears, ideally with a new PPP connection of modem type appearing in the window. (If it doesn’t appear, select System Settings
➪
Network.)
11_579495 ch05.qxd 12/27/04 9:54 PM Page 188
188
Part II ✦
Running the Show
Select the new dial-up entry (so it is highlighted), and choose File
➪
Save to save its new dial-up configuration.
Now select the PPP device name and click the Activate button. The Internet dialer starts up and dials your ISP. (If you have sound turned on, you should hear your modem dialing out.) If everything is working properly, your login and password are accepted, and the PPP connection is completed.
Try opening Mozilla or another Web browser to see if you can access a Web site on the Internet. If this doesn’t work the first time, don’t be discouraged. Skip ahead to the “Checking Your PPP Connection” section to see what to check to get your dialup PPP connection working.
Your dial-up connection is now configured, but it is not set to connect automatically.
One way to start the connection is to set it up to launch manually from the desktop panel. Here’s how:
From the GNOME desktop:
Right-click the panel and choose Add to Panel
➪
Launcher from Menu
➪
System Settings
➪
Network from the main menu. An icon appears on the panel that you can click to open the Network Configuration window.
Select the new icon from the panel. A Network Configuration window appears.
Select the dial-up interface you added (probably ppp0
) and click Activate to connect.
From the KDE desktop:
Right-click the panel and choose Add
➪
Application Button
➪
System Settings
➪
Network from the main menu.
Select the new icon from the panel (type the root password, if prompted). A
Network Configuration window appears.
Select the dial-up interface you added (probably ppp0
) and click Activate to connect.
From this point forward, icons appear on your desktop that you can click to immediately connect to your ISP over the dial-up connection you configured.
11_579495 ch05.qxd 12/27/04 9:54 PM Page 189
Chapter 5
✦
Getting on the Internet
189
Instead of starting a dial-up PPP connection manually each time you want to contact the Internet from Fedora, you can set your dial-up connection to start automatically when an application (such as a Web browser or e-mail program) tries to use the connection. On-demand dialing is particularly useful if
✦
The dial-up connection on your Linux system is acting as the gateway for other computers in your home or office. You don’t have to run over to your
Linux box to start the connection when another computer needs the dial-up connection.
✦
Programs that you run during off hours, such as remote backups, require an
Internet connection.
✦
You don’t want to be bothered clicking an extra icon when you just want to browse the Web a bit.
The risk of on-demand dialing is that because it gets going automatically, the dial-up connection can start up when you don’t want it to. (Some people get worried when their computers start dialing by themselves in the middle of the night.)
Here is an example of settings you can add to your dial-up configuration file (probably / etc/sysconfig/network-scripts/ifcfg-ppp0 ) to configure on-demand dialing:
ONBOOT=yes
DEMAND=yes
IDLETIMEOUT=600
RETRYTIMEOUT=30
Note
The ONBOOT=yes because DEMAND starts the pppd daemon (but doesn’t immediately begin dialing is set to yes ). Also, because DEMAND=yes , a dial-up connection attempt is made anytime traffic tries to use your dial-up connection. With IDLE
TIMEOUT set to 600 , the connection is dropped after 600 seconds (10 minutes) with no traffic on the connection. With RETRYTIMEOUT set to 30 , a dropped connection is retried after 30 seconds (unless the connection was dropped by an idle timeout, in which case there is no retry). You can change the timeout values as it suits you.
Because it can take a bit of time for dial-up connections to be established, operations may fail while dialing occurs. In particular, DNS requests can time out in 30 seconds, which may not be long enough to establish a dial-up connection. If you have three
DNS servers configured for each client, you have a 90-second timeout period. As a result, the modem connection may be running before the request fails.
11_579495 ch05.qxd 12/27/04 9:54 PM Page 190
190
Part II ✦
Running the Show
The following information will help you debug your PPP connection or simply better understand how it works.
It is possible that your modem is not supported under Linux. If that is the case, your PPP connection might be failing because the modem was not detected at all.
To scan your serial ports to see where your modem might be, type the following
(as root user):
$
wvdialconf /etc/wvdial.conf.new
The wvdialconf conf command is really to build a configuration file (the file) that is used by the dialer command ( wvdial
/etc/wvdial.
). (You only need this file if you use wvdial to do your dial-up.) Its first action, however, is to scan the serial ports on your computer and report where it finds modems. If it tells you that “no modem was detected,” it’s likely that either your modem isn’t connected properly or no driver is available to support the modem.
If the modem wasn’t detected, you should determine whether it is a modem supported in Linux. You can do this by finding out what type of chip set is used in the modem. This is even more important than finding out the manufacturer of the modem because the same manufacturer can use chips from different companies.
(This applies primarily to internal modems because most external serial modems and many USB modems are supported in Linux.)
After you have determined the chip set being used, check the Linmodems.org Web site ( www.linmodems.org
), which contains information on so-called Winmodems that have only recently begun to be supported in Linux. Search for the chip set on your modem from this site. In many cases, the site tells you if there is a driver available for your modem.
Many different tools are available for configuring network connections in the various
Linux distributions. Fedora and other Red Hat Linux systems use a graphical Network
Configuration. SUSE Linux uses its YaST administrative interface to configure network equipment. For dial-up networks, the KDE desktop includes the KPPP GUI tool for configuring modems. If your network connection doesn’t start up automatically
(as it does in many cases), this chapter explains how to use some of these network configuration tools to configure it manually.
By adding your computer to a public network, such as the Internet, you open it to possible intruders. The next chapter describes ways in which you can secure your
12_579495 ch06.qxd 12/27/04 9:48 PM Page 191
S
ince the dawn of interconnected networks, some user has been trying to break into other users’ systems. As the Internet has grown and broadband Internet access has spread, the problem has only become more severe. A home computer running an insecure configuration can be used as a powerful mail relay, storage for traffic in pirated data, allow the user’s personal information to become compromised, or any number of other such horrors.
Once upon a time network attacks required some effort and skill on the part of the attacker. Today automated tools can get even the most novice user up and running trying to compromise network-attached systems in an alarmingly short time. Additionally, worms have the capability to turn large numbers of insecure Win32 systems into an army of “zombies” usable for massive coordinated Denial of Service attacks.
Why should you care about security? According to the Internet
Storm Center ( http://isc.sans.org
), a computer connected to the Internet has 16 minutes before it falls under some form of attack. Securing any computer system is not hugely difficult; it simply requires some common sense and careful application of good security practices.
In many cases, good practices for setting and protecting passwords, monitoring log files, and creating good firewalls will keep out many would-be intruders. Sometimes, more proactive approaches are needed to respond to break-ins. Use this chapter to familiarize yourself, as a Linux administrator, with the security dangers that exist and the tools necessary to protect your system.
✦ ✦ ✦ ✦
In This Chapter
Protecting against
Denial of Service
(DoS) attacks
Preventing network break-ins
Using log files to detect intrusions
Improving security with strong passwords
Using encryption techniques
Security auditing tools
Guarding your computer with
PortSentry
✦ ✦ ✦ ✦
12_579495 ch06.qxd 12/27/04 9:48 PM Page 192
192
Part II ✦
Running the Show
Just as closing and locking the doors and windows of your house helps keep burglars from wandering in off the street, so will some basic security precautions keep most intruders out of your computer system. There are also some simple techniques for monitoring your system (like watching system log files and checking for people scanning your ports) that enable you to take an active role in responding to intrusions.
If you think that nobody will break into your computer because there’s nothing on it worth stealing, think again. Often, a system is broken into solely to gain use of it as a jumping-off point to launch further attacks on other systems. And crackers might try to hijack your computer to serve up copyrighted materials or pornography from your system.
Linux (and similar UNIX and BSD systems) were designed to give you the tools to protect your computers from intruders. Your job is to learn a bit about those tools and utilize them in ways to keep your computer safe. You can start by applying a few rules for your own personal computer use:
✦
Use strong passwords (discussed later in this chapter). Simple “dictionary word” passwords (even those using number-to-letter substitution) are woefully easy to crack with freely available automated tools.
✦
Be skeptical of unsolicited e-mail. Don’t open and run executable files that come to you in e-mail attachments that you don’t know to be trustworthy. If an e-mail comes in telling you that you need a critical update (and tells you
“click here to get it”), make sure that the message came from a valid source.
✦
Know the source of the software you allow on your computer. Download software only from valid mirror sites associated with the Linux distribution you use or from a reputable project site. Be sure to check the md5sum of iso images you download to be sure the image isn’t corrupted or hasn’t been tampered with.
The following tips will help you as the network administrator (which you are if you connect your computer to the Internet) prevent the majority of malicious network activity from taking you out of order:
✦
Always place a firewall between your systems and public or unsecured networks such as the Internet. Ideally this should be a standalone device, but that is not essential. If your Linux system is directly connected to the Internet, the firewall features covered in detail in Chapter 17 will help you configure Linux to only allow requests for services you want to provide to the Internet and filter out other traffic trying to get into your system.
✦
Keep tabs on the kinds of activity to which your system is exposed. Regularly monitoring your log files helps make you better able to identify the beginnings of suspicious activity. You can even monitor network ports on your system to watch for attempts by intruders to scan those ports to find vulnerabilities.
(Refer to the Syslog and Portsentry sections later in this chapter for information on tools for watching your system.)
12_579495 ch06.qxd 12/27/04 9:48 PM Page 193
Chapter 6
✦
Securing Linux
193
Tip
✦
Get security updates regularly. All major Linux distributions offer tools and software repositories for getting fixes for security vulnerabilities to you as they are discovered and patched. Getting those critical patches is often as simple as running a single command that downloads and installs the patches.
Several Web sites provide excellent vulnerability, outbreak, and mitigation information including www.isc.sans.org
(general Internet attack information), www.
sarc.com
(virus outbreak information), www.cert.org
mation), and www.securityfocus.com
(software security infor-
(general security Web site).
✦
Disable network services you do not need. Any service that isn’t actively being used is just a liability. Shut it down and rest easier knowing that there’s one less route of entry into your systems.
Attacks on computing systems take on different forms, depending on the goal and resources of the attacker. Some attackers want to be disruptive, while others want to infiltrate your machines and utilize your resources for their own nefarious purposes.
Still others are targeting your data for financial gain or blackmail. Some common attacks that are described in this section include Denial of Service, Distributed
Denial of Service, and intrusion attacks.
Denial of Service (DoS) attacks are the easiest to perpetrate. The primary purpose of these attacks is to disrupt the activities of a remote site by overloading it with irrelevant data. DoS attacks can be as simple as sending thousands of page requests per second to a Web site. These types of attacks are fairly easy to resolve: after you get a handle on where the attack is coming from, a simple phone call to the perpetrator’s ISP gets the problem solved.
Advanced DoS attacks are called
Distributed Denial of Service (DDoS) attacks
. They are much harder to execute and nearly impossible to stop. The attacker takes control of hundreds or even thousands of weakly secured Internet-connected computers and then directs them in unison to send a stream of irrelevant data to a single Internet host. The result is that the power of one attacker is magnified thousands of times.
Instead of an attack coming from one direction, as in the usual DoS, it comes from thousands of directions at once. The best defense against a DDoS attack is to contact your own ISP to see if it can filter traffic at its border routers.
Many people use the excuse “I have nothing on my machine anyone would want” to avoid considering security. The problem with this argument is that attackers have a lot of reasons to use your machine. The attacker can turn your machine into an agent for later use in a DDoS attack. More than once, authorities have shown up at the door of a dumbfounded computer user asking questions about threats originating from the user’s computer. By ignoring security, owners have opened themselves up to a great deal of liability.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 194
194
Part II ✦
Running the Show
Although DoS attacks are disruptive, intrusion-type attacks are the most damaging.
The reasons are varied, but the result is always the same: An uninvited guest takes up residence on your machine and uses it in a way over which you have no control.
To remotely use the resources of a target machine, an attacker must first look for an opening to exploit. In the absence of inside information such as passwords or encryption keys, he must scan the target machine to see what services are offered.
Perhaps one of the services is weakly secured, and the attacker can use some known exploit to finagle his way in.
Note
A tool called nmap is generally considered the best way to scan a host for services.
Once the attacker has a list of the available services running on his target, he needs to find a way to trick one of those services into letting him have privileged access to the system. This is usually done with a program called an
exploit,
which uses known vulnerabilities in a service to ask the service to run an alternate program, change a configuration file, or give out information about the system.
Besides being used as an intrusion tool, nmap can be used by a computer’s own system administrator to check the security of the machine. You can use nmap on your own machine to see what an attacker would see if he scanned your system, enabling you to fill potential security holes.
As explained earlier, a Denial of Service attack attempts to crash your computer or at least degrade its performance to an unusable level. There are a variety of DoS exploits. Most try to overload some system resource, such as your available disk space or your Internet connection. Some common attacks and defenses are discussed in the following sections.
Mailbombing
is the practice of sending so much e-mail to a particular user or system that the computer’s hard drive becomes full. There are a couple of ways to protect yourself from mailbombing: Use the Procmail e-mail-filtering tool or configure your sendmail daemon.
The Procmail e-mail-filtering tool is available in many Linux distributions and is tightly integrated with the sendmail e-mail daemon. This integration allows Procmail to selectively block or filter out specific types of e-mail. You can learn more about it at www.procmail.org
.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 195
Chapter 6
✦
Securing Linux
195
To enable Procmail for your user account, create a .procmailrc
directory. The file should be mode
0600 file in your home
(readable by you but nobody else). Type the following, replacing bombing you.
evilmailer
with the actual e-mail address that is mail-
#
Delete mail from
evilmailer
:0
* ^From.*
evilmailer
/dev/null
The Procmail recipe looks for the From line at the start of each e-mail to see if it includes the string
evilmailer
. If it does, the message is sent to
/dev/null
(effectively throwing it away).
The Procmail e-mail tool works quite well when only one user is being mailbombed.
If, however, the mailbombing affects many users, you should probably configure your sendmail daemon to block all e-mail from the mailbomber. Do this by adding the mailbomber’s e-mail address or system name to the
/etc/mail directory.
access file located in the
Each line of the access file contains an e-mail address, host name, domain, or IP address followed by a tab and then a keyword specifying what action to take when that entity sends you a message. Valid keywords are
OK
,
RELAY
,
REJECT
,
DISCARD
, and ERROR . The REJECT keyword causes a sender’s e-mail to be bounced back with an error message. The keyword
DISCARD causes the message to be silently dropped without sending an error back. You can even return a custom error message by using the
ERROR keyword.
Here’s an example
/etc/mail/access file:
# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package.
#
# by default we allow relaying from localhost...
localhost.localdomain RELAY localhost RELAY
127.0.0.1 RELAY
#
# Senders we want to Block
# [email protected] REJECT stimpy.glaci.com REJECT cyberpromo.com DISCARD
199.170.176.99 ERROR:”550 Die Spammer Scum!”
199.170.177 ERROR:”550 Email Refused”
12_579495 ch06.qxd 12/27/04 9:48 PM Page 196
196
Part II ✦
Running the Show
As with most Linux configuration files, lines that begin with a # pound sign are comments. The list of blocked spammers is at the end of this example file. Note that the address to block can be a complete e-mail address, a full host name, a domain only, an IP address, or a subnet.
To block a particular e-mail address or host from mailbombing you, log in to your system as root, edit the /etc/mail/access from the offending sender.
file, and add a line to DISCARD mail
After saving the file and exiting the editor, you must convert the access file into a hash-indexed database called access.db
. The database is updated automatically the next time sendmail starts. Or you can convert the database immediately, as follows:
#
cd /etc/mail
#
make
Sendmail should now discard e-mail from the addresses you added.
Another way in which your e-mail services can be abused is by having your system used as a spam relay.
Spam
refers to the unsolicited junk e-mail that has become a common occurrence on the Internet. Spammers often deliver their annoying messages from a normal dial-up Internet account. They need some kind of high-capacity e-mail server to accept and buffer the payload of messages. They deliver the spam to the server all in one huge batch and then log off, letting the server do the work of delivering the e-mail to the many victims.
Naturally, no self-respecting Internet service provider (ISP) cooperates with this action, so spammers resort to hijacking servers at another ISP to do the dirty work.
Having your mail server hijacked to act as a spam relay can have a devastating effect on your system and your reputation. There are even Internet “blacklists” that are used to ban communications with servers that allow open relay.
Note
If your system is used to forward mass mailing, you could find your mail server unable to deliver e-mail to some other e-mail servers because you have been blacklisted. On many Linux installations, open mail relay is disabled by default. You can either upgrade to the latest build of sendmail, which does not allow open mail relay by default, or you can simply disable sendmail if you are not using it for host e-mail services. Open mail relaying is typically one security issue that you will not have to worry about with a recent distribution of Linux.
Abuse of open mail relays is not limited to small businesses and home users. One cable Internet provider in my area had several of its mail servers added to a blacklist. I contacted my ISP, and it was totally unaware that the abuses were going on let alone that it had been blacklisted.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 197
Chapter 6
✦
Securing Linux
197
Tip
You can allow specific hosts or domains to relay mail through your system by adding those senders to your
/etc/mail/access file with keyword
RELAY
. By default, relaying is allowed only from the local host. Refer to the sendmail documentation for more information.
One package you might consider using to filter out spam on your mail server is spamassassin, which examines the text of incoming mail messages and attempts to filter out messages that it determines to be spam. Spamassassin is described in
Chapter 24.
Smurfing
refers to a particular type of Denial of Service attack aimed at flooding your Internet connection. It can be a difficult attack to defend against because it isn’t easy to trace it back to the attacker.
The attack makes use of the ICMP protocol, a service intended for checking the speed and availability of network connections. Using the ping command, you can send a network packet from your computer to another computer on the Internet.
The remote computer recognizes the packet as an ICMP request and echoes a reply packet to your computer, which can then print a message revealing that the remote system is up and telling you how long it took to reply to the ping.
A smurfing attack uses a malformed ICMP request to bury your computer in network traffic. The attacker bounces a ping request off an unwitting third party in such a way that the reply is duplicated dozens or even hundreds of times. An organization with a fast Internet connection and a large number of computers is used as the relay. The destination address of the ping is set to an entire subnet instead of a single host. The return address is forged to be your machine’s address instead of the actual sender’s. When the ICMP packet arrives at the unwitting relay’s network, every host on that subnet replies to the ping! Furthermore, they reply to your computer instead of to the actual sender. If the relay’s network has hundreds of computers, your Internet connection can be quickly flooded.
The best fix is to contact the organization being used as a relay, informing it of the abuse. That organization usually need only reconfigure its Internet router to stop any future attacks. If the organization is uncooperative, you can minimize the effect of the attack by blocking the ICMP protocol on your router, which at least keeps the traffic off your internal network. It helps even more if you can persuade your ISP to block ICMP packets aimed at your network.
A DDoS attack is much harder to initiate and nearly impossible to stop. It begins with the penetration of hundreds or even thousands of weakly secured machines. These machines are then directed to attack a single host based on the desire of the attacker.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 198
198
Part II ✦
Running the Show
With the advent of DSL and cable modems, millions of people are enjoying Internet access with virtually no speed restrictions. In their rush to get online, many of those people neglect even the most basic security. Because the vast majority of these people run Microsoft operating systems, they tend to get hit with worms and viruses rather quickly. Until very recently, it was common practice for Microsoft systems to have many services open to the network of which users were unaware and very little emphasis placed on using firewall features to block intruders.
After a machine has been infiltrated, quite often the worm or virus installs a program on the victim’s machine that instructs it to quietly call home and announce that it is now ready to do the master’s bidding. At the whim of the master, the infected machines can now be used to focus a concentrated stream of garbage data at a selected host. In concert with thousands of other infected machines, an attacker now has the power to take down nearly any site on the Internet.
Detecting a DDoS is similar to detecting a DoS attack. One or more of the following signs are likely to be present:
✦
Sustained saturated data link
✦
No reduction in link saturation during off-peak hours
✦
Hundreds or even thousands of simultaneous network connections
✦
Extremely slow system performance
Pinging an outside host can tell you a lot about your data link saturation: Much higher than usual latency is a dead giveaway. Normal ping latency (that is, the time it takes for a ping response to come back from a remote host) looks like the following:
#
ping www.example.com
PING www.example.com (192.0.34.166) from 10.0.0.11: 56(84) bytes of data
64 bytes from 192.0.34.166: icmp_seq=1 ttl=49 time=40.1 ms
64 bytes from 192.0.34.166: icmp_seq=2 ttl=49 time=42.5 ms
64 bytes from 192.0.34.166: icmp_seq=3 ttl=49 time=39.5 ms
64 bytes from 192.0.34.166: icmp_seq=4 ttl=49 time=38.4 ms
64 bytes from 192.0.34.166: icmp_seq=5 ttl=49 time=39.0 ms
--- www.example.com ping statistics ---
5 packets transmitted, 5 received, 0% loss, time 4035ms rtt min/avg/max/mdev = 38.472/39.971/42.584/1.432 ms
In this example, the average time for a ping packet to make the round trip was about 39 thousandths of a second.
A ping to a nearly saturated link will look like the following:
12_579495 ch06.qxd 12/27/04 9:48 PM Page 199
Chapter 6
✦
Securing Linux
199
# ping www.example.com
PING www.example.com (192.0.34.166): from 10.0.0.11:
56(84)bytes of data
64 bytes from 192.0.34.166: icmp_seq=1 ttl=62 time=1252 ms
64 bytes from 192.0.34.166: icmp_seq=2 ttl=62 time=1218 ms
64 bytes from 192.0.34.166: icmp_seq=3 ttl=62 time=1290 ms
64 bytes from 192.0.34.166: icmp_seq=4 ttl=62 time=1288 ms
64 bytes from 192.0.34.166: icmp_seq=5 ttl=62 time=1241 ms
--- www.example.com ping statistics ---
6 packets transmitted, 5 received, 0% loss, time 5032ms rtt min/avg/max/mdev = 1218.059/1258.384/1290.861/28.000 ms
In this example, a ping packet took, on average, 1.3 seconds to make the round trip.
From the first example to the second example, latency increased by a factor of 31!
A data link that goes from working normally to slowing down by a factor of 31 is a clear sign that link utilization should be investigated.
For a more accurate measure of data throughput, a tool such as ttcp can be used. To test your connection with ttcp, you must have installed the ttcp package on machines inside
and
outside your network. If you are not sure if the package is installed, simply type
at a command prompt. You should see something like the following:
#
ttcp
Usage: ttcp -t [-options] host [ < in ] ttcp -r [-options > out]
Common options:
-l ## length of bufs read from or written to network (default 8192)
-u use UDP instead of TCP
-p ## port number to send to or listen at (default 5001)
-s -t: source a pattern to network
-r: sink (discard) all data from network
-A align the start of buffers to this modulus (default 16384)
-O start buffers at this offset from the modulus (default 0)
-v verbose: print more statistics
-d set SO_DEBUG socket option
-b ## set socket buffer size (if supported)
-f X format for rate: k,K = kilo{bit,byte}; m,M = mega; g,G = giga
Options specific to -t:
-n## number of source bufs written to network (default 2048)
-D don’t buffer TCP writes (sets TCP_NODELAY socket option)
Options specific to -r:
-B for -s, only output full blocks as specified by -l (for TAR)
-T “touch”: access each byte as it’s read
The first step is to start up a receiver process on the server machine:
#
ttcp -rs
ttcp-r: buflen=8192, nbuf=2048, align=16384/0, port=5001 tcp ttcp-r: socket
12_579495 ch06.qxd 12/27/04 9:48 PM Page 200
200
Part II ✦
Running the Show
The –r flag denotes that the server machine will be the receiver. The –s junction with the
–r flag, tells ttcp to ignore any received data.
flag, in con-
Have someone outside your data link, with a network link close to the same speed as yours, set up a ttcp sending process:
#
ttcp -ts server.example.com
ttcp-t: buflen=8192, nbuf=2048, align=16384/0, port=5001 tcp
-> server.example.com
ttcp-t: socket ttcp-t: connect
Let the process run for a few minutes and then press Ctrl+C on the transmitting side to stop the testing. The receiving side will then take a moment to calculate and present the results:
#
ttcp -rs
ttcp-r: buflen=8192, nbuf=2048, align=16384/0, port=5001 tcp ttcp-r: socket ttcp-r: accept from 64.223.17.21
ttcp-r: 2102496 bytes in 70.02 real seconds = 29.32 KB/sec +++ ttcp-r: 1226 I/O calls, msec/call = 58.49, calls/sec = 17.51
ttcp-r: 0.0user 0.0sys 1:10real 0% 0i+0d 0maxrss 0+2pf 0+0csw
In this example, the average bandwidth between the two hosts was 29.32 kilobytes per second. On a link suffering from a DDoS, this number would be a fraction of the actual bandwidth for which the data link is rated.
If the data link is indeed saturated, the next step is to determine where the connections are coming from. A very effective way of doing this is with the netstat command. Type the following to see connection information:
#
netstat –tupn
Table 6-1 describes each of the netstat parameters used here.
Parameter
-t
,
--tcp
-u
,
--udp
-p
,
--program
-n
,
--numeric
Table 6-1
Description
Shows TCP socket connections.
Shows UDP socket connections.
Shows the PID and name of the program to which each socket belongs.
Shows numerical address instead of trying to determine symbolic host, port, or usernames.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 201
Chapter 6
✦
Securing Linux
201
The following is an example of what the output might look like:
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 65.213.7.96:22 13.29.132.19:12545 ESTABLISHED 32376/sshd tcp 0 224 65.213.7.96:22 13.29.210.13:29250 ESTABLISHED 13858/sshd tcp 0 0 65.213.7.96:6667 13.29.194.190:33452 ESTABLISHED 1870/ircd tcp 0 0 65.213.7.96:6667 216.39.144.152:42709 ESTABLISHED 1870/ircd tcp 0 0 65.213.7.96:42352 67.113.1.99:53 TIME_WAIT tcp 0 0 65.213.7.96:42354 83.152.6.9:113 TIME_WAIT tcp 0 0 65.213.7.96:42351 83.152.6.9:113 TIME_WAIT tcp 0 0 127.0.0.1:42355 127.0.0.1:783 TIME_WAIT tcp 0 0 127.0.0.1:783 127.0.0.1:42353 TIME_WAIT tcp 0 0 65.213.7.96:42348 19.15.11.1:25 TIME_WAIT -
The output is organized into columns defined as follows:
✦
— Protocol used by the socket.
✦
— The number of bytes not yet copied by the user program attached to this socket.
✦
— The number of bytes not acknowledged by the host.
✦
— Address and port number of the local end of the socket.
✦
— Address and port number of the remote end of the socket.
✦
— Current state of the socket. Table 6-2 provides a list of socket states.
✦
— Process ID and program name of the process that owns the socket.
State
ESTABLISHED
SYN_SENT
SYN_RECV
FIN_WAIT1
FIN_WAIT2
TIME_WAIT
CLOSED
CLOSE_WAIT
Table 6-2
Description
Socket has an established connection.
Socket actively trying to establish a connection.
Connection request received from the network.
Socket is closed and the connection is shutting down.
Socket is waiting for remote end to shut down.
Socket is waiting after closing to handle packets still in the network.
Socket is not being used.
The remote end has shut down, waiting for the socket to close.
Continued
12_579495 ch06.qxd 12/27/04 9:48 PM Page 202
202
Part II ✦
Running the Show
State
LAST_ACK
LISTEN
CLOSING
UNKNOWN
Table 6-2 (continued)
Description
The remote end has shut down, and the socket is closed, waiting for acknowledgment.
Socket is waiting for an incoming connection.
Both sides of the connection are shut down, but not all of your data has been sent.
The state of the socket is unknown.
During a DoS attack, the foreign address is usually the same for each connection, in which case it’s a simple matter of typing the foreign IP address into the search form at www.arin.net/whois/ so you can alert your ISP.
During a DDoS attack, the foreign address is likely to be different for each connection, which makes it impossible to track down all the offenders because there are probably thousands of them. The best way to defend yourself is to contact your ISP to see if it can filter the traffic at its border routers.
Crackers have a wide variety of tools and techniques to assist them in breaking into your computer. Intrusion attacks focus on exploiting weaknesses in your security, so crackers can take more control of your system (and potentially do more damage) than they could from the outside.
Fortunately, there are many tools and techniques for combating intrusion attacks.
Let’s explore some of the most common break-in methods and the tools available to protect your system.
Linux systems provide many network services and therefore many avenues for cracker attacks. You should know these services and how to limit access to them.
What is a network service? Basically, it’s any task that the computer performs that requires it to send and receive information over the network using some predefined set of rules. Routing e-mail is a network service. So is serving Web pages. Your Linux box has the potential to provide thousands of services. Many of them are listed in the /etc/services file. Look at a snippet of that file:
12_579495 ch06.qxd 12/27/04 9:48 PM Page 203
Chapter 6
✦
Securing Linux
203
# /etc/services:
# service-name port/protocol [aliases ...] [# comment] chargen 19/tcp ttytst source chargen 19/udp ttytst source ftp-data 20/tcp ftp-data 20/udp
# 21 is registered to ftp, but also used by fsp ftp 21/tcp ftp 21/udp fsp fspd ssh 22/tcp # SSH Remote Login Protocol ssh 22/udp # SSH Remote Login Protocol telnet 23/tcp telnet 23/udp
# 24 - private mail system smtp 25/tcp mail
There are three columns of information after comment lines. The left column contains the name of each service, the middle column defines the port number and protocol type used for that service, and the right column contains an optional alias or list of aliases for the service. The last entry in this example, for instance, describes the SMTP (Simple Mail Transfer Protocol) service, which is the service used for delivering e-mail over the Internet. The middle column tells you that the
SMTP protocol uses port 25 and uses the Transmission Control Protocol (TCP) as its protocol type.
Note
What exactly is a port number? It is a unique number that’s been set aside for a particular network service. It allows network connections to be properly routed to the software that handles that service. For example, when an e-mail message is delivered from some other computer to your Linux box, the remote system must first establish a network connection with your system. Your computer receives the connection request, examines it, sees it labeled for port 25, and knows that the connection should be handed to the program that handles e-mail (which happens to be sendmail).
A program that runs quietly in the background handling service requests (such as sendmail) is called a daemon. Daemons are usually started automatically when your system boots up, and they keep running until your system is shut down. Daemons may also be started on an as-needed basis by xinetd, a special daemon that listens on a large number of port numbers, and then launches the service that is registered with that port number.
SMTP uses the TCP protocol; some other services use UDP, the User Datagram
Protocol. For this security discussion, all you really need to know about TCP and
UDP is that they provide different ways of packaging the information sent over a network connection. A TCP connection provides error detection and retransmission of lost data. UDP doesn’t check to ensure that the data arrived complete and intact; it is meant as a fast way to send noncritical information.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 204
204
Part II ✦
Running the Show
Although there are hundreds of services potentially available and subject to attack on your Linux system, in reality only a few dozen services are installed, and only a handful of those are on by default. Most network services are started by either the xinetd process (named inetd on some Linux distributions) or by a startup script in the /etc/init.d
directory.
Xinetd is a daemon that listens on a great number of network port numbers. When a connection is made to a particular port number, xinetd automatically starts the appropriate program for that service and hands the connection to it.
The configuration file /etc/xinetd.conf
is used to provide default settings for the xinetd server. (If the daemon is called inetd, look for an /etc/inetd.conf
instead.) The directory /etc/xinetd.d
contains files telling xinetd file what ports to listen on and what programs to start. Each file contains configuration information for a single service, and the file is usually named after the service it configures. For example, to enable the rsync service, edit the rsync file in the /etc/xinetd.d
directory and look for a section similar to the following: service rsync
{ disable = yes socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID
}
The first line of this example identifies the service as rsync, which exactly matches the service name listed in the /etc/services file, causing the service to listen on port 873 for TCP and UDP protocols. You can see that the service is off by default ( disable = yes ). To enable the rsync services, change the line to read disable = no : service rsync
{
disable = no
socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID
}
12_579495 ch06.qxd 12/27/04 9:48 PM Page 205
Chapter 6
✦
Securing Linux
205
Tip
The rsync service is a nice one to turn on if your machine is an FTP server. It enables people to use an rsync client (which includes a checksum-search algorithm) to download files from your server. With that feature, users can restart a disrupted download without having to start from the beginning.
Tip
Because most services are disabled by default, your computer is only as insecure as you make it. You can double-check that insecure services, such as rlogin and rsh
(which are included in the rsh-server package), are also disabled by making sure that disabled = yes is set in the /etc/xinetd.d/rlogin and rsh files.
You can make the remote login service active but disable the use of the
/etc/ host.equiv
and
.rhosts
files, requiring rlogin to always prompt for a password. Rather than disabling the service, locate the server line in the rsh
( server = /usr/sbin/in.rshd
) and add a space followed by
-L file at the end.
You now need to send a signal to the xinetd process to tell it to reload its configuration file. The quickest way to do that is to restart the service. As the root user, type the following from a shell:
#
service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
That’s it — you have enabled the ipop3 service. Provided that you have properly configured your mail server, clients should now be able to get their mail from your computer.
Completely disabling an unused service is fine, but what about the services that you really need? How can you selectively grant and deny access to these services?
With most current Linux distributions, TCP wrapper support has been integrated into the xinetd daemon. Xinetd will look at the /etc/hosts.allow
and /etc/hosts.
deny files to determine when a particular connection should be granted or refused for services such as rlogin, rsh, telnet, finger, and talk.
When a service that relies on TCP wrappers is requested, the hosts.allow
hosts.deny
and files are scanned and checked for an entry that matches the IP address of the connecting machine. The following checks are made when connection attempts occur:
✦
If the address is listed in the hosts.allow
file, the connection is allowed, and hosts.deny
is not checked.
✦
Otherwise, if the address is in hosts.deny
, the connection is denied.
✦
Finally, if the address is in neither file, the connection is allowed.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 206
206
Part II ✦
Running the Show
It is not necessary (or even possible) to list every single address that may connect to your computer. The hosts.allow
and hosts.deny
files enable you to specify entire subnets and groups of addresses. You can even use the keyword ALL to specify all possible addresses. You can also restrict specific entries in these files so they only apply to specific network services. Take a look at an example of a typical pair of hosts.allow
and hosts.deny
files. Here’s the
/etc/hosts.allow
file:
#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
# cups-lpd: 199.170.177.
in.telnetd: 199.170.177., .linuxtoys.net
vsftpd: ALL
Here’s the /etc/hosts.deny
file:
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as
# decided by the ‘/usr/sbin/tcpd’ server.
#
ALL: ALL
This example is a rather restrictive configuration. It allows connections to the cupslpd and telnet services from certain hosts, but then denies all other connections.
It also allows connections to the FTP service (vsftp) to all hosts. Let’s examine the files in detail.
As usual, lines beginning with a # character are comments and are ignored by xinetd when it parses the file. Each noncomment line consists of a comma-separated list of daemons followed by a colon ( : ) character and then a comma-separated list of client addresses to check (for example, tftpd,fingerd: .linuxtoys.net, .fedora
trouble.com
.) In this context, a client is any computer that attempts to access a network service on your system.
A client entry can be a numeric IP address (such as
199.170.177.25
) or a host name (such as jukebox.linuxtoys.net
) but is more often a wildcard variation that specifies an entire range of addresses. A client entry can take four different forms. The online manual page for the hosts.allow
file describes them as follows:
✦
A string that begins with a dot character ( .
). A host name is matched if the last components of its name match the specified pattern. For example, the pattern .tue.nl
matches the host name wzv.win.tue.nl
.
✦
A string that ends with a dot character ( .
). A host address is matched if its first numeric fields match the given string. For example, the pattern 131.155
.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 207
Chapter 6
✦
Securing Linux
207 matches the address of nearly every host on the Eindhoven University of
Technology network (
131.155.x.x
).
✦
A string that begins with an at sign ( @ )is treated as an NIS (formerly YP) netgroup name. A host name is matched if it is a host member of the specified netgroup. Netgroup matches are not supported for daemon process names or for client user names.
✦
An expression of the form
n.n.n.n
/
m.m.m.m
is interpreted as a
net
/
mask
pair.
A host address is matched if
net
is equal to the bitwise
and
of the address and the mask. For example, the net/mask pattern
131.155.72.0/255.255.254.0
matches every address in the range 131.155.72.0
through 131.155.73.255
.
The example host.allow
entry
199.170.177.
contains the first two types of client specification. The will match any IP address that begins with that string, such as 199.170.177.25
. The client entry .linuxtoys.net
such as jukebox.linuxtoys.net
or will match host names picframe.linuxtoys.net
.
Take a look at what happens when a host named jukebox.linuxtoys.net
(with IP address 199.170.179.18
) connects to your Linux system using the Telnet protocol:
Xinetd receives the connection request.
Xinetd begins comparing the address and name of jukebox.linuxtoys.net
to the rules listed in /etc/hosts.allow
. It starts at the top of the file and works its way down the file until finding a match. Both the daemon (the program handling the network service on your Linux box) and the connecting client’s IP address or name must match the information in the hosts.allow
file. In this case, the second rule that is encountered matches the request: in.telnetd: 199.170.177., .linuxtoys.net
The jukebox host is not in the 199.170.177
subnet, but it is in the linuxtoys.
net domain. Xinetd stops searching the file as soon as it finds this match.
What if jukebox connects to your box using the IMAP protocol? Requests from jukebox for the IMPA service matches none of the rules in hosts.allow
; the only line that refers to the imapd daemon does not refer to the 199.170.179
the linuxtoys.net
domain. Xinetd continues on to the hosts.deny
subnet or to file. The entry
ALL: ALL matches anything, so tcpd denies the connection.
The ALL wildcard was also used in the hosts.allow
file, telling xinetd to permit absolutely any host to connect to the FTP service on the Linux box. This is appropriate for running an anonymous FTP server that anyone on the Internet can access.
If you are not running an anonymous FTP site, you probably should not use the
ALL flag.
A good rule of thumb is to make your hosts.allow
and hosts.deny
files as restrictive as possible and to explicitly enable only those services that you really need.
Also, grant access only to those systems that really need access. Using the ALL flag
12_579495 ch06.qxd 12/27/04 9:48 PM Page 208
208
Part II ✦
Running the Show
Tip
to grant universal access to a particular service may be easier than typing in a long list of subnets or domains, but better a few minutes spent on proper security measures than many hours recovering from a break-in.
You can further restrict access to services by using various options within the
/etc/ xinetd.conf
file, even to the point of limiting access to certain services to specific times of the day. Read the manual page for xinetd (by typing man xinetd at a command prompt) to learn more about these options.
If you make use of good firewalling practices as described in Chapter 17, you will be well prepared to mitigate and prevent most cracker attacks. If your firewall should fail to stop an intrusion, you must be able to recognize the attack when it is occurring. Understanding the various (and numerous) log files in which Linux records important events is critical to this goal. The log files for your Linux system can be found in the
/var/log directory.
Most Linux systems make use of log-viewing tools, either provided with the desktop environment (such as GNOME) or as a command you can execute from a terminal window. Fedora Core and Red Hat Enterprise Linux come with a System Logs window
( system-logviewer command) that you can use to view and search critical system log files from the GUI. To open the System Logs window in Fedora, from the main desktop menu, select System Tools
➪
System Logs. Figure 6-1 shows an example of the System Logs window.
Figure 6-1:
Display system log files in the System Logs window.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 209
Chapter 6
✦
Securing Linux
209
To view a particular log file, click the log name in the left column. If you are looking for a particular message or problem, type a keyword into the Filter For box, and click
Filter. Only lines containing that keyword are displayed. Case matters, so searching for “Mem” won’t find “mem” when you use the filter. Click Reset to display the whole file again.
Table 6-3 contains a listing of log files displayed in the System Logs window, along with other files in the
/var/log directory that may interest you. Many of these files are included with most Linux systems.
Table 6-3
Filename Description System Logs
Name
Boot Log
Cron Log
Kernel Startup
Log
FTP Log dmesg xferlog
Apache Access
Log
Apache Error
Log
Mail Log httpd/access_log httpd/error_log maillog
MySQL Server
Log
News Log
RPM Packages boot.log
cron mysqld.log
spooler rpmpkgs
Contains messages indicating which systems services have started and shut down successfully and which (if any) have failed to start or stop. The most recent bootup messages are listed near the end of the file.
Contains status messages from the crond
, a daemon that periodically runs scheduled jobs, such as backups and log file rotation.
A recording of messages printed by the kernel when the system boots.
Contains information about files transferred using the wu-ftpd FTP service.
Logs requests for information from your Apache
Web server.
Logs errors encountered from clients trying to access data on your Apache Web server.
Contains information about addresses to which and from which e-mail was sent. Useful for detecting spamming.
Includes information related to activities of the
MySQL database server (mysqld).
Directory containing logs of messages from the
Usenet News server if you are running one.
Contains a listing of RPM packages that are installed on your system.
Continued
12_579495 ch06.qxd 12/27/04 9:48 PM Page 210
210
Part II ✦
Running the Show
Table 6-3 (continued)
System Logs
Name
Security Log
Filename Description
System Log
Update Agent
Log
X.Org X11 Log
*
*
*
*
*
* secure messages up2date
Xorg.0.log
gdm/:0.log
samba/log.smbd
squid/access.log
vsftpd.log
sendmail uucp
Records the date, time, and duration of login attempts and sessions.
A general-purpose log file to which many programs record messages.
Contains messages resulting from actions by the
Red Hat Update Agent.
Includes messages output by the X.Org X server.
Holds messages related to the login screen
(GNOME display manager).
Shows messages from the Samba SMB file service daemon.
Contains messages related to the squid proxy/caching server.
Contains messages relating to transfers made using the vsFTPd daemon (FTP server).
Shows error messages recorded by the sendmail daemon.
Shows status messages from the UNIX to UNIX
Copy Protocol daemon.
* Indicates a log file that is not contained in the System Logs window. Access these files directly from
/var/log
.
Most of the files in the /var/log directory are maintained by the syslogd service.
The syslogd daemon is the System Logging Daemon. It accepts log messages from a variety of other programs and writes them to the appropriate log files. This is better than having every program write directly to its own log file because it enables you to centrally manage how log files are handled. It is possible to configure syslogd to record varying levels of detail in the log files. It can be told to ignore all but the most critical messages, or it can record every detail.
The syslogd daemon can even accept messages from other computers on your network. This is particularly handy because it enables you to centralize the management and reviewing of the log files from many systems on your network. There is also a major security benefit to this practice. If a system on your network is broken into, the cracker cannot delete or modify the log files because those files are stored on a separate computer. It is important to remember, though, that those log messages
12_579495 ch06.qxd 12/27/04 9:48 PM Page 211
Chapter 6
✦
Securing Linux
211 are not, by default, encrypted. Anyone tapping into your local network can eavesdrop on those messages as they pass from one machine to another. Also, although the cracker may not be able to change old log entries, he can affect the system such that any new log messages should not be trusted.
It is not uncommon to run a dedicated loghost
, a computer that serves no other purpose than to record log messages from other computers on the network.
Because this system runs no other services, it is unlikely that it will be broken into.
This makes it nearly impossible for a cracker to erase his or her tracks, but it does not mean that all of the log entries are accurate after a cracker has broken into a machine on your network.
To redirect your computer’s log files to another computer’s syslogd, you must make some changes to your local syslogd’s configuration file, /etc/syslog.conf
. Become root using the su command and then load the
/etc/syslog.conf
file in a text editor (such as vi). You should see something similar to this:
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
# Log anything (except mail) of level info or higher.
# Don’t log private authentication messages!
*.info;mail.none;news.none;authpriv.none;cron.none /var/log/messages
# The authpriv file has restricted access.
authpriv.* /var/log/secure
# Log all the mail messages in one place.
mail.* /var/log/maillog
# Log cron stuff cron.* /var/log/cron
# Everybody gets emergency messages
*.emerg *
# Save news errors of level crit and higher in a special file.
uucp,news.crit /var/log/spooler
# Save boot messages also to boot.log
local7.* /var/log/boot.log
#
# INN
# news.=crit /var/log/news/news.crit
news.=err /var/log/news/news.err
news.notice /var/log/news/news.notice
12_579495 ch06.qxd 12/27/04 9:48 PM Page 212
212
Part II ✦
Running the Show
The lines beginning with a # character are comments. Other lines contain two columns of information. The left field is a semicolon-separated list (spaces won’t work) of message types and message priorities. The right field is the log file to which those messages should be written.
To send the messages to another computer (the loghost) instead of a file, simply replace the log filename with the @ character followed by the name of the loghost.
For example, to redirect the output normally sent to the messages
, secure
, and maillog log files, make these changes to the preceding file:
# Log anything (except mail) of level info or higher.
# Don’t log private authentication messages!
*.info;mail.none;news.none;authpriv.none;cron.none @loghost
# The authpriv file has restricted access.
authpriv.* @loghost
# Log all the mail messages in one place.
mail.* @loghost
The messages will now be sent to the syslogd running on the computer named loghost. The name loghost was not an arbitrary choice. It is customary to create such a host name and make it an alias to the actual system acting as the loghost.
That way, if you ever need to switch the loghost duties to a different machine, you only need to change the loghost alias; you do not need to reedit the syslog.conf
file on every computer.
Because of the many programs and services that record information to the messages log file, it is important that you understand the format of this file. You can get a good early warning of problems developing on your system by examining this file. Each line in the file is a single message recorded by some program or service. Here is a snippet of an actual messages log file:
Feb 25 11:04:32 toys network: Bringing up loopback interface: succeeded
Feb 25 11:04:35 toys network: Bringing up interface eth0: succeeded
Feb 25 13:01:14 toys vsftpd(pam_unix)[10565]: authentication failure; logname= uid=0 euid=0 tty= ruser= rhost=10.0.0.5 user=chris
Feb 25 14:44:24 toys su(pam_unix)[11439]: session opened for user root by chris(uid=500)
This is really very simple when you know what to look for. Each message is divided into five main parts. From left to right they are:
✦
The date and time that the message was logged.
✦
The name of the computer from which the message came.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 213
Chapter 6
✦
Securing Linux
213
✦
The program or service name to which the message pertains.
✦
The process number (enclosed in square brackets) of the program sending the message.
✦
The actual text message.
Take another look at the preceding file snippet. In the first two lines, you can see that the network was restarted. The next line shows that the user named chris tried and failed to get to the FTP server on this system from a computer at address
10.0.0.5
(he typed the wrong password and authentication failed). The last line shows chris using the su command to become root user.
By occasionally reviewing the messages and secure files, it’s possible to catch a cracking attempt before it is successful. If you see an excessive number of connection attempts for a particular service, especially if they are coming from systems on the Internet, you may be under attack.
Passwords are the most fundamental security tool of any modern operating system and consequently, the most commonly attacked security feature. It is natural to want to choose a password that is easy to remember, but very often this means choosing a password that is also easy to guess. Crackers know that on any system with more than a few users, at least one person is likely to have an easily guessed password.
By using the “brute force” method of attempting to log in to every account on the system and trying the most common passwords on each of these accounts, a persistent cracker has a good shot of finding a way in. Remember that a cracker can automate this attack, so thousands of login attempts are not out of the question.
Obviously, choosing good passwords is the first and most important step to having a secure system.
Here are some things to avoid when choosing a password:
✦
Do not use any variation of your login name or your full name. Even if you use varied case, append or prepend numbers or punctuation, or type it backwards, this will still be an easily guessed password.
✦
Do not use a dictionary word, even if you add numbers or punctuation to it.
✦
Do not use proper names of any kind.
✦
Do not use any contiguous line of letters or numbers on the keyboard (such as “qwerty” or “asdfg”).
12_579495 ch06.qxd 12/27/04 9:48 PM Page 214
214
Part II ✦
Running the Show
A strong password is one that is not easily guessed. It should contain a mixture of uppercase and lowercase letters, numbers, and possibly even punctuation, yet still be something you can remember.
A good way to choose a strong password is to take the first letter from each word of an easily remembered sentence. The password can be made even better by adding numbers, punctuation, and varied case. The sentence you choose should have meaning only to you, and should not be publicly available (choosing a sentence on your personal Web page is a bad idea). Table 6-4 lists examples of strong passwords and the tricks used to remember them.
Password
Mrci7yo!
2emBp1ib
ItMc?Gib
Table 6-4
How to Remember It
My rusty car is 7 years old!
2 elephants make BAD pets, 1 is better
Is that MY coat? Give it back
The passwords look like gibberish, but are actually rather easy to recall. Placing emphasis on words that stand for capital letters, for example, make them simple to remember.
Use the passwd command to change your password. Type
in a command shell; you’re prompted to enter your old password. To protect against someone
“shoulder surfing” and learning your password, the password is not displayed as you type.
If you typed your old password correctly, you are prompted to type in your new password. The passwd command checks the new password against cracklib to determine if it is a good or bad password. Non-root users are required to try a different password if the one they have chosen is not a good password. The root user is the only user who is permitted to assign bad passwords. Once the password has been accepted by cracklib , the passwd command will ask you to enter the new password a second time to make sure there are no typos (which are hard to detect when you can’t see what you are typing).
When running as root, it is possible to change a user’s password by supplying that user’s login name as a parameter to the passwd command. For example, typing
#
passwd joe
12_579495 ch06.qxd 12/27/04 9:48 PM Page 215
Chapter 6
✦
Securing Linux
215 results in the passwd command prompting you for joe’s new password. It does not prompt you for the user’s old password so that root can reset a user’s password when that user has forgotten it (an event that happens all too often).
In early versions of UNIX, all user account and password information was stored in a file that all users could read (although only root could write to it). This was generally not a problem because the password information was encrypted using a
trapdoor algorithm,
meaning that the clear text password was encoded into a scrambled string of characters before it was stored in the file, and that the string could not be translated back to the nonencoded password.
How does the system check your password in this case? When you log in, the system encodes the password you entered, compares the resulting scrambled string with the scrambled string that is stored in the password file, and grants you access only if the two match. Have you ever asked a system administrator what the password on your account is, only to hear “I don’t know” in response? If so, this is why:
The administrator really doesn’t have the password, only the encrypted version.
The nonencoded password exists only at the moment you type it.
There is a problem with people being able to see encrypted passwords, however.
Although it may be difficult (or even impossible) to reverse the encryption of a trapdoor algorithm, it is very easy to encode a large number of password guesses and compare them to the encoded passwords in the password file. This is, in order of magnitude, more efficient than trying actual login attempts for each user name and password. If a cracker can get a copy of your password file, the cracker has a much better chance of breaking into your system.
Fortunately, Linux and all modern UNIX systems support a shadow password file by default. The shadow file is a special version of the passwd file that only root can read. It contains the encrypted password information, so passwords can be left out of the passwd file, which any user on the system can read. Linux supports the older, single-password file method as well as the newer, shadow password file. You should always use the shadow password file (it is the default).
The password file is named passwd and can be found in the
/etc directory. The shadow password file is named shadow shadow and is also located in /etc . If your /etc/ file is missing, then it is likely that your Linux system is storing the password information in the /etc/passwd file instead. Verify this by displaying the file with the less command:
#
less /etc/passwd
12_579495 ch06.qxd 12/27/04 9:48 PM Page 216
216
Part II ✦
Running the Show
Something similar to the following should be displayed: root:DkkS6Uke799fQ:0:0:root:/root:/bin/bash bin:*:1:1:bin:/bin: daemon:*:2:2:daemon:/sbin:
.
.
.
mary:KpRUp2ozmY5TA:500:100:Mary Smith:/home/mary:/bin/sh joe:0sXrzvKnQaksI:501:100:Joe Johnson:/home/joe:/bin/sh jane:ptNoiueYEjwX.:502:100:Jane Anderson:/home/jane:/bin/sh bob:Ju2vY7A0X6Kzw:503:100:Bob Renolds:/home/bob:/bin/sh
Each line in this listing corresponds to a single user account on the Linux system.
Each line is made up of seven fields separated by colon ( : ) characters. From left to right the fields are the login name, the encrypted password, the user ID, the group
ID, the description, the home directory, and the default shell. Looking at the first line, you see that it is for the root account and has an encrypted password of
DkkS6Uke799fQ. You can also see that root has a user ID of zero, a group ID of zero, and a home directory of
/root
, and root’s default shell is
/bin/sh
.
All of these values are quite normal for a root account, but seeing that encrypted password between the first and second colon on each line should set off alarm bells in your head. It confirms that your system is not using the shadow password file. At this point, you should immediately use the pwconv command to convert your password file to
/etc/shadow to store the password information. Simply log in as root
(or use the su command to become root) and enter the pwconv command at a prompt. It will print no messages, but when your shell prompt returns, you should have a /etc/shadow file and your /etc/passwd file that looks like this: root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin: daemon:x:2:2:daemon:/sbin:
.
.
.
mary:x:500:100:Mary Smith:/home/mary:/bin/sh joe:x:501:100:Joe Johnson:/home/joe:/bin/sh jane:x:502:100:Jane Anderson:/home/jane:/bin/sh bob:x:503:100:Bob Renolds:/home/bob:/bin/sh
Encrypted password data is replaced with an
x
. The password data is moved to
/etc/shadow .
There is also a screen-oriented command called authconfig that you can use to manage shadow passwords and other system authentication information. This tool also has features that enable you to work with MD5 passwords, LDAP authentication, and Kerberos 5 authentication. Type
and step through the screens to use it.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 217
Chapter 6
✦
Securing Linux
217
To work with passwords for groups, you can use the grpconv command to convert passwords in
/etc/groups to shadowed group passwords in
/etc/gshadow
. If you change passwords or group passwords and something breaks (you are unable to log in to the accounts), you can use the pwunconv and grpunconv commands, respectively, to reverse password conversion.
Using the shadow password file and picking good passwords are a great start toward securing your system. You may have noticed by now that security is not just a one-time job. It is an ongoing process, as much about policies as programs.
Keep reading to learn more.
The previous sections told you how to lock the doors to your Linux system to deny access to crackers. The best lock is useless, however, if you are mugged in your own driveway and have your keys stolen. Likewise, the best computer security can be for naught if you are sending passwords and other critical data unprotected across the
Internet.
A savvy cracker can use a tool called a
protocol analyzer
or a
network sniffer
to peek at the data flowing across a network and pick out passwords, credit card data, and other juicy bits of information. The cracker does this by breaking into a poorly protected system on the same network and running software, or by gaining physical access to the same network and plugging in his or her own equipment.
You can combat this sort of theft by using encryption. The two main types of encryption in use today are symmetric cryptography and public-key cryptography.
Symmetric cryptography, also called private-key cryptography, uses a single key to both encrypt and decrypt a message. This method is generally inappropriate for securing data that will be used by a third party because of the complexity of secure key exchange. Symmetric cryptography is generally useful for encrypting data for one’s own purposes.
A classic use of symmetric cryptography is for a personal password vault. Anyone who has been using the Internet for any amount of time has accumulated a quantity of user names and passwords for accessing various sites and resources. A personal password vault lets you store this access information in an encrypted form. The end result is that you only have to remember one password to unlock all of your access information.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 218
218
Part II ✦
Running the Show
Until recently, the United States government was standardized on a symmetric encryption algorithm called DES (Data Encryption Standard) to secure important information. There’s no direct way to crack DES-encrypted data, so to decrypt the data without a password requires an unimaginable amount of computing power to try to guess the password — the brute force method of decryption.
As personal computing power has increased nearly exponentially, the DES algorithm has had to be retired. In its place, after a very long and interesting search, the U.S. government has accepted the Rijndael algorithm as what it calls the
AES
(Advanced Encryption Standard). Although the AES algorithm is also subject to brute-force attacks, it requires significantly more computing power to crack than the DES algorithm does.
Go to http://aescrypt.sourceforge.net/ for more information on AES, including a command line implementation of the algorithm.
Public-key cryptography does not suffer from key distribution problems, and that is why it is the preferred encryption method for secure Internet communication. This method uses multiple keys (usually two), one to encrypt the message and another to decrypt the message. The key used to encrypt the message is called the
public key
because it is made available for all to see. The key used to decrypt the message is the private key and is kept hidden.
Say, for example, that you want to send me a secure message using public-key encryption. Here’s how the process works:
I must have a public and private key pair. Depending on the circumstances, I may generate the keys myself (using special software) or obtain the keys from a key authority.
You want to send me a message, so you first look up my public key (or more accurately, the software you are using looks it up).
You encrypt the message with the public key. At this point, the message can only be decrypted with the private key (the public key cannot be used to decrypt the message).
I receive the message and use my private key to decrypt it.
A classic implementation of public-key cryptography is with SSL (secure socket layer) communication. This is the technology that enables you to securely submit your credit card information to an online merchant. The elements of an SSL encrypted session are:
12_579495 ch06.qxd 12/27/04 9:48 PM Page 219
Chapter 6
✦
Securing Linux
219
✦
SSL-enabled Web browser (Mozilla, Internet Explorer, Opera, Konquerer, etc.)
✦
SSL-enabled Web server (Apache)
✦
SSL certificate
To initiate an SSL session, a Web browser first makes contact with a Web server on port 443, also known as the HTTPS (Hypertext Transport Protocol Secure) port.
After a socket connection has been established between the two machines, the following occurs:
Server sends SSL certificate to browser.
Browser verifies identity of server through SSL certificate.
Browser generates symmetric encryption key.
Browser uses SSL certificate to encrypt symmetric encryption key.
Browser sends encrypted key to the server.
Server decrypts the symmetric key with its private key counterpart of the public SSL certificate.
Browser and server can now encrypt and decrypt traffic based on a common knowledge of the symmetric key.
Secure data interchange can now occur.
Note
To create your own SSL certificate for secure HTTP data interchange, you must first have an SSL-capable Web server such as the Apache Web server (httpd package), which comes with virtually every Linux distribution. Once you have a server ready to go, familiarize yourself with the important server-side components of an SSL certificate:
The following example is from a Fedora Core system. A similar procedure for using
SSL certificates with an Apache server on a Debian system is contained in Chapter 23.
#
ls -1 /etc/httpd/conf
-rw-r--r-- 1 root root 36010 Jul 14 15:45 httpd.conf
lrwxrwxrwx 1 root root 37 Aug 12 23:45 Makefile ->
../../../usr/share/ssl/certs/Makefile drwx------ 2 root root 4096 Aug 12 23:45 ssl.crl
drwx------ 2 root root 4096 Aug 12 23:45 ssl.crt
drwx------ 2 root root 4096 Jul 14 15:45 ssl.csr
drwx------ 2 root root 4096 Aug 12 23:45 ssl.key
drwx------ 2 root root 4096 Jul 14 15:45 ssl.prm
#
ls -l /etc/httpd/conf.d/ssl.conf
-rw-r--r-- 1 root root 11140 Jul 14 15:45 ssl.conf
12_579495 ch06.qxd 12/27/04 9:48 PM Page 220
220
Part II ✦
Running the Show
The /etc/httpd/conf and /etc/httpd/conf.d
directories contain all of the components necessary to create your SSL certificate. Here are descriptions of the components:
Component
httpd.conf
Makefile ssl.crl
ssl.crt
ssl.csr
ssl.key
ssl.prm
ssl.conf
Description
Web server configuration file
Certificate building script
Certificate revocation list directory
SSL certificate directory
Certificate service request directory
SSL certificate private key directory
SSL certificate parameters
Primary Web server SSL configuration file
Now take a look at the tools used to create SSL certificates:
#
cd /etc/httpd/conf
#
make
This makefile allows you to create: o public/private key pairs o SSL certificate signing requests (CSRs) o self-signed SSL test certificates
To create a key pair, run “make SOMETHING.key”.
To create a CSR, run “make SOMETHING.csr”.
To create a test certificate, run “make SOMETHING.crt”.
To create a key and a test certificate in one file, run “make
SOMETHING.pem”.
To create a key for use with Apache, run “make genkey”.
To create a CSR for use with Apache, run “make certreq”.
To create a test certificate for use with Apache, run “make testcert”.
Examples: make server.key
make server.csr
make server.crt
make stunnel.pem
make genkey make certreq make testcert
12_579495 ch06.qxd 12/27/04 9:48 PM Page 221
Chapter 6
✦
Securing Linux
221
The make command utilizes the Makefile to create SSL certificates. Without any arguments the make command simply prints the information as just shown. The following are the arguments you can give to make :
Argument
make server.key
make server.csr
make server.crt
make stunnel.pem
make genkey make certreq make testcert
Description
Creates generic public/private key pairs.
Generates a generic SSL certificate service request.
Generates a generic SSL test certificate.
Generates a generic SSL test certificate, but puts the private key in the same file as the SSL test certificate.
Same as make server.key
except it places the key in the ssl.key
directory.
Same as make server.csr
except it places the certificate service request in the ssl.csr
directory.
Same as make server.crt
in the ssl.crt
directory.
except it places the test certificate
Using Third-Party Certificate Signers
In the real world, I know who you are because I recognize your face, your voice, and your mannerisms. On the Internet, I cannot see these things and must rely on a trusted third party to vouch for your identity. To ensure that a certificate is immutable, it has to be signed by a trusted third party (certificate authority) when the certificate is issued and validated every time an end user taking advantage of your secure site loads it. The following are trusted third-party certificate signers:
✦
GlobalSign ( www.globalsign.net
)
✦
Baltimore ( www.baltimore.com
)
✦
GeoTrust ( www.geotrust.com
)
✦
VeriSign ( www.verisign.com
)
✦
FreeSSL ( www.freessl.com
)
✦
Thawte ( www.thawte.com
)
✦
EnTrust ( www.entrust.com
)
✦ ipsCA ( www.ipsca.com
)
✦
COMODO Group ( www.comodogroup.com
)
12_579495 ch06.qxd 12/27/04 9:48 PM Page 222
222
Part II ✦
Running the Show
Each of these certificate authorities has a chunk of cryptographic code embedded into nearly every Web browser in the world. This chunk of cryptographic code allows a Web browser to determine whether an SSL certificate is authentic. Without this validation, it would be trivial for crackers to generate their own certificates and dupe people into thinking they are giving sensitive information to a reputable source.
Each certificate authority has different deals, prices, and products. Check out each of the CAs in the preceding list to determine which works best for you.
Certificates that are not validated are called
self-signed certificates
. If you come across a site that has not had its identity authenticated by a trusted third party, your Web browser will display a message similar to the one shown in Figure 6-2.
Figure 6-2:
A pop-up window alerts you when a site is not authenticated.
This does not necessarily mean that you are encountering anything illegal, immoral, or fattening. Many sites opt to go with self-signed certificates, not because they are trying to pull a fast one on you, but because there may not be any reason to validate the true owner of the certificate and they do not want to pay the cost of getting a certificate validated. Some reasons for using a self-signed certificate include:
✦
In this case, you as the end user have nothing to worry about — no one is trying to steal your information because you aren’t giving out any information. The certificate simply secures the Web transmission from the server to you. The data in and of itself may not be sensitive, but, being a good netizen (‘net citizen), the site has enabled you to secure the transmission to keep third parties from sniffing the traffic.
✦
If you run a Web site that has a very limited set of customers, such as an Application Service Provider (ASP), you can simply inform your users that you have no certificate signer and that they can browse the certificate information and validate it with you over the phone or in person.
✦
It makes no sense to pay for an SSL certificate if you are only testing a new Web site or Web-based application. Use a self-signed certificate until you are ready to go live.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 223
Chapter 6
✦
Securing Linux
223
Each signing authority has different deals, prices, and products. Check out each of the signing authorities listed in the “Using Third-Party Certificate Signers” section earlier in this chapter to determine which works best for you. The following are areas where signing authorities differ:
✦
Credibility and stability
✦
Pricing
✦
Browser recognition
✦
Warranties
✦
Support
✦
Certificate strength
For good comparisons, studies, and inside information to make the job of finding an
SSL signer easier, go to www.whichssl.org
.
Creating a Certificate Service Request
To create a third-party validated SSL certificate, you start with a Certificate Service
Request (CSR). To create a CSR, do the following on your Web server:
#
cd /etc/httpd/conf
#
make certreq
umask 77 ; \
/usr/bin/openssl genrsa -des3 1024 >
/etc/httpd/conf/ssl.key/server.key
.
.
.
You are asked to enter a password to secure your private key. This password should be at least eight characters long, and should not be a dictionary word or contain numbers or punctuation. The characters you type do not appear on the screen to prevent someone from shoulder surfing your password. Enter the password once again to verify. The certificate generation process now begins.
At this point, it is time to start adding some identifying information to the certificate that the third-party source will later validate. Before you can do this, you must unlock the private key you just created. Do so by typing the password you just created. Then enter information as you are prompted. Here’s an example of a session for adding information for a certificate:
Enter pass phrase for /etc/httpd/conf/ssl.key/server.key:
You are about to be asked to enter information that will be incorporated into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 224
224
Part II ✦
Running the Show
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
-----
Country Name (2 letter code) [GB]:
US
State or Province Name (full name) [Berkshire]:
Connecticut
Locality Name (eg, city) [Newbury]:
Mystic
Organization Name (eg, company) [My Company Ltd]:
Acme Marina, Inc.
Organizational Unit Name (eg, section) []:
InfoTech
Common Name (eg, your name or your server’s hostname) []
:www.acmemarina.com
Email Address []: [email protected]
To complete the process, you are asked if you want to add any extra attributes to your certificate. Unless you have a reason to provide more information, simply press Enter at each of the prompts to leave them blank:
Please enter the following ‘extra’ attributes to be sent with your certificate request
A challenge password []:
An optional company name []:
Getting the CSR Signed
After your CSR is created, select a certificate authority (from the list in the “Using
Third-Party Certificate Signers” section earlier in this chapter).
Then send your CSR to the CA for validation. Instructions at each CA’s Web site describe where to send your CSR for validation.
You will have to go through some validation steps. Each signer has a different method of validating identity and certificate information. Some require that you fax articles of incorporation, while others require that a company officer be made available to talk to a validation operator. At some point in the process you are asked to copy and paste the contents of the CSR you created into the signer’s Web form.
#
cd /etc/httpd/conf/ssl.csr
#
cat server.csr
-----BEGIN CERTIFICATE REQUEST-----
MIIB6jCCAVMCAQAwgakxCzAJBgNVBAYTAlVTMRQwEgYDVQQIEwtDb25uZWN0aWN1 dDEPMA0GA1UEBxMGTXlzdGljMRowGAYDVQQKExFBY21lIE1hcmluYSwgSW5jLjER
MA8GA1UECxMISW5mb1RlY2gxGzAZBgNVBAMTEnd3dy5hY21lbWFyaW5hLmNvbTEn
MCUGCSqGSIb3DQEJARYYd2VibWFzdGVyQGFjbWVtYXJpbmEuY29tMIGfMA0GCSqG
SIb3DQEBAQUAA4GNADCBiQKBgQDcYH4pjMxKMldyXRmcoz8uBVOvwlNZHyRWw8ZG u2eCbvgi6w4wXuHwaDuxbuDBmw//Y9DMI2MXg4wDq4xmPi35EsO1Ofw4ytZJn1yW aU6cJVQro46OnXyaqXZOPiRCxUSnGRU+0nsqKGjf7LPpXv29S3QvMIBTYWzCkNnc gWBwwwIDAQABoAAwDQYJKoZIhvcNAQEEBQADgYEANv6eJOaJZGzopNR5h2YkR9Wg l8oBl3mgoPH60Sccw3pWsoW4qbOWq7on8dS/++QOCZWZI1gefgaSQMInKZ1II7Fs
YIwYBgpoPTMC4bp0ZZtURCyQWrKIDXQBXw7BlU/3A25nvkRY7vgNL9Nq+7681EJ8
W9AJ3PX4vb2+ynttcBI=
-----END CERTIFICATE REQUEST-----
You can use your mouse to copy and paste the CSR into the signer’s Web form.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 225
Chapter 6
✦
Securing Linux
225
Within 48 to 72 hours after you complete the validation and have paid for the signing, you should receive an e-mail with your shiny new SSL certificate in it. The certificate will look similar to the following:
-----BEGIN CERTIFICATE-----
MIIEFjCCA3+gAwIBAgIQMI262Zd6njZgN97tJAVFODANBgkqhkiG9w0BAQQFADCB ujEfMB0GA1UEChMWVmVyaVNpZ24gVHJ1c3QgTmV0d29yazEXMBUGA1UECxMOVmVy aVNpZ24sIEluXy4xMzAxBgNVBAsTKlZlcmlTaWduIEludGVybmF0aW9uYWwgU2Vy dmVyIENBIC0gZ2xhc3MgMzFJMEcG10rY2g0Dd3d3LnZlcmlzaWduLmNvbS9DUFMg
SW5jb3JwLmJ51FJlZi4gTElBQklMSVRZIExURC4oYyk5NyBWZXJpU2lnbjAeFw0w
MzAxMTUwMDAwMDBaFw0wNDAxMTUyMzU5NTlaMIGuMQswCQYDVQQGEwJVUzETMBEG
A1UECBMKV2FzaG1uZ3RvHiThErE371UEBxQLRmVkZXJhbCBXYXkxGzAZBgNVBAoU
EklETSBTZXJ2aWMlcywgSW5jLjEMMAoGA1UECxQDd3d3MTMwMQYDVQQLFCpUZXJt cyBvZiB1c2UgYXQgd3d3LnZlcmlzawduLmNvbS9ycGEgKGMpMDAxFDASBgNVBAMU
C2lkbXNlcnYuY29tMIGfMA0GCSqGS1b3DQEBAQUAA4GNADCBiQKBgQDaHSk+uzOf
7jjDFEnqT8UBa1L3yFILXFjhj3XpMXLGWzLmkDmdJjXsa4x7AhEpr1ubuVNhJVI0
FnLDopsx4pyr4n+P8FyS4M5grbcQzy2YnkM2jyqVF/7yOW2pDl30t4eacYYaz4Qg q9pTxhUzjEG4twvKCAFWfuhEoGu1CMV2qQ1DAQABo4IBJTCCASEwCQYDVR0TBAIw
ADBEBgNVHSAEPTA7MDkGC2CGSAGG+EUBBxcDMCOwKAYIKwYBBQUHAgEWHGh0dHBz
Oi8vd3d3LnZlcmlzaWduLmNvbS9ycGEwCwYDVRRPBAQDAgWgMCgGA1UdJQQhMB8G
CWCGSAGG+EIEM00c0wIYBQUHAwEGCCsGAQUFBwmCMDQGCCsGAQUFBwEBBCgwJjAk
BggrBgEFBQcwAYYYaHR0cDovL29jc2AudmVyaXNpZ24uY29tMEYGA1UdHwQ/MD0w
O6A5oDeGNWh0dHA6Ly9jcmwudmVyaxNpZ24uY29tL0NsYXNzM0ludGVybmF0aW9u
YWxTZXJ2ZXIuY3JsMBkGCmCGSAgG+E+f4Nfc3zYJODA5NzMwMTEyMA0GCSqGSIb3
DQEBBAUAA4GBAJ/PsVttmlDkQai5nLeudLceb1F4isXP17B68wXLkIeRu4Novu13
8lLZXnaR+acHuCkW01b3rQPjgv2y1mwjkPmC1WjoeYfdxH7+Mbg/6fomnK9auWAT
WF0iFW/+a8OWRYQJLMA2VQOVhX4znjpGcVNY9AQSHm1UiESJy7vtd1iX
-----END CERTIFICATE-----
Copy and paste this certificate into an empty file called server.crt
, which must reside in the /etc/httpd/conf/ssl.crt
directory, and restart your Web server.
In Fedora Core, you restart your Web server by typing:
#
service httpd restart
Assuming your Web site was previously working fine, you can now view it in a secure fashion by placing an s after the http in the Web address. So if you previously viewed your Web site at http://acmemarina.com
, you can now view it in a secure fashion by going to https://acmemarinacom
.
Generating and running a self-signed SSL certificate is much easier than having a signed certificate. To generate a self-signed SSL certificate, do the following:
Remove the key and certificate that currently exist:
# cd /etc/httpd/conf
#
rm ssl.key/server.key ssl.crt/server.crt
Create your own server key:
#
/usr/bin/openssl genrsa 1024 > ssl.key/server.key
12_579495 ch06.qxd 12/27/04 9:48 PM Page 226
226
Part II ✦
Running the Show
Make the server.key file readable and writable only by root:
#
chmod 600 ssl.key/server.key
Create the self-signed certificate by typing the following:
#
make testcert
umask 77 ; \
/usr/bin/openssl req -new -key
/etc/httpd/conf/ssl.key/server.key
.
.
.
-x509 -days 365 -out /etc/httpd/conf/ssl.key/server.crt
At this point, it is time to start adding some identifying information to the certificate that the third-party source will later validate. Before you can do this, you must unlock the private key you just created. Do so by typing the password you typed earlier. Then follow this sample procedure:
You are about to be asked to enter information that will be incorporated into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
-----
Country Name (2 letter code) [GB]:
US
State or Province Name (full name) [Berkshire]:
Ohio
Locality Name (e.g., city) [Newbury]:
Cincinnati
Organization Name (e.g., company) [My Company Ltd]:
Industrial
Press, Inc.
Organizational Unit Name (e.g., section) []:
IT
Common Name (e.g., your name or your server’s hostname)
[]:
www.industrialpressinc.com
Email Address []:
This generation process places all files in the proper place. All you need to do is restart your Web server and add https instead of http in front of your URL. (The https protocol is used when you want transmissions to be encrypted.) Remember, you’ll get a certificate validation message from your Web browser, which you can safely ignore.
Restarting Your Web Server
Your Web server requires you to enter your certificate password every time it is started. This is to prevent someone from breaking into your server, stealing your private key, and masquerading as you. Should someone manage to break in and take your key, you are safe in the knowledge that the private key is a jumbled mess.
If you just cannot stand having to enter a password every time your Web server starts and are willing to accept the increased risk, you can remove the password encryption on your private key. Simply do the following:
12_579495 ch06.qxd 12/27/04 9:48 PM Page 227
Chapter 6
✦
Securing Linux
227
#
cd /etc/hhtpd/conf/ssl.key
#
/usr/bin/openssl rsa -in server.key -out server.key
Troubleshooting Your Certificates
If you are having problems with your SSL certificate, here are some troubleshooting tips:
✦
Only one SSL certificate per IP address is allowed. If you want to add more than one SSL-enabled Web site to your server, you must bind another IP address to the network interface.
✦
Make sure the permission mask on the /etc/httpd/conf/ssl.* directories and their contents is 700 ( rwx-----).
✦
Make sure you aren’t blocking port 443 on your Web server. All https requests come in on port 443. If you are blocking it, you will not be able to get secure pages.
✦
The certificate only lasts for one year, and then you must renew it with your certificate authority. Each CA has a different renewal procedure, so check your CA’s Web site for details.
✦
Make sure you have the mod_ssl package installed. You will not be able to serve any SSL-enabled traffic without it.
The Secure Shell package (SSH) provides shell services similar to the rsh
, rcp
, and rlogin commands, but encrypts the network traffic. It uses private-key cryptography, so it is ideal for use with Internet-connected computers.
If you have installed the openssh-server software package, the SSH server is automatically configured to start. The SSH daemon is started from the
/etc/init.d/sshd startup script. To make sure the service is set up to start automatically, type the following (as root user) on a Fedora Core system:
#
chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
This result shows that the sshd service is set to run in system states 2, 3, 4, and 5, which means that whenever the system is up and connected to the network, the sshd service is running. If the service is off, you can turn it on so it comes up when you boot Linux by typing the following as root user:
#
chkconfig sshd on
12_579495 ch06.qxd 12/27/04 9:48 PM Page 228
228
Part II ✦
Running the Show
This line turns on the SSH service when you enter run level 2, 3, 4, or 5. To start the service immediately, type the following:
#
/etc/init.d/sshd start
The commands you can use with the SSH service are ssh
, sftp
, and scp
. Remote users use the ssh command to log in to your system securely. The scp lets remote users copy files to and from a system. The sftp command command provides a safe way to access FTP sites.
Like the normal remote shell services, secure shell looks in the /etc/hosts.equiv
file and in a user’s
.rhost
file to determine whether it should allow a connection.
It also looks in the ssh-specific files /etc/shosts.equiv
shosts.equiv
and the
.shosts
and .shosts
. Using the files is preferable because it avoids granting access to the nonencrypted remote shell services. The /etc/shosts.equiv
and .shosts
files are functionally equivalent to the traditional hosts.equiv
and
.rhosts
files, so the same instructions and rules apply.
Now you are ready to test the SSH service. From another computer on which SSH has been installed (or even from the same computer if another is not available), type the ssh command followed by a space and the name of the system to which you are connecting. For example, to connect to the system ratbert.glaci.com
, type:
#
ssh ratbert.glaci.com
If this is the first time you’ve ever logged in to that system using the ssh command, the command will ask you to confirm that you really want to connect:
Host key not found from the list of known hosts.
Are you sure you want to continue connecting (yes/no)?
Type
and press Enter. You should be prompted for a username and password in the normal way. The connection will function like a normal telnet connection, except that the information is encrypted as it travels over the network. You should now also be able to use the local system.
ssh command to run remote commands from a shell on the
The scp command is similar to the rcp command for copying files to and from
Linux systems. Here is an example of using the scp memo command to copy a file called from the home directory of the user named jake to the
/tmp directory on a computer called maple:
$
scp /home/jake/memo maple:/tmp
passwd:
********
memo 100%|****************| 153 0:00
12_579495 ch06.qxd 12/27/04 9:48 PM Page 229
Chapter 6
✦
Securing Linux
229
Enter the password for your username (if a password is requested). If the password is accepted, the remote system indicates that the file has been copied successfully.
You can name multiple files to transfer at a time. You can also use the -r with scp option to recursively copy all files from below any directories indicated.
Similarly, the sftp command starts an interactive FTP session with an FTP server that supports SSH connections. Many security-conscious people prefer sftp other ftp to clients because it provides a secure connection between you and the remote host. Here’s an example:
$
sftp ftp.handsonhistory.com
Connecting to ftp.handsonhistory.com
passwd:
********
sftp>
Tip
At this point you can begin an interactive FTP session. You can use get and put commands on files as you would using any FTP client but with the comfort of knowing that you are working on a secure connection. Use the help command to learn more about supported commands.
The sftp command, as with ssh and scp
, requires that the SSH service be running on the server. If you can’t connect to an FTP server using sftp
, the SSH service may not be available.
It’s often helpful to set up machines that you use a great deal so that you do not have to use a password to log in. The following steps take you through setting up passwordless authentication from one machine to another. (In this example, the local user is named chuckw on a computer named host1, and the remote user is also chuckw, on a computer named host2. Of course, you would use your own users’ and computers’ names.)
Caution
Log in to the local computer (in this example, I log in as chuckw to host1).
Run step 2 only once as local user on your local workstation. Do not run it again unless you lose your ssh keys. When configuring subsequent remote servers, skip right to step 3.
Type the following to generate the ssh key:
$
ssh-keygen -t dsa
Accept the defaults by pressing Enter at each request.
Type the following to copy the key to the remote server (using your own remote user and host names):
$
cd ~/.ssh
$
scp id_dsa.pub [email protected]:/tmp
[email protected]’s password:
*******
12_579495 ch06.qxd 12/27/04 9:48 PM Page 230
230
Part II ✦
Running the Show
Note
You will be asked for passwords in steps 4 and 5. This is okay.
Note
Type the following to add the ssh key to the remote-user’s authorization keys
(the code should be on one line, not wrapped):
$
ssh [email protected] ‘cat /tmp/id_dsa.pub >> /home/chuckw/.ssh/ \ authorized_keys2’
Type the following to remove the key from the temporary directory:
$
ssh [email protected] /bin/rm /tmp/id_dsa.pub
Step 6 should not ask for a password.
Now anytime you try to log in from one machine to the other using the user account chuckw, you should connect immediately without being required to enter a password.
Note
Once you have this working, it will work regardless of how many times the IP address changes on your local computer. IP address has nothing to do with this form of authentication.
You can log in to an ssh server from a Windows system using the ssh client called
PuTTY. To find out more, visit
PuTTY link.
www.chiark.greenend.org.uk
and click the
While LogSentry gathers and sorts log messages that may represent attempts to break into your computer system, PortSentry actively watches ports for intrusion behavior. It takes a more active approach to protecting your system from network intrusions.
PortSentry is a nice complement to LogSentry. It can be installed and configured on any Linux system to monitor selected TCP and UDP ports. When PortSentry perceives an attack, it reacts to the attack (in ways that you choose) and produces log messages about the activity that can be forwarded to the system administrator by
LogSentry.
PortSentry operates in several different modes, each of which can be applied to monitoring of TCP and UDP ports. The modes include:
✦
— PortSentry’s default mode. Selected UDP and TCP ports in this mode are bound by PortSentry, giving the monitored ports the appearance of offering a service to the network.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 231
Chapter 6
✦
Securing Linux
231
✦
— PortSentry listens to the ports at the socket level instead of binding the ports. This mode can detect a variety of scan techniques (strobe-style,
SYN, FIN, NULL, XMAS, and UDP scans), but because it is more sensitive than basic mode, it is likely to produce more false alarms.
✦
A
— Uses the same detection method as the regular stealth mode, but instead of monitoring only the selected ports, it monitors all ports below a selected number (port number 1023, by default). You can then exclude monitoring of particular ports. This mode is even more sensitive than Stealth mode and is more likely to cause false alarms than regular stealth mode.
Note
When a port is “bound” by PortSentry or any other network service daemon process, all requests that come to that port from the network are handled by the binding process. For example, when the httpd daemon binds to port 80, requests for Web services from the network are processed by httpd.
In addition to selecting the PortSentry mode and the ports that are monitored, you also can choose the response to your computer’s being scanned. By default,
PortSentry can log intrusion attempts and block access from the intruder. PortSentry also offers ways of using other tools to respond to intrusions, including firewall rules, route changes, and host denial configuration.
Portsentry is available from the SentryTools project site ( http://sourceforge.
net/projects/sentrytools ). You can download it in tar.gz
format, unzip and untar the file, and then make the binaries from source code. There are, however,
PortSentry software packages available from rpmfind.net for Fedora, Yellow Dog, and other Linux systems that use RPM-based software packaging.
To install PortSentry on a Debian GNU/Linux system, use the apt-get utility
( apt get install portsentry ). For Gentoo, download and install PortSentry with the emerge command ( emerge portsentry ).
As with LogSentry, you don’t need to do anything to get PortSentry to work after it is installed. By default, here is what PortSentry does after you install the portsentry package:
✦
The /etc/init.d/portsentry startup script runs automatically when you boot to run level 3, 4, or 5 (levels 3 and 5 are most commonly used).
✦
The following port numbers are configured to be monitored by PortSentry in basic mode:
1, 11, 15, 143, 540, 635, 1080, 1524, 2000, 5742, 6667, 12345, 12346,
20034, 31337, 32771, 32772, 32773, 32774, 40421, 49724, 54320
12_579495 ch06.qxd 12/27/04 9:48 PM Page 232
232
Part II ✦
Running the Show
1, 513, 635, 640, 641, 700, 32770, 32771, 32772, 32773, 32774, 31337,
54321
✦
In response to attacks (represented by scans of the ports being monitored), all further attempts to connect to any services for the protocol (TCP or UDP) will be blocked.
The computers that are blocked from accessing your system are listed in either the portsentry.blocked.tcp
portsentry or portsentry.blocked.udp
files (in the /var/ directory), depending on which protocol was scanned (TCP or UPD).
Remove entries from these files to restore access to blocked computers.
Chances are that you will want to make some changes to the way that PortSentry runs. To change how it behaves, modify the /etc/portsentry/portsentry.conf
file. In that file, you can choose which ports to monitor, the mode in which to monitor, and the responses to take when a scan is detected. The responses can include:
✦
Blocking access by the remote computer.
✦
Rerouting messages from the remote computer to a dead host. (A dead host is a machine dedicated to taking unwanted network traffic, to draw that traffic away from machines doing serious work.)
✦
Adding a firewall rule to drop packets from the remote computer.
The other file you may want to change is /etc/portsentry/portsentry.modes
, which contains the modes in which PortSentry can be run.
To edit the portsentry.conf
file, as root user, open the file using any text editor.
The following sections describe the information that can be changed in that file.
Selecting Ports
The portsentry.conf
file defines which ports are monitored in basic and stealth modes. By default, only basic TCP and UDP modes are active, so only those ports are monitored (unless you change to one of the stealth modes). The TCP_PORTS and UDP_PORTS options define which ports are monitored. Here is how they appear in the portsentry.conf
file:
TCP_PORTS=”1,11,15,143,540,635,1080,1524,2000,5742,6667,12345,12346,200
34,31337,32771,32772,32773,32774,40421,49724,54320”
UDP_PORTS=”1,513,635,640,641,700,32770,32771,32772,32773,32774,31337,
54321”
12_579495 ch06.qxd 12/27/04 9:48 PM Page 233
Chapter 6
✦
Securing Linux
233
Unless you are a TCP/IP expert, you’re probably wondering what services these ports represent. The Internet Assigned Numbers Authority (IANA) assigns services to UDP and TCP ports. You can see these assignments at www.iana.org/assignments/ port-numbers
.
Network services obtain port number assignments from the
/etc/services file.
So, in general, you can simply check the /etc/services services that are assigned to ports being scanned.
file to find out most of the
Ports assigned for monitoring are chosen based on a couple of different criteria.
Lower port numbers (1, 11, 15, and so on) are selected to catch port scanners that begin at port 1 and scan through a few hundred ports. If the scanner is blocked after accessing port 1, it won’t be able to get information about any other ports that might be open on your computer. Another criterion is to include ports that are checked specifically by intruders because those services might be vulnerable to attack. They include the systat (port 11) and netstat (port 15) services.
You will want to remove ports from the list in the portsentry.conf
file if you are actually running the service assigned to that port. On the other hand, you might want to add ports to the list if you are paranoid about attacks and you want a bit more coverage. The file contains some examples that you can uncomment (remove the
# sign) so that more ports are monitored.
If you change from basic to stealth scans (as described in the “Changing the portsentry.modes File” section later in this chapter), the ports that are monitored are those defined by the
ADVANCED_PORTS_TCP and
ADVANCED_PORTS_UDP options.
Here is how those two options are set by default:
ADVANCED PORTS TCP=”1023”
ADVANCED_PORTS_UDP=”1023”
These settings indicate that all ports from 1 to 1023 are monitored. Monitoring higher port numbers can result in many more false alarms, so that practice is not recommended. If you find that PortSentry is being tripped accidentally, you might want to exclude the ports being tripped by using the ADVANCED_EXCLUDE_TCP and
ADVANCED_EXCLUDE_UDP options. The following example shows how these two values are set by default:
ADVANCED_EXCLUDE_TCP=”111,113,139”
ADVANCED_EXCLUDE_UDP=”520,138,137,67”
Ident and NetBIOS services for TCP (ports 111, 113, and 139) and route, NetBIOS, and Bootp broadcasts for UDP (ports 520, 138, 137, and 67) are excluded from the advanced scan by default because a remote computer might hit these ports without representing any misuse. If you are running in stealth mode, you should exclude any services that you are running on your system by adding their port numbers to this list.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 234
234
Part II ✦
Running the Show
Identifying Configuration Files
PortSentry uses several configuration files in addition to portsentry.conf
. You can identify the locations of these other files within the portsentry.conf
file.
Here’s how those files are defined:
# Hosts to ignore
IGNORE_FILE=”/etc/portsentry/portsentry.ignore”
# Hosts that have been denied (running history)
HISTORY_FILE=”/var/portsentry/portsentry.history”
# Hosts denied this session only (temporary until next restart)
BLOCKED_FILE=”/var/portsentry/portsentry.blocked”
Here’s what these files are used for:
✦
The portsentry.ignore
file contains a list of all IP addresses that you do not want blocked (even if they improperly try to access ports on your computer).
By default, all IP addresses assigned to the local computer are added to this file. You can add IP addresses of trusted computers, if you like.
✦
The portsentry.history
file contains a list of IP addresses for computers that have been blocked from accessing your computer.
✦
The portsentry.blocked.* files contain a list of computers that have been blocked from accessing your computer during the current session.
The portsentry.blocked.tcp
file contains IP addresses of computers that have improperly scanned TCP ports on your computer. Addresses of computers that have been blocked after scanning UDP ports are contained in the portsentry.blocked.udp
file.
Access to ports on your computer is only blocked during the current session (that is, until the next reboot or restart of PortSentry). To more permanently exclude remote computers, you should impose other restrictions (such as by using the /etc/ hosts.deny
file, a firewall command, or a reroute to a dead host). These methods are described later in this chapter.
Choosing Responses
Someone scanning a port can be compared to someone checking a door in your house to see if it is locked. In most cases, it indicates that someone is checking your system for weaknesses. That is why, when another computer scans your ports, the default response from PortSentry is to block further access from the other computer to your computer for the duration of the current session. No action is taken to permanently block access from that computer. The BLOCK_UDP and BLOCK_TCP in the portsentry.conf
options file set which type of automatic response is taken when ports are scanned. Here is how these options are set by default:
BLOCK_UDP=”2”
BLOCK_UDP=”2”
The value in quotation marks determines how PortSentry reacts to a scan of your ports by another computer. The following list describes each of these values.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 235
Chapter 6
✦
Securing Linux
235
✦
A value of “2” (the default value) causes access to be temporarily blocked to services for the scanned protocol (TCP or UDP) and for the action to be logged.
Also, if any commands were defined to be run by a KILL_RUN_CMD command is then run. (This option is not configured by default.) option, that
✦
A value of “0” causes port scans to be logged, but not blocked.
✦
A value of “1” causes the KILL_ROUTE and KILL_HOSTS_DENY options to be run. (See the following list for descriptions of these options.) By default, further requests from the remote computer will be rerouted to a dead host, and the remote host’s IP address will be added to the
/etc/hosts.deny
file, thereby denying access to network services.
Note
Following are some suggestions on options you can use to change the responses to your ports being scanned:
✦
KILL_ROUTE
Runs the
/sbin/route command to reroute requests from the remote computer to a dead host. By default, this option is set to the following value, which effectively drops the request from the remote computer:
KILL_ROUTE=”/sbin/route add -host $TARGET$ gw 127.0.0.1”
This ipchains rule denies all packets from the remote computer. To make this action permanent, you could add the ipchains of the line) to the
/etc/sysconfig/ipchains options (from the file, replacing the
-I to the end
$TARGET$ with the actual IP address of the computer you want to deny access to.
Instead of rerouting IP packets from the remote host, you can use firewall rules to deny access. If you use ipchains access from the remote host.
firewalls, uncomment the following line to deny
KILL_ROUTE=”/sbin/ipchains -I input -s $TARGET$ -j DENY
-l”
If you are using iptables, change ipchains to iptables and create an appropriate iptables response.
✦
KILL_HOSTS_DENY
Used to deny requests for any network services that are protected by TCP wrappers. This option is set by default as follows:
KILL_HOSTS_DENY=”ALL: $TARGET$”
With the preceding option set, $TARGET$ is replaced by the IP address of the intruding remote computer and the line in quotes is added to the /etc/hosts.
deny file. For example, if the remote computer’s IP address were 10.0.0.59
, the line that appears in /etc/hosts.deny
would be:
ALL: 10.0.0.59
✦
KILL_RUN_CMD
Instead of using firewalls, rerouting, or TCP wrappers to deny an intruding computer from accessing your computer, you can choose any command you like in response. With the BLOCK_TCP and BLOCK_UDP options set to “2” , the value of KILL_RUN_CMD is run in response to a scan of your monitored ports.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 236
236
Part II ✦
Running the Show
Caution
The value of KILL_RUN_CMD should be the full path to the script you want to run, plus any options. To include the IP address of the remote computer or the port number that was scanned, you could include the $TARGET$ or $PORT$ variables, respectively. In the following example, replace
/path/to/script
with the full path to the script you want to run:
KILL_RUN_CMD=”
/path/to/script
$TARGET$ $PORT$”
Do not use any
KILL_RUN_CMD to retaliate against the intruding remote host. First, it is quite possible that the computer that is scanning your ports has itself been cracked and is thus not a valid target for retaliations, and second, retaliation may simply incite a cracker into further attacks on you.
✦
PORT_BANNER
You can send a message to the person who sets off the
PortSentry monitor by setting the PORT_BANNER option. By default, no message is defined. However, you can uncomment the following line to use that message. (An abusive message is not recommended.)
PORT_BANNER=”** UNAUTHORIZED ACCESS PROHIBITED ***
YOUR CONNECTION ATTEMPT HAS BEEN LOGGED. GO AWAY.”
The number of scans from an intruding computer that PortSentry will accept before setting off these responses can be set by using the that option is set as follows:
SCAN_TRIGGER option. By default,
SCAN_TRIGGER=”0”
The “0” value means that you won’t accept any scans from an intruding system. In other words, the first scan will trip the PortSentry monitor. You can increase this value to be tolerant of one or more errant scans (although you probably won’t want to).
The /etc/portsentry/portsentry.modes
file defines the modes in which the
PortSentry command is run at boot time. Here is how that file appears by default: tcp udp
#stcp
#sudp
#atcp
#audp
The tcp and udp options are the basic PortSentry modes for the TCP and UDP services, respectively. Your other choices of options include stealth TCP ( stcp ) and advanced stealth TCP ( atcp ) and stealth UDP ( sudp ) and advanced stealth UDP
( audp ). Run only one TCP service and one UDP service, so if you uncomment a stealth or advanced stealth service, be sure to add a comment to the appropriate basic service.
To activate the new services, execute the following command:
12_579495 ch06.qxd 12/27/04 9:48 PM Page 237
Chapter 6
✦
Securing Linux
237
#
/etc/init.d/portsentry restart
The new PortSentry modes will take effect immediately, and they will also be in effect when your computer reboots.
There are different ways to test that your ports are properly protected. What you want to do is run a program that a potential intruder would run to see if it trips the appropriate response from PortSentry. For example, you could use a port scanner to see how your ports appear to the outside world. You could also use a command, such as telnet
, to try to set off a particular port. Does PortSentry catch it?
nmap is a popular tool for scanning TCP and UDP ports. You can give the nmap command a host name or IP address, and it will scan about 1,500 ports on the local computer or on a computer you can reach on the network to see which ports are open (and presumably offering services that could potentially be cracked).
With nmap installed on your system, do the following:
If PortSentry is running, shut it down by typing the following:
#
/etc/init.d/portsentry stop
Type the following nmap system: commands to see which ports are open on the local
#
nmap -sS -O 127.0.0.1
#
nmap -sU -O 127.0.0.1
The output shows you which ports are currently offering services on your computer for TCP and UDP protocols, respectively.
If there are any services that you don’t want open, turn off those services by using chkconfig
service
off (replacing
service
with the service name), by editing the configuration file in the /etc/xinetd.d
the service and changing disable = no to directory that represents disable = yes , or by changing your firewall setup.
If there are services that you want to be available from your computer, make sure that the port numbers representing those services are not being monitored by PortSentry. Remove the port number from the
TCP_PORTS and/or
UDP_PORTS options in the /etc/portsentry/portsentry.conf
file, or
PortSentry will report that there is a possible stealth scan on the port.
Restart PortSentry as follows:
#
/etc/init.d/portsentry start
Run nmap again:
#
nmap -sS -O 127.0.0.1
#
nmap -sU -O 127.0.0.1
12_579495 ch06.qxd 12/27/04 9:48 PM Page 238
238
Part II ✦
Running the Show
The ports offering legitimate services, as well as the ports being monitored by
PortSentry, should all appear to be open.
Check the /var/log/messages file to make sure that PortSentry is not trying to monitor any ports on which you are offering services.
When you have determined that PortSentry is set up the way you would like it to be, run the nmap command from another computer on your network. This time, replace 127.0.0.1
with the name or IP address of the PortSentry computer. If everything is working, the first port that the remote computer scans on your
PortSentry computer should block all subsequent scans.
Never run nmap on a machine that is not yours. Running nmap to scan someone’s system for open ports is considered an intrusion.
In addition to taking action against intruders, PortSentry logs its activities using the syslog utility. PortSentry’s startup, shutdown, and scan-detection activities are logged to your /var/log/messages file. Here are some examples of PortSentry output in that file: portsentry[13259]: adminalert: Psionic PortSentry 1.0 is starting.
portsentry[13260]: adminalert: Going into listen mode on TCP port: 1 portsentry[13260]: adminalert: Going into listen mode on TCP port: 11
.
.
.
portsentry[13260]: adminalert: PortSentry is active and listening.
portsentry[]: attackalert: Connect from host:10.0.0.4 to TCP port: 31337 portsentry[]: attackalert: Connect from host: 10.0.0.4 to TCP port: 11 portsentry[]: attackalert: Host: 10.0.0.4 is already blocked. Ignoring
.
.
.
portsentry[13371]: securityalert: Psionic PortSentry is shutting down portsentry[13371]: adminalert: Psionic PortSentry is shutting down
The first part of the output shows PortSentry starting up. As PortSentry begins listening to each port, that port is noted in a separate log message. The next messages show the computer being scanned. Someone from host 10.0.0.4
ran nmap to scan the ports on the computer. PortSentry caught the scan of port 31337 and blocked attempts to scan other ports.
Finally, the last set of messages shows PortSentry being shut down. This is a security alert because someone besides you could shut down PortSentry to hide that he had broken in. It is followed by an adminalert.
12_579495 ch06.qxd 12/27/04 9:48 PM Page 239
Chapter 6
✦
Securing Linux
239
Note
If you’ve been running the LogSentry package (described earlier in this chapter), these messages show up in the e-mail messages you receive each hour from
Logcheck.
Tip
If access was cut off to a computer that you wanted to have access, there are several things you can check to correct that problem:
✦
/etc/hosts.deny
— See if the computer’s IP address was mistakenly added to this file. This would cause network services to be denied to the host at that
IP address.
✦
/var/portsentry/portsentry.blocked
— Check that an entry for the computer’s IP address wasn’t added to the portsentry.blocked.tcp
files.
portsentry.blocked.udp
or
✦ route — Run the /sbin/route command to see if messages from the computer are being rerouted to a dead host (probably the localhost).
✦ iptables
— Run the iptables -L command to see if a new firewall was created to block access from the computer.
To make sure that access isn’t cut off again, you can add the IP address of the remote computer to the
/etc/portsentry/portsentry.ignore
file. Future improper scans or requests for services won’t cause the remote computer to be blocked.
Once you have gone to all the effort of fortifying your server, you should test the strength of your defenses. There are several tools and one real handy collection of tools that can help you find the soft spots in your system configuration and network security.
Caution
Some of the tools described in this section require thorough research before you attempt to use them on a mission-critical network. Using these products often triggers alarms on intrusion detection systems, and some of the brute-force attack tools crash the servers they target. If you read up on them, you should be fine, but always experiment in a test environment before using these tools in a production environment.
Freely available network security tools were probably designed with less than noble goals in mind. The following security auditing software packages are essentially
12_579495 ch06.qxd 12/27/04 9:48 PM Page 240
240
Part II ✦
Running the Show
penetration tools designed to find weaknesses, report them, and ultimately exploit them if the user desires. Here’s a brief rundown on each:
✦
— The Nessus project ( www.nessus.org
) has produced a very powerful network auditing tool. One of the key features of Nessus is that it goes beyond searching for known vulnerabilities and does a good job of hunting for
possible
vulnerabilities.
✦
— If you have wireless networks to manage, monitor, and protect,
Kismet ( www.kismetwireless.net
) is a very useful tool for seeing just how easy it is to get on to those wireless networks. It is effective if you need to search for rogue access points on your network. Kismet also serves as an intrusion detection tool and traffic sniffer.
✦
— The Ethereal tool captures and analyzes network traffic related to some 530 network protocols. Data can be evaluated in real time or stored in capture files for later analysis. Ethereal can view capture logs from a wide array of network sniffer applications as well. For more information, and to obtain a copy, go to www.ethereal.com
.
If individual tools are not enough to satisfy your needs, there is an all-in-one tool simply called Auditor. Available from www.moser-informatik.ch/ , this tool combines powerful applications such as Nessus, kismet, Ethereal, and about 300 others.
Auditor combines all of these tools into a single, bootable CD that uses a simple GUI to launch the tools. The full spectrum of security-testing tools is included in this package from foot-printing (gathering information about the target of an attack) to brute-force password cracking.
With the rise of the Internet, security has become a critical issue for nearly all computer users. Properly using passwords, securely configuring network services, keeping on top of security issues, and monitoring log files are critical ways of keeping your computer secure.
Using encryption keys, you can help verify the authenticity of those with whom you communicate, as well as make the data you transmit more secure. With tools such as PortSentry, you can quickly identify unauthorized activity and help protect your
Linux system from intrusions. Protection, in this case, can even include automatic responses to those scanning your system, such as being blocked from access or being sent a message.
Auditing software such as Nessus can be used to ensure that the security provisions you have put in place are effective against modern hacking tools. There are a variety of bootable Linux distributions that are full of security-related tools you can use to get your systems safe and running smoothly.
✦ ✦ ✦
13_579495 pt03.qxd 12/27/04 9:59 PM Page 241
P A R T
✦ ✦ ✦
In This Part
✦
Chapter 7
Installing Linux
Chapter 8
Running Fedora
Core and Red Hat
Enterprise Linux
Chapter 9
Running Debian
GNU/Linux
Chapter 10
Running SUSE Linux
Chapter 11
Running KNOPPIX
Chapter 12
Running Yellow
Dog Linux
Chapter 13
Running Gentoo Linux
Chapter 14
Running
Slackware Linux
Chapter 15
Running Linspire
Chapter 16
Running
Mandrakelinux
Chapter 17
Running a Linux
Firewall/Router
Chapter 18
Running Bootable
Linux Distributions
✦ ✦ ✦ ✦
13_579495 pt03.qxd 12/27/04 9:59 PM Page 242
14_579495 ch07.qxd 12/27/04 10:08 PM Page 243
I
f someone hasn’t already installed and configured a Linux system for you, this chapter is going to help you get started so you can try out the Linux features described in the rest of the book. If you are a first-time Linux user, I recommend that you:
✦
This book’s DVD and CD include several bootable Linux systems. The advantage of a bootable Linux is that you can try out Linux without touching the contents of your computer’s hard disk. In particular, KNOPPIX is a full-featured Linux system that can give you a good feel for how Linux works. Using the
DVD or CD, you can boot directly to KNOPPIX or Damn
Small Linux, respectively. There are also other bootable
Linux distributions on the CD that you can use to create your own bootable CDs (listed in Appendix A).
✦
Choose one of the other
Linux distributions and install it on your computer’s hard disk. This will give you more flexibility for adding and removing software, accessing and saving data to hard disk, and more permanently customizing your system.
Installing Linux as a desktop system lets you try out some useful applications and get the feel for Linux before dealing with more complex server issues.
This chapter provides you with an overview of how to choose a Linux distribution and then describes issues and topics that are common to installing most Linux distributions. Appendix
A describes exactly which Linux distributions are included on this book’s DVD and CD and how to either boot them from the
DVD or CD or burn them to CD for installation. Each of the other chapters in this part of the book is dedicated to understanding and installing a particular Linux distribution.
After you’ve installed Linux, you’ll want to understand how to get and manage software for your Linux system. These are important topics that are actually covered throughout the book, but this chapter describes the major packaging formats and tools to get you going.
✦ ✦ ✦ ✦
In This Chapter
Choosing a Linux distribution
Getting a Linux distribution
Understanding installation issues
✦ ✦ ✦ ✦
14_579495 ch07.qxd 12/27/04 10:08 PM Page 244
244
Part III ✦
Choosing and Installing a Linux Distribution
There are literally hundreds of Linux distributions available today. Some are generalized distributions that you can use as a desktop, server, or workstation system; others are specialized for business or computer enthusiasts. Part of the intention of this book is to help you choose which one (or ones) will suit you best.
Using the DVD that comes with this book, you can boot directly to KNOPPIX (to try out Linux without installing it on your hard disk) or to Fedora Core 3 (to install
Linux on your computer’s hard disk). Because the Fedora Core 3 included with the book is the complete FC3 distribution, you can install a full range of desktop interfaces and applications, programming tools, and server features. So after you’ve tried out KNOPPIX and are ready to install Linux on your hard disk, I recommend you try Fedora.
The CD that comes with this book boot directly to either Damn Small Linux (a compact KNOPPIX derivative) or to a Devian GNU/Linux network install (to install a customized Debian system over the network). Damn Small Linux runs well on lower-memory machines, while te Debian install we describe works well for the sample web (LAMP) and mail servers described in chapters 23 and 24.
Other Linux distributions included on the DVD are stored there in ISO images that fit on CDs, or, in some cases, mini-CDs or bootable business card-sized CDs (shaped like business cards but can be read by most CD drives). Because of space limitations on the DVD, some of the distributions contained there are intended for network installs, which means you need an Internet connection to get some of the software to complete a full install.
Because I know a lot of people who use Linux, both informally and at work, I want to share my general impressions of how different Linux distributions are being used in the U.S. Most consultants I know who set up small office servers used to use Red
Hat Linux but now have mostly split off to using Fedora Core or Debian GNU/Linux.
Mandrakelinux has been popular with people wanting a friendly Linux desktop, but
Fedora and SUSE are also well liked. The more technically inclined like to play with
Gentoo (highly tunable) or Slackware (Linux in a more basic form).
For people who are transitioning to Linux with Mac hardware, Yellow Dog Linux lets them install on a PowerPC and learn skills that are useful to expand later to Red Hat
Linux systems (Yellow Dog is based on Red Hat). As for the bootable Linuxes, everyone I know thinks they are great fun to try out and a good way to learn about Linux.
For a bootable Linux containing desktop software that fits on a full CD (or DVD),
KNOPPIX is a good choice; for a bootable mini-CD-size Linux, Damn Small Linux works well.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 245
Chapter 7
✦
Installing Linux
245
This book exposes you to several different Linux distributions. It gives you the advantage of being able to see the strengths and weaknesses of each distribution by actually putting your hands on it. You can also try to connect into the growing
Linux user communities because strong community support results in a more solid software distribution and help when you need it (from such things as forums and online chats).
There seems to be a new Linux distribution every five minutes, and I really have to stop writing this book at some point. To keep the descriptions of Linux distributions to a reasonable size (and actually have the space to describe how to use Linux), there are several interesting Linux distributions that aren’t explored in this book.
Notable Linux distributions not included in this book are TurboLinux, Lycoris, and
Xandros. TurboLinux ( www.turbolinux.com
) is a popular distribution in Asia
Pacific countries. Lycoris (originally based on OpenLinux) and Xandros (designed to operate well in Microsoft Windows environments) are both well-regarded desktop Linux systems (see www.lycoris.com
and www.xandros.com
, respectively).
The following sections look beyond the confines of this book for those and other
Linux distributions.
By packaging a handful of Linux distributions with this book, I hoped to save you the trouble of getting Linux yourself. If you have a DVD or CD drive, perhaps you can use this opportunity to at least try KNOPPIX or Damn Small Linux so you’ll see better what’s being discussed.
If for some reason you can’t use the software on the DVD, you may want to get your own Linux distributions to use with the descriptions in this book. Reasons you might want to get your own Linux distributions include:
✦
— You need a bootable DVD drive on your computer to directly use the software that comes with this book. (If you have access to a
CD drive, however, you can copy Coyote Linux from the CD and create a Linux distribution, as described in chapter 17, hat runs from a floppy disk.)
✦
— You may want a more recent version of a particular distribution than comes with this book.
✦
— Because there’s limited space on the DVD and because some distributions require subscriptions or other fees, you may want to obtain your own, more complete distribution with which to work.
Today, there is no shortage of ways to get Linux.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 246
246
Part III ✦
Choosing and Installing a Linux Distribution
You can go to the Web site of each distribution (such as http://fedora.redhat.
com/download or http://slackware.com/getslack ) to get Linux software.
Those sites often let you download a copy (or sample) of their distributions and give you the opportunity to purchase a boxed set.
However, a way to get a more complete view of available Linux distributions is to go to a Web site that’s dedicated to spreading information about Linux distributions.
Use these sites to connect to forums, download sites, and documentation about many Linux distributions. Here are some examples:
✦
( www.distrowatch.com
) — The first place I go to find Linux distributions is DistroWatch.com. Go to the Major Distributions link to read about the top Linux distributions (most of which are included with this book).
Links will take you to download sites, forums, home pages, and other sites related to each distribution.
✦
( www.linuxiso.org
) — Like DistroWatch, this site also connects you to download sites, as well as forums, home pages, and other sites for
Linux distributions. Look for the Helpful Stuff box on the LinuxISO home page for great information on getting, burning, and verifying Linux ISO images.
✦
( www.linuxhelp.net
) — Select the ISO images link from this site’s home page, and you can find download links to ISO images for many of the most popular Linux distributions.
If you don’t want to download and burn the CDs yourself, there are plenty of ads on those sites from places willing to sell you Linux CDs or DVDs. Distribution prices are often only a little bit higher than the cost of the media and shipping. If you really like a particular Linux distribution, it’s a good idea to purchase it directly from the organization that makes it. That can ensure the health of the distribution into the future.
Books such as the
Red Hat Fedora Linux Bible
can also be a good way to get a Linux distribution. Up-to-date documentation is often a weakness when you have nothing but a CD to start out with. Standard Linux documentation (such as HOWTOs and man pages) are often out of date with the software. So, I would particularly recommend a book and distribution (such as this one or
Red Hat Fedora Linux Bible
) for first-time Linux users.
By far, the most common way of getting Linux is on CDs, or secondarily, DVDs. The next most common way is to start with a floppy or CD that includes an installation boot image and get the parts of Linux you need live from the network as you install
Linux.
The images that are burned on to the CDs are typically stored on the Internet in what are called
software repositories.
You can download them and burn them to CDs yourself. Alternatively, the software packages are usually also included separately
14_579495 ch07.qxd 12/27/04 10:08 PM Page 247
Chapter 7
✦
Installing Linux
247 in directories. Those separate software directories enable you to start an install process with a minimal boot disk that can grab packages over the network during the installation process. (Some of the installations we recommend with this book are done that way.)
Note
When you follow links to Linux software repositories, here’s what you look for:
✦
— You often have to step down a few directories from the download link that gets you to a repository. Look for subdirectories that describe the distribution, architecture, release, and medium format. For example, mirrors for the Fedora Core 3 Linux distribution might be named fedora/ linux/core/3/i386/iso
.
✦
— The software images you are going to burn to CD are typically stored in ISO format. Some repositories include a README file to tell you what images you need (others just assume you know). To install a distribution, you want the set of ISOs containing the Linux distribution’s binary files. For example, the set of four Fedora Core 3 installation images for i386 platforms starts with FC3-i386-disc1.iso (with the others named disc2, disc3, and disc4).
Although an ISO image appears as one file, it’s actually like a snapshot of a file system. You can mount that image to see all the files the image contains by using the loop feature of the mount command. For example, with an image called abc.iso
in the current directory, create an empty directory ( mkdir myiso ) and run the mount command as follows: mount -o loop abc.iso myiso
. Change to the myiso directory, and you can view the files and directories the ISO image contains.
✦
— To verify that you got the right CDs completely intact, after you download them, look for a file named MD5SUM or ending in .md5
in the ISO directory. You can use that file to verify the content of each CD (as described later).
You can download each ISO image by simply clicking the link and downloading it to a directory in your computer when prompted. You can do this on a Windows or
Linux system.
If you know the location of the image you want, with a running Linux system, the wget command is a better way to download than just clicking a link in your browser. The advantage of using wget is that you can restart a download that stops in the middle for some reason. A wget command to download a KNOPPIX CD image (starting from the directory you want to download to) might look like this:
$
wget -c ftp.tux.org/pub/linux/knoppix/KNOPPIX_V3.6-2004-08-16-EN.iso
If the download stops before it is completed, run the command again. The -c option tells wget to begin where the download left off, so that if you are 640MB into a 650MB download when it stopped, it will just add in the last 10MB.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 248
248
Part III ✦
Choosing and Installing a Linux Distribution
There is also a facility called BitTorrent ( http://bitconjurer.org/BitTorrent ) you might want to look into. BitTorrent lets you download a file to your computer by grabbing bits of that file from multiple computers on the network that are downloading the file at the same time. For the privilege, you also use your upload capacity to share the same file with others as you are downloading. During times of heavy demand with a new Linux distribution, BitTorrent can be the best way to go.
If you are on a dial-up modem, you should strongly consider purchasing Linux CDs
(or getting them from a friend) if the DVD or CD with this book doesn’t have what you want. You might be able to download a whole 700MB CD in a couple hours on a fast
DSL or cable modem connection. On a dial-up line, you might be talking a whole day or more per CD. For a large, multi-CD distribution, available disk space can also become a problem (although, with today’s large hard disks, it’s not as much of a problem as it used to be).
With the CD images copied to your computer, you can proceed to verify their contents and burn them to CD. All you really need is a CD burner on your computer.
Note
With Linux running, you can use the md5sum command to verify the CD.
If you are using Windows to validate the contents of the Linux CD, you can get the
MD5Summer utility ( www.md5summer.org
) to verify each CD image.
Assuming you downloaded the MD5 file associated with each CD image and have it in the same directory as your CD images, run the md5sum command to verify the image.
For example, to verify the KNOPPIX CD shown previously in the wget example, you could type the following:
$
md5sum KNOPPIX_V3.6-2004-08-16-EN.iso
5bc8e9fee2a8be0b7180fcf3e49b5386 KNOPPIX_V3.6-2004-08-16-EN.iso
The MD5SUM file I downloaded previously from the download directory was called
KNOPPIX_V3.4-2004-05-17-EN.iso.md5
. It contained this content:
5bc8e9fee2a8be0b7180fcf3e49b5386 * KNOPPIX_V3.6-2004-08-16-EN.iso
As you can see, the checksum (first string of characters shown) that is output from the ISO image matches the checksum in the MD5 file. So you know that the image you downloaded is the image they put on the server. As long as you got the image from a reliable site, you should be ready to burn the CD.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 249
Chapter 7
✦
Installing Linux
249
With your Linux distribution in hand (either the DVD or Cd with this book or the set of CDs you got elsewhere), proceed to Appendix A for details on burning your own
CDs or DVDs. After that, instructions for installing the distributions from the DVD can be found in separate chapters for each distribution (Chapters 8 through 18).
Before you proceed, however, there’s some information that is useful for nearly every Linux system you are installing.
Before you begin installing your Linux distribution of choice, there is some general
Linux information you should understand. Reading over this information might help you avoid problems or keep you from getting stuck when you install Linux.
Every Linux will not run on every computer. When installing Linux, most people use a Pentium-class PC. There are Linux systems that are compiled to run on other hardware, such as Mac PowerPCs or AMD 64-bit computers. However, the distributions provided with this book run on only 32-bit Pentium-class PCs.
Note
Minimum hardware requirements from the Fedora Project are pretty good guidelines for most Linux systems:
✦
— The latest version of Fedora Core recommends that you at least have a Pentium-class processor. For a text-only installation, a 200 MHz
Pentium is the minimum, while a 400MHz Pentium II is the minimum for a GUI installation.
If you have a 486 machine (at least 100 MHz), consider trying Slackware. The problem is that many machines that old have only floppy disks, so you can’t use the CD or DVD that come with this book. In that case, you can try ZipSlack ( www.slack
ware.com/zipslack ), which is a Slackware version that comes on about 30+ floppy disk images or a 100MB zip disk and can run on a 486 with at least 100MB of disk space.
✦
— You should have at least 64MB of RAM to install most Linux distributions and run it in text mode. Slackware might run on 8MB of RAM, but 16MB is considered the minimum. If you are running in graphical mode, you will probably need at least 192MB. The recommended RAM for graphical mode in
Fedora is 256MB. A GNOME environment generally requires a bit less memory to run than a KDE environment. If you are using a more streamlined graphical system (that runs X with a small window manager, such as Blackbox), you might get by with as little as 32MB. In that case, you might try Damn Small
Linux or Slackware.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 250
250
Part III ✦
Choosing and Installing a Linux Distribution
✦
— You need to be able to boot up the installation process from a DVD or CD. If you can’t boot from a DVD or CD, there are ways to start the installation from a hard disk or using a PXE install. Some distributions, such as Slackware or Fedora (prior to Fedora Core 2), let you use floppy disks to boot installation. Once the install is booted, the software can sometimes be retrieved from different locations (over the network or from hard disk, for example).
✦
— If you are doing an install of one of the distributions for which we provide a scaled-down boot disk, you might need to have an Ethernet card installed to get the software you need over the network. A dial-up connection won’t work for network installs. You don’t necessarily have to be connected to the Internet to do a network install. Some people will download the necessary software packages to a computer on their LAN and then use that as an install server.
If you’re not sure about your computer hardware, there are a few ways to check what you have. If you are running Windows, the System Properties window can show you the processor you have, as well as the amount of RAM that’s installed.
As an alternative, you can boot KNOPPIX and let it detect and report to you the hardware you have. (Run lspci , lsmod , and information about your computer hardware.) dmseg commands in Linux to view
If you already have a version of the Linux you are installing on your computer, many
Linux distributions offer an upgrade option. This lets you upgrade all packages, for example, from version 1 of the distribution to version 2. Here are a few general rules before performing an upgrade:
✦
— There is a possibility that after you finish your upgrade, the operating system won’t boot. It’s always a good idea to back up any critical data and configuration files (in /etc ) before doing any major changes to your operating system.
✦
— If there are software packages you don’t need, remove them before you do an upgrade. Upgrade processes typically upgrade only those packages that are on your system. Upgrades generally do more checking and comparing than clean installs do, so any package you can remove saves time during the install.
✦
— A Linux upgrade procedure often leaves copies of old configuration files. You should check that the new configuration files still work for you.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 251
Chapter 7
✦
Installing Linux
251
Tip
Installing Linux from scratch goes faster than an upgrade. It also results in a cleaner Linux system. So if you have the choice of backing up your data or just erasing it if you don’t need it, a fresh install is usually best.
Some Linux distributions, most notably Gentoo, have taken the approach of ongoing updates. Instead of taking a new release every few months, you simply continuously grab updated packages as they become available and install them on your system.
It is possible to have multiple, bootable operating systems on the same computer
(using multiple partitions on a hard disk and/or multiple hard disks). Setting up to boot more than one operating system, however, requires some thought. It also assumes some risks.
Caution
While tools for resizing Windows partitions and setting up multiboot systems have improved in recent years, there is still considerable risk of losing data on Windows/
Linux dual-boot systems. Different operating systems often have different views of partition tables and master boot records that can cause your machine to become unbootable (at least temporarily) or lose data permanently. Always back up your data before you try to resize a Windows (NTFS or FAT) file system to make space for Linux. If you have a choice, install Linux on a machine of its own or at least on a separate hard disk.
If the computer you are using already has a Windows system on it, it’s likely that that the entire hard disk is devoted to Windows. While you can run a bootable
Linux such as KNOPPIX or Damn Small Linux without touching the hard disk, to do a more permanent installation you’ll want to find disk space outside the Windows installation. There are a few ways to do this:
✦
— Instead of messing with your Windows partition, you can simply add a hard disk and devote it to Linux.
✦
— If you have available space on your
Windows partition, you can shrink that partition so there is available free space on the disk to devote to Linux. Commercial tools such as Partition
Magic ( www.semantec.com/partitionmagic ) or Acronis Disk Director
( www.acronis.com
) are available to resize your disk partitions and set up a workable boot manager. Some Linux distributions (particularly bootable
Linuxes used as rescue CDs) include a tool called QTParted that is an open source clone of Partition Magic (which includes software from the Linux-NTFS project for resizing Windows NTFS partitions).
Before you try to resize your Windows partition, you might need to defragment it. To
defragment
your disk on some Windows systems, so that all your used space is put in order on the disk, open My Computer, right-click your hard disk icon (typically C:), select Properties, click Tools, and select Defragment Now.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 252
252
Part III ✦
Choosing and Installing a Linux Distribution
Defragmenting your disk can be a fairly long process. The result of defragmentation is that all the data on your disk are contiguous, creating a lot of contiguous free space at the end of the partition. There are cases where you will have to do the following special tasks to make this true:
• If the Windows swap file is not moved during defragmentation, you must remove it. Then, after you defragment your disk again and resize it, you will need to restore the swap file. To remove the swap file, open the
Control Panel, open the System icon, and then click the Performance tab and select Virtual Memory. To disable the swap file, click Disable Virtual
Memory.
• If your DOS partition has hidden files that are on the space you are trying to free up, you need to find them. In some cases, you won’t be able to delete them. In other cases, such as swap files created by a program, you can safely delete those files. This is a bit tricky because some files should not be deleted, such as DOS system files. You can use the attrib -s -h command from the root directory to deal with hidden files.
Once your disk is defragmented, you can use commercial tools described earlier
(Partition Magic or Acronis Disk Director) to repartition your hard disk to make space for Linux. An open source alternative to those tools is QTParted.
Boot KNOPPIX or any of several other bootable Linux distributions (particularly rescue CDs) and run QTParted by selecting System Tools
➪
QTParted from the desktop main menu. From the QTParted window, select the hard disk you want to resize. Then choose Options
➪
Configuration to open a window where you can select the ntfsresize tool to resize your NTFS partition.
After you have cleared enough disk space to install Linux (see disk space requirements earlier in this chapter), you can choose your Linux distribution and install it.
As you set up your boot loader during installation, you will be able to identify the
Windows, Linux, and any other bootable partitions so that you can select which one to boot when your start your computer.
Sometimes a Linux installation will fail because the computer has some nonfunctioning or nonsupported hardware. Sometimes you can get around those issues by passing options to the install process when it boots up. Those options can do such things as disable selected hardware (nousb, noscsi, noide, and so on) or not probe hardware when you need to select your own driver (noprobe).
Although some of these options are distribution-specific, others are simply options that can be passed to an installer environment that works from a Linux kernel.
Chapter 11 includes a list of many boot options that can be used with KNOPPIX and other Linux systems.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 253
Chapter 7
✦
Installing Linux
253
Tip
The hard disk (or disks) on your computer provides the permanent storage area for your data files, applications programs, and the operating system itself. Partitioning is the act of dividing a disk into logical areas that can be worked with separately.
In Windows, you typically have one partition that consumes the whole hard disk.
However, there are several reasons you may want to have multiple partitions:
✦
— If you install Linux on a PC that already has a
Windows operating system, you may want to keep both operating systems on the computer. For all practical purposes, each operating system must exist on a completely separate partition. When your computer boots, you can choose which system to run.
✦
— To protect from having your entire operating system run out of disk space, people often assign separate partitions to different areas of the Linux file system. For example, if /home
/var and were assigned to separate partitions, then a gluttonous user who fills up the /home partition wouldn’t prevent logging daemons from continuing to write to log files in the /var/log directory.
Multiple partitions also make it easier to do certain kinds of backups (such as an image backup). For example, an image backup of /home would be much faster
(and probably more useful) than an image backup of the root file system ( / ).
✦
— Different kinds of file systems that have different structures. File systems of different types must be on their own partitions.
In most Linux systems, you need at least one file system type for / (typically ext3) and one for your swap area. File systems on CD-ROM use the iso9660 file system type.
When you create partitions for Linux, you will usually assign the file system type as
Linux native (using the ext2 or ext3 type on some Linux systems and reiserfs on others). Reasons to use other types include needing a file system that allows particularly long filenames or many inodes (each file consumes an inode).
For example, if you set up a news server, it can use many inodes to store news articles. Another reason for using a different file system type is to copy an image backup tape from another operating system to your local disk (such as one from an OS/2 or Minix operating system).
If you have used only Windows operating systems before, you probably had your whole hard disk assigned to C: and never thought about partitions. With many
Linux systems, you have the opportunity to view and change the default partitioning based on how you want to use the system.
During installation, systems such as SUSE and Fedora let you partition your hard disk using a graphical partitioning tool (Yast and Disk Druid, respectively). The following sections describe how to use Disk Druid (during installation) or fdisk. See the section
“Tips for Creating Partitions” for some ideas about creating disk partitions.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 254
254
Part III ✦
Choosing and Installing a Linux Distribution
During installation, Fedora gives you the opportunity to change how your hard disk is partitioned using a tool called Disk Druid. The Disk Druid screen is divided into two sections. The top shows general information about each hard disk. The bottom shows details of each partition. Figure 7-1 shows an example of the Disk Druid window.
Figure 7-1:
Partition your disk during Fedora installation from the
Disk Setup window.
For each of the hard disk partitions, you can see:
✦
— The device name is the name representing the hard disk partition in the /dev directory. Each disk partition device begins with two letters: hd
IDE disks, sd for SCSI disks, ed for ESDI disks, or xd for for XT disks. After that is a single letter representing the number of the disk (disk 1 is a , disk 2 is b , disk 3 is c , and so on). The partition number for that disk ( 1 , 2 , 3 , and so on) follows that. For example, /dev/hda1 hard drive on the computer.
represents the first partition on the first IDE
✦
— The directory where the partition is connected into the Linux file system (if it is). You must assign the root partition ( / ) to a native Linux partition before you can proceed. If you are using RAID or LVM, the name of the RAID device or LVM volume appears here.
✦
— The type of file system that is installed on the disk partition. In many cases, the file system will be Linux (ext3), Win VFAT (vfat), or Linux swap.
However, you can also use the previous Linux file system (ext2), physical volume (LVM), or software RAID.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 255
Chapter 7
✦
Installing Linux
255
✦
— Indicates whether (check mark) or not (no check mark) the installation process should format the hard disk partition. Partitions marked with a check are erased! So, on a multiboot system, be sure your Windows partitions as well as other partitions containing data are not checked!
✦
— The amount of disk space allocated for the partition. If you selected to let the partition grow to fill the existing space, this number may be much larger than the requested amount.
✦
/
— Represents the partition’s starting and ending cylinders on the hard disk.
In the top section, you can see each of the hard disks that are connected to your computer. The drive name is shown first. The Geometry section (Geom) shows the numbers of cylinders, heads, and sectors, respectively, on the disk. That’s followed by the model name of the disk. The total amount of disk space, the amount used, and the amount free are shown in megabytes.
Reasons for Partitioning
There are different opinions about how to divide up a hard disk. Here are some issues:
✦
If you want Windows on your computer along with Linux, you need at least one Windows (Win95 FAT16,
VFAT, or NTFS type), one Linux (Linux ext3), and one Linux swap partition.
✦
If you are using the system yourself, you probably don’t need many partitions. One reason for partitioning an operating system is to keep the entire system from running out of disk space at once. That also serves to put boundaries on what an individual can use up in his or her home directory (although disk quotas are good for that as well).
✦
You need at least one partition per hard disk. If your system has two hard disks, you may assign one to
/ and one to
/home (if you have lots of users) or /var lots of data).
(if the computer is a server sharing
Deleting, Adding, and Editing Partitions
Before you can add a partition, there needs to be some free space available on your hard disk. If all space on your hard disk is currently assigned to one partition (as it often is in DOS or Windows), you must delete or resize that partition before you can claim space on another partition. The section on reclaiming disk space discusses how to add a partition without losing information in your existing single-partition system.
Caution
Make sure that any data that you want to keep is backed up before you delete the partition. When you delete a partition, all its data is gone.
Disk Druid is less flexible, but more intuitive, than the fdisk utility. Disk Druid lets you delete, add, and edit partitions.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 256
256
Part III ✦
Choosing and Installing a Linux Distribution
Tip
If you create multiple partitions, make sure that there is enough room in the right places to complete the installation. For example, most of the Linux software is installed in the
/usr directory (and subdirectories), whereas most user data are eventually added to the
/home or
/var directories.
To delete a partition in Disk Druid, do the following:
Select a partition from the list of Current Disk Partitions on the main Disk
Druid window (click it or use the arrow keys).
To delete the partition, click Delete.
When asked to confirm the deletion, click Delete.
If you made a mistake, click Reset to return to the partitioning as it was when you started Disk Druid.
To add a partition in Disk Druid, follow these steps from the main Disk Druid window:
Tip
Select New. A window appears, enabling you to create a new partition.
Type the name of the Mount Point (the directory where this partition will connect to the Linux file system). You need at least a root ( / ) partition and a swap partition.
Select the type of file system to be used on the partition. You can select from
Linux native (ext2 or preferably ext3), software RAID, Linux swap (swap), physical volume (LVM), or Windows FAT (vfat).
To create a file system type different from those shown, leave the space you want to use free for now. After installation is complete, use of the type you want.
fdisk to create a partition
Type the number of megabytes to be used for the partition (in the Size field).
If you want this partition to grow to fill the rest of the hard disk, you can put any number in this field (1 will do fine).
If you have more than one hard disk, select the disk on which you want to put the partition from the Allowable Drives box.
Type the size of the partition (in megabytes) into the Size (MB) box.
Select one of the following Additional Size Options:
•
— Click here to use only the number of megabytes you entered into the Size text box when you create the partition.
•
— If you want to use all remaining space up to a certain number of megabytes, click here and fill in the number. (You may want to do this if you are creating a VFAT partition up to the 2048MB limit that Disk Druid can create.)
•
— If you want this partition to grow to fill the rest of the disk, click here.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 257
Chapter 7
✦
Installing Linux
257
Optionally select Force to Be a Primary Partition if you want to be sure to be able to boot the partition or Check for Bad Blocks if you want to have the partition checked for errors.
Select OK if everything is correct. (The changes don’t take effect until several steps later when you are asked to begin installing the packages.)
To edit a partition in Disk Druid from the main Disk Druid window, follow these steps:
Click the partition you want to edit.
Click the Edit button. A window appears, ready to let you edit the partition definition.
Change any of the attributes (as described in the add partition procedure).
For a new install, you may need to add the mount point ( / ) for your primary
Linux partition.
Select OK. (The changes don’t take effect until several steps later, when you are asked to begin installing the packages.)
The fdisk utility is available with most every Linux system for creating and working with disk partitions in Linux. It does the same job as graphical partitioning tools such as Disk Druid, although it’s no longer offered as an option during Fedora installation.
However, during Fedora installation, and other Linux installations that have virtual terminals running, you can switch to a shell (press Ctrl+Alt+F2) and use fdisk manually to partition your hard disk.
Caution
The following procedures are performed from the command line as root user.
Remember that any partition commands can easily erase your disk or make it inaccessible. Back up critical data before using any tool to change partitions! Then be very careful about the changes you do make. Keeping an emergency boot disk handy is a good idea, too.
The fdisk command is one that is available on many different operating systems
(although it looks and behaves differently on each). In Linux, fdisk is a menu-based command. To use fdisk to list all your partitions, type the following (as root user):
#
fdisk –l
Disk /dev/hda: 40.0 GB, 40020664320 bytes
255 heads, 63 sectors/track, 4865 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 4833 38716650 83 Linux
/dev/hda3 4834 4865 257040 82 Linux swap
14_579495 ch07.qxd 12/27/04 10:08 PM Page 258
258
Part III ✦
Choosing and Installing a Linux Distribution
To see how each partition is being used on your current system, type the following:
#
df –h
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 37G 5.4G 30G 16% /
/dev/hda1 99M 8.6M 86M 10% /boot none 61M 0 61M 0% /dev/shm
Note
From the output of df
, you can see that the root of your Linux system (
/
) is on the
/dev/hda2 partition and that the /dev/hda1 partition is used for /boot .
If this had been a dual-boot system (with Windows 98), you might have seen a
Windows partition from fdisk that looked like the following:
Caution
/dev/hda1 * 1 83 666666+ b Win95 FAT32
You could mount that partition in Linux (to get to your Windows files when Linux is booted) by typing:
# mkdir /mnt/win
# mount -t vfat /dev/hda1 /mnt/win
Before using fdisk df –h to change your partitions, I strongly recommend running the command to see how your partitions are currently being defined. This will help reduce the risk of changing or deleting the wrong partition.
To use fdisk to change your partitions, you need to identify the hard disk you are partitioning. For example, the first IDE hard disk is identified as /dev/hda . So, to partition your first IDE hard drive, you can begin (as root user) by typing:
#
fdisk /dev/hda
For different hard drive types or numbers, /dev/hda is replaced by the name of the device you want to work with. For example, here are some of your choices:
Device
/dev/hda
/dev/sda
/dev/rd/c0d0
/dev/ida/c0d0
Description
For the first IDE hard disk; hdb, hdc, and so on for other IDE disks.
For the first SCSI hard disk; sdb, sdc, and so on for other SCSI disks.
For a RAID device.
Also for a RAID device.
After you have started fdisk, type
to see the options. Here is what you can do with fdisk :
14_579495 ch07.qxd 12/27/04 10:08 PM Page 259
Chapter 7
✦
Installing Linux
259
✦
Type
example,
/dev/sda2 and a partition number, and then press Enter. For would be partition number 2. (The deletion won’t take effect until you write the change — you can back out up to that point.)
✦
; l
If you have free space, you can add a new partition. Type for a logical partition (5 or over) or p for a primary partition (1–4); and a partition number from the available range. Then choose the first cylinder number from those available. (The output from fdisk –l shown earlier will show you cylinders being used under the Start and End columns.)
Next, enter the cylinder number the partition will end with (or type the specific number of megabytes or kilobytes you want: for example, +50M or +1024K).
You just created an ext3 Linux partition. Again, this change isn’t permanent until you write the changes.
✦
Press T to choose the type of file system. Enter the partition number of the partition number you want to change. Type the number representing the file system type you want to use in hexadecimal code. (Type
at this point to see a list of file system types and codes.) For a
Linux file system, use the number 83; for a Linux swap partition, use 82; and for a windows FAT32 file system, use the letter b.
✦
Throughout this process, feel free to type
display (print on the screen) the partition table as it now stands.
to
✦
Before you write your changes, display the partition table again and make sure that it is what you want it to be. If you don’t like a change you make to your partitions, press
to exit without saving. Nothing changes on your partition table.
If your changes are correct, write them to the partition table by pressing
.
You are warned about how dangerous it is to change partitions, and you must confirm the change.
An alternative to the menu-driven fdisk command is sfdisk
, which is a commandline oriented partitioning tool. With sfdisk , you type the full command line to list or change partitions, instead of being taken through a set of prompts (as with fdisk
).
See the sfdisk man page for details. Linux experts often prefer sfdisk because it can be used in combination with other commands to take and output partitioning information.
Changing your disk partitions to handle multiple operating systems can be very tricky. Part of the reason is that each different operating system has its own ideas about how partitioning information should be handled, as well as different tools for doing it. Here are some tips to help you get it right:
✦
If you are creating a dual-boot system, particularly for Windows ME or
Windows XP, try to install the Windows operating system first. Otherwise, the Windows installation may make the Linux partitions inaccessible.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 260
260
Part III ✦
Choosing and Installing a Linux Distribution
✦
The fdisk man page recommends that you use partitioning tools that come with an operating system to create partitions for that operating system. For example, the DOS fdisk knows how to create partitions that DOS will like, and the Linux fdisk will happily make your Linux partitions. Once your hard disk is set up for dual boot, however, you should probably not go back to Windows-only partitioning tools. Use Linux fdisk or a product made for multiboot systems
(such as Partition Magic).
✦
You can have up to 63 partitions on an IDE hard disk. A SCSI hard disk can have up to 15 partitions. You won’t need nearly that many partitions.
If you are using Linux as a desktop system, you probably don’t need a lot of different partitions. There are, however, some very good reasons for having multiple partitions for Linux systems that are shared by a lot of users or are public Web servers or file servers. Multiple partitions within Fedora Linux, for example, offer the following advantages:
✦
Denial of Service attacks sometimes take action that tries to fill up your hard disk. If public areas, such as /var , are on separate partitions, a successful attack can fill up a partition without shutting down the whole computer. Because /var is the default location for Web and FTP servers, and expected to hold a lot of data, entire hard disks often are assigned to the
/var file system alone.
✦
If you have only one file system (
/
), its corruption can cause the whole Fedora Linux system to be damaged.
Corruption of a smaller partition can be easier to fix and often allows the computer to stay in service while the correction is made.
Here are some directories that you may want to consider making into separate file system partitions.
Directory
/boot
/usr
Explanation
Sometimes the BIOS in older PCs can access only the first 1024 cylinders of your hard disk. To make sure that the information in your
/boot directory is accessible to the BIOS, create a separate disk partition (of about 100MB) for
/boot and make sure that it exists below cylinder 1024. The rest of your Linux system can exist outside of that 1024-cylinder boundary if you like. Even with several boot images, there is rarely a reason for
/boot to be larger than
100MB. (For newer hard disks, you can select the Linear Mode check box during installation. Then the boot partition can be anywhere on the disk.)
This directory structure contains most of the applications and utilities available to Fedora Linux users. Having
/usr on a separate partition lets you mount that file system as read-only after the operating system has been installed. This prevents attackers from replacing or removing important system applications with their own versions that may cause security problems. A separate
/usr partition is also useful if you have diskless workstations on your local network.
Using NFS, you can share
/usr over the network with those workstations.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 261
Chapter 7
✦
Installing Linux
261
Directory
/var
/home
/tmp
Explanation
Your FTP ( /var/ftp ) and Web-server ( /var/www ) directories are, by default in many Linux systems, stored under
/var
. Having a separate
/var partition can prevent an attack on those facilities from corrupting or filling up your entire hard disk.
Because your user account directories are located in this directory, having a separate /home account can prevent a reckless user from filling up the entire hard disk.
Protecting
/tmp from the rest of the hard disk by placing it on a separate partition can ensure that applications that need to write to temporary files in
/tmp are able to complete their processing, even if the rest of the disk fills up.
Although people who use Linux systems casually rarely see a need for lots of partitions, those who maintain and occasionally have to recover large systems are thankful when the system they need to fix has several partitions. Multiple partitions can localize deliberate damage (such as Denial of Service attacks), problems from errant users, and accidental file system corruption.
A boot loader lets you choose when and how to boot the bootable operating systems installed on your computer’s hard disks. Most Linux systems give you the opportunity to use GRUB or LILO boot loaders. The following sections describe both GRUB and LILO boot loaders.
With multiple operating systems installed and several partitions set up, how does your computer know which operating system to start? To select and manage which partition is booted and how it is booted, you need a boot loader. The boot loader that is installed by default with Fedora is called the GRand Unified Boot loader (GRUB).
GRUB is a GNU boot loader ( www.gnu.org/software/grub ) that replaced the LILO as the default boot loader in many Linux systems (including Fedora). GRUB offers the following features:
✦
Support for multiple executable formats.
✦
Support for multiboot operating systems (such as Fedora, FreeBSD, NetBSD,
OpenBSD, and other Linux systems).
✦
Support for nonmultiboot operating systems (such as Windows 95, Windows 98,
Windows NT, Windows ME, Windows XP, and OS/2) via a chain-loading function.
Chain-loading is the act of loading another boot loader (presumably one that is specific to the proprietary operating system) from GRUB to start the selected operating system.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 262
262
Part III ✦
Choosing and Installing a Linux Distribution
✦
Support for multiple file system types.
✦
Support for automatic decompression of boot images.
✦
Support for downloading boot images from a network.
For more information on how GRUB works, type
or
. The info command contains more details about GRUB.
When you install Linux, you are typically given the option to configure the information needed to boot your computer (with one or more operating systems) into the default boot loader. With GRUB configured, when you boot your computer, the first thing you see after the BIOS loads is the GRUB boot screen (it says GRUB at the top and lists bootable partitions below it), do one of the following:
✦
— If you do nothing, the default operating system will boot automatically after a few seconds.
✦
— Use the up and down arrow keys to select any of the operating systems shown on the screen. Then press Enter to boot that operating system.
✦
— If you want to change any of the options used during the boot process, use the arrow keys to select the operating system you want and type
to select it. Follow the next procedure to change your boot options temporarily.
If you want to change your boot options so that they take effect every time you boot your computer, see the section on permanently changing boot options.
Changing those options involves editing the /boot/grub/grub.conf
file.
From the GRUB boot screen, you can select to change or add boot options for the current boot session. First, select the operating system you want (using the arrow keys) and type
(as described earlier). You will see a graphical screen that contains information like the following:
GRUB version 0.94 (639K lower / 128768K upper memory) root (hd0,0) kernel /boot/vmlinuz-2.6.5-1.350 ro root=LABEL=/ initrd /boot/initrd-2.6.5-1.350.img
Use the
↑ and
↓ keys to select which entry is highlighted.
Press ‘b’ to boot, ‘e’ to edit the selected command in the boot sequence, ‘c’ for a command-line, ‘o’ to open a new line after (‘O’ for before) the selected line, ‘d’ to remove the selected line, or escape to go back to the main menu.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 263
Chapter 7
✦
Installing Linux
263
There are three lines in the example of the GRUB editing screen that identify the boot process for the operating system you chose. The first line (beginning with root ) shows that the entry for the GRUB boot loader is on the first partition of the first hard disk ( hd0,0
). GRUB represents the hard disk as hd
, regardless of whether it is a SCSI, IDE, or other type of disk. You just count the drive number and partition number, starting from zero.
The second line of the example (beginning with kernel
) identifies the boot image
( /boot/vmlinuz-2.6.5-1.350
) and several options. The options identify the partition as initially being loaded ro
(read-only) and the location of the root file system on a partition with the label LABEL=/ . The third line (starting with initrd ) identifies the location of the initial RAM disk, which contains the minimum files and directories needed during the boot process.
If you are going to change any of the lines related to the boot process, you would probably change only the second line to add or remove boot options. Here is how you do that:
Position the cursor on the kernel line and type
.
Either add or remove options after the name of the boot image. You can use a minimal set of bash shell command-line editing features to edit the line. You can even use command completion (type part of a filename and press Tab to complete it). Here are a few options you may want to add or delete:
•
If you forgot your root password or if your boot process hangs, you can boot directly to a shell by adding init=/bin/sh to the boot line. (The file system is mounted read-only, so you can copy files out. You need to remount the file system with read/write permission to be able to change files.)
•
If you want to boot to a particular run level, you can add the word linux
,
followed by the number of the run level you want.
For example, to have Fedora Linux boot to run level 3 (multiuser plus networking mode), add linux 3 to the end of the boot line. You can also boot to single-user mode (1), multiuser mode (2), or X GUI mode (5).
Level 3 is a good choice if your GUI is temporarily broken.
Press Enter to return to the editing screen.
Type
to boot the computer with the new options. The next time you boot your computer, the new options will not be saved. To add options so they are saved permanently, see the next section.
You can change the options that take effect each time you boot your computer by changing the GRUB configuration file. In Fedora and other Linux systems, GRUB configuration centers around the /boot/grub/grub.conf
file.
The /boot/grub/grub.conf
file is created when you install Linux. Here’s an example of that file for Fedora Core:
14_579495 ch07.qxd 12/27/04 10:08 PM Page 264
264
Part III ✦
Choosing and Installing a Linux Distribution
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making
# changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hda6
# initrd /initrd-version.img
#boot=/dev/hda default=0 timeout=10 splashimage=(hd0,4)/grub/splash.xpm.gz
title Fedora Linux (2.6.5-1.350) root (hd0,4) kernel /vmlinuz-2.6.5-1.350 ro root=LABEL=/ initrd /initrd-2.6.5-1.350.img
title Windows XP rootnoverify (hd0,0) chainloader +1
The default=0 line indicates that the first partition in this list (in this case Fedora
Linux) will be the one that is booted by default. The line timeout=10 causes GRUB to pause for 10 seconds before booting the default partition. (That’s how much time you have to press E if you want to edit the boot line, or to press arrow keys to select a different operating system to boot.)
Note
The splashimage line looks in the fifth partition on the first disk ( hd0,4
) for the boot partition (in this case /dev/hda5 , which is the /boot splash.xpm.gz
partition). GRUB loads as the image on the splash screen (
/boot/grub/splash.xpm.gz
).
The splash screen appears as the background of the boot screen.
GRUB indicates disk partitions using the following notation: ( hd0,0
). The first number represents the disk, and the second is the partition on that disk. So,
( hd0,1
) is the second partition (1) on the first disk (0).
The two bootable partitions in this example are Fedora and Windows XP . The title lines for each of those partitions are followed by the name that appears on the boot screen to represent each partition.
For the Fedora Linux system, the root line indicates the location of the boot partition as the second partition on the first disk. So, to find the bootable kernel
( vmlinuz-2.6.5-1.350
) and the initrd initial RAM disk boot image that is loaded
( initrd-2.6.5-1.350.img
), GRUB looks in the root of hd0,4
(which is represented by /dev/hda5 and is eventually mounted as /boot ). Other options on the kernel line set the partition as read-only initially ( ro
) and set the root file system to
/dev/hda6
.
For the Windows XP partition, the rootnoverify line indicates that GRUB should not try to mount the partition. In this case, Windows ME is on the first partition of the first hard disk
(hd0,0) or
/dev/hda1
. Instead of mounting the partition and
14_579495 ch07.qxd 12/27/04 10:08 PM Page 265
Chapter 7
✦
Installing Linux
265
Note
passing options to the new operating system, the chainloader +1 indicates to hand control the booting of the operating system to another boot loader. The
+1 indicates that the first sector of the partition is used as the boot loader.
Microsoft operating systems require that you use the chainloader to boot them from GRUB. This is because GRUB doesn’t offer native support for WIndows operating sytems.
If you make any changes to the /boot/grub/grub.conf
file, you
do not
need to load those changes. GRUB automatically picks up those changes when you reboot your computer. If you are accustomed to using the LILO boot loader, this may confuse you at first, as LILO requires you to rerun the lilo command for the changes to take effect.
You may have different boot images for kernels that include different features. Here is the procedure for modifying the grub.conf
file:
Copy the new image from the directory in which it was created (such as
/usr/src/linux-2.4/arch/i386/boot
) to the
/boot directory. Name the file something that reflects its contents, such as bz-2.4.21
. For example:
# cp /usr/src/linux-2.6.5/arch/i386/boot/bzImage /boot/bz-2.6.5
Add several lines to the /boot/grub/grub.conf
started at boot time if it is selected. For example: file so that the image can be title Fedora Linux (IPV6 build) root (hd0,4) kernel /bz-2.6.5 ro root=/dev/hda6 initrd /initrd-2.6.5.img
Reboot your computer.
When the GRUB boot screen appears, move your cursor to the title representing the new kernel and press Enter.
The advantage to this approach, as opposed to copying the new boot image over the old one, is that if the kernel fails to boot, you can always go back and restart the old kernel. When you feel confident that the new kernel is working properly, you can use it to replace the old kernel or perhaps just make the new kernel the default boot definition.
LILO stands for LInux LOader. Like other boot loaders, LILO is a program that can stand outside the operating systems installed on the computer so you can choose which system to boot. It also lets you give special options that modify how the operating system is booted. On Slackware and other Linux systems, LILO is used instead of GRUB as the default boot loader.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 266
266
Part III ✦
Choosing and Installing a Linux Distribution
If LILO is being used on your computer, it is installed in either the master boot record or the first sector of the root partition. The master boot record is read directly by the computer’s BIOS. In general, if LILO is the only loader on your computer, install it in the master boot record. If there is another boot loader already in the master boot record, put LILO in the root partition.
Using LILO
When your computer boots with the Fedora version of LILO installed in the master boot record, a graphical Fedora screen appears, displaying the bootable partitions on the computer. Use the up and down arrow keys on your keyboard to select the one you want and press Enter. Otherwise, the default partition that you set at installation will boot after a few seconds.
If you want to add any special options when you boot, press Ctrl+X. You will see a text-based boot prompt that appears as follows: boot:
LILO pauses for a few seconds and then automatically boots the first image from the default bootable partition. To see the bootable partitions again, quickly press
Tab. You may see something similar to the following:
LILO boot: linux linux-up dos boot:
This example shows that three bootable partitions are on your computer, called linux , linux-up , and dos . The first two refer to two different boot images that can boot the Linux partition. The third refers to a bootable DOS partition (presumably containing a Windows operating system). The first bootable partition is loaded if you don’t type anything after a few seconds. Or you could type the name of the other partition to have that boot instead.
If you have multiple boot images, press Shift, and LILO will ask you which image you want to boot. Available boot images and other options are defined in the
/etc/lilo.conf
file.
Note
Setting Up the /etc/lilo.conf File
The /etc/lilo.conf
file is where LILO gets the information it needs to find and start bootable partitions and images. By adding options to the
/etc/lilo.conf
file, you can change the behavior of the boot process. The following is an example of some of the contents of the
/etc/lilo.conf
file:
Because LILO is not used by default in Fedora Core and some other Linux systems, there may be no
/etc/lilo.conf
file. However, the Fedora installation program creates an
/etc/lilo.conf.anaconda
file to suit your installation. If you change from GRUB to LILO, you can copy that file to
/etc/lilo.conf
.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 267
Chapter 7
✦
Installing Linux
267 prompt timeout=50 default=linux boot=/dev/hda map=/boot/map install=/boot/boot.b
message=/boot/message linear image=/boot/vmlinuz-2.6.5-1.327
label=linux initrd=/boot/initrd-2.6.5-1.327.img
read-only root=/dev/hda6 append=”root=LABEL=/” other=/dev/hda1 optional label=dos
With prompt on, the boot prompt appears when the system is booted without requiring that any keys are pressed. The timeout value, in this case 50 tenths of a second (5 seconds), defines how long to wait for keyboard input before booting the default boot image. The boot line indicates that the bootable partition is on the hard disk represented by
/dev/hda
(the first IDE hard disk).
The map line indicates the location of the map file (
/boot/map
, by default). The map file contains the name and locations of bootable kernel images. The install line indicates that the
/boot/boot.b
file is used as the new boot sector. The message line tells LILO to display the contents of the /boot/message file when booting (that contains the graphical Fedora boot screen that appears). The linear line causes linear sector addresses to be generated (instead of sector/head/cylinder addresses).
In the sample file, there are two bootable partitions. The first ( image=/boot/ vmlinuz-2.6.5-1.327
) shows an image labeled linux . The root file system ( / ) for that image is on partition
/dev/hda6
. Read-only indicates that the file system is first mounted read-only, though it is probably mounted as read/write after a file system check. The inidrd line indicates the location of the initial RAM disk image used to start the system.
The second bootable partition, which is indicated by the word
other
in this example, is on the
/dev/hda1 partition. Because it is a Windows XP system, it is labeled a
DOS file system. The table line indicates the device that contains the partition.
Other bootable images are listed in this file, and you can add another boot image yourself (like one you create from reconfiguring your kernel as discussed in the next section) by installing the new image and changing lilo.conf
.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 268
268
Part III ✦
Choosing and Installing a Linux Distribution
After you change lilo.conf
, you then must run the lilo command for the changes to take effect. You may have different boot images for kernels that include different features. Here is the procedure for modifying the lilo.conf
file:
Copy the new image from the directory in which it was created (such as
/usr/src/linux-2.6/arch/i386/boot
) to the
/boot directory. Name the file something that reflects its contents, such as zImage-2.6.5-1 .
Add several lines to the /etc/lilo.conf
at boot time if it is selected. For example: file so that the image can be started image=/boot/zImage-2.6.5-1 label=new
Type the lilo -t command (as root user) to test that the changes were okay.
Type the lilo command (with no options) for the changes to be installed.
To boot from this new image, either select new from the graphical boot screen or type
and press Enter at the LILO boot prompt. If 5 seconds is too quick, increase the timeout value (such as 100 for 10 seconds).
Options that you can use in the /etc/lilo.conf
file are divided into global options, per-image options, and kernel options. There is a lot of documentation available for
LILO. For more details on any of the options described here or for other options, you can see the lilo.conf
manual page (type man lilo.conf
) or any of the documents in /usr/share/doc/lilo*/doc .
A few examples follow of global options that you can add to /etc/lilo.conf
.
Global options apply to LILO as a whole, instead of just to a particular boot image.
You can use the default=label option, where label is replaced by an image’s label name, to indicate that a particular image be used as the default boot image.
If that option is excluded, the first image listed in the
/etc/lilo.conf
file is used as the default. For example, to start the image labeled new by default, add the following line to lilo.conf
: default=new
Change the delay from 5 seconds to something greater if you want LILO to wait longer before starting the default image. This gives you more time to boot a different image. To change the value from 5 seconds (50) to 15 seconds (150), add the following line: delay=150
14_579495 ch07.qxd 12/27/04 10:08 PM Page 269
Chapter 7
✦
Installing Linux
269
You can change the message that appears before the LILO prompt by adding that message to a file and changing the message line. For example, you could create a
/boot/boot.message
file and add the following words to that file: Choose linux, new, or dos
. To have that message appear before the boot prompt, add the following line to /etc/lilo.conf
: message=/boot/boot.message
All per-image options begin with either an image= line (indicating a Linux kernel) or other= (indicating some other kind of operating system, such as Windows XP). The per-image options apply to particular boot images rather than to all images (as global options do). Along with the image or other line is a label= line, which gives a name to that image. The name is what you would select at boot time to boot that image.
Here are some of the options that you can add to each of those image definitions:
✦ lock — This enables automatic recording of boot defaults for different boot options.
command lines as the
✦ alias=name — You can replace
name
with any name. That name becomes an alias for the image name defined in the label option.
✦ password=
password
— You can password-protect all images by adding a password option line and replacing
password
with your own password.
The password would have to be entered to boot any of the images.
✦ restricted — This option is used with the password option. It indicates that a password should be used only if command-line options are given when trying to boot the image.
For Linux kernel images, there are specific options that you can use. These options let you deal with hardware issues that can’t be autodetected, or provide information such as how the root file system is mounted. Here are some of kernel image-specific options:
✦ append — Add a string of letters and numbers to this option that need to be passed to the kernel. In particular, these can be parameters that need to be passed to better define the hard disk when some aspect of that disk can’t be autodetected. For example: append=”hd=64,32,202”
✦ ramdisk — Add the size of the RAM disk that you want to use so as to override the size of the RAM disk built into the kernel.
✦ read-only — Indicates to mount the root file system read-only. It is typically remounted read/write after the disk is checked.
✦ read-write
— Indicates to mount the root file system read/write.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 270
270
Part III ✦
Choosing and Installing a Linux Distribution
If you don’t want to use the GRUB boot loader, or if you tried out LILO and want to switch back to GRUB, it’s not hard to change to a different boot loader on Linux distributions that support both boot loaders. To switch your boot loader from GRUB to LILO, do the following:
Configure the /etc/lilo.conf
file as described in the “Booting Your Computer with LILO” section. (On Fedora systems, you can use the contents of /etc/ lilo.conf.anaconda
to start.)
As root user from a Terminal window, type the following:
#
lilo
The new Master Boot Record is written, including the entries in /etc/ lilo.conf
.
Reboot your computer. You should see the LILO boot screen.
To change your boot loader from LILO to GRUB, do the following:
Configure the /boot/grub/grub.conf
Computer with GRUB” section.
file as described in the “Booting Your
You need to know the device on which you want to install GRUB. For example, to install GRUB on the master boot record of the first disk, type the following as root user from a Terminal window:
#
grub-install /dev/hda
The new Master Boot Record is written to boot with the GRUB boot loader.
Reboot your computer. You should see the GRUB boot screen.
If you are connecting your computer to an Ethernet LAN that has a DHCP server available, you probably don’t need to do anything to start up automatically on your
LAN and probably be connected to the Internet. However, if there is no DHCP server on your LAN and you have to configure your TCP/IP connection manually, here is the information you will probably be prompted for during Linux installation:
✦
— If you set your own IP address, this is the four-part, dot-separated number that represents your computer to the network. How IP addresses are formed and how you choose them is more than can be said in a few sentences
(see Chapter 5 for a more complete description). An example of a private IP address is 192.168.0.1.
✦
— The netmask is used to determine what part of an IP address represents the network and what part represents a particular host computer. An example of a netmask for a Class C network is 255.255.255.0. Applying this
14_579495 ch07.qxd 12/27/04 10:08 PM Page 271
Chapter 7
✦
Installing Linux
271 netmask to an IP address of 192.168.0.1, for example, the network address would be 192.168.0 and the host address 1. Because 0 and 255 can’t be assigned to a particular host, that leaves valid host numbers between
1 and 254 available for this local network.
✦
— Some Linux install procedures ask you to indicate if you want the network to start at boot time (you probably do if you have a LAN).
✦
— This is the name identifying your computer within your domain. For example, if your computer were named “baskets” in the handson history.com
domain, your full hostname may be baskets.handsonhistory.
com . You can either set the domain name yourself (manually) or have it assigned automatically, if that information is being assigned by a DHCP server (automatically via DHCP).
✦
— This is the IP number of the computer that acts as a gateway to networks outside your LAN. This typically represents a host computer or router that routes packets between your LAN and the Internet.
✦
— This is the IP address of the host that translates computer names you request into IP addresses. It is referred to as a Domain Name
System (DNS) server. You may also have Secondary and Tertiary name servers in case the first one can’t be reached. (Most ISPs will give you two
DNS server addresses.)
Depending on which Linux install you are using, there are other types of information you will be asked to enter. These might involve:
✦
— Most Linux distributions these days use iptables to configure firewalls. Older Linux systems use ipchains. When you configure a default firewall, you typically choose which ports will be open to outside connections on your system (although there are many other things a firewall can be configured to do as well). The iptables firewall facility is described in Chapter 17 when you configure a router/firewall.
✦
— While Linux itself doesn’t include support for lots of different languages, some Linux distributions (such as Fedora) and desktop environments (such as KDE) offer support for many different languages. Nearly all
Linux distributions let you configure language-specific keyboards.
✦
— Every Linux system that uses passwords will have you add at least the root user’s password when you install
Linux. Some distributions require that you add at least one additional nonroot user as well.
Besides the features just mentioned, every distribution needs to have some initial configuration done before you have a fully functional Linux system. See Chapter 4 for information on basic administrative tasks for Linux.
14_579495 ch07.qxd 12/27/04 10:08 PM Page 272
272
Part III ✦
Choosing and Installing a Linux Distribution
With the knowledge you’ve gained in this chapter, you’re ready to select a Linux distribution to install. Read the descriptions of Linux distributions in the other chapters in Part II of this book. Each chapter includes an icon box that tells you if the distribution described there is on the DVD or CD or, if it isn’t, where you can get it.
If you need more information about the DVD or CD, Appendix A describes the contents of those media. It also tells you which Linux distributions can be booted directly from the DVD or CD and which have to be burned to CD before you can boot or install the distribution.
While every Linux distribution includes a different installation method, there are many common activities you need to do, regardless of which Linux system you install. For every Linux system, you need to deal with issues of disk partitioning, network configuration, and boot loaders.
Linux Bible 2005 Edition
includes a DVD and a CD with several different Linux systems you can install. If you prefer, you can instead download and burn your own
CDs or DVDs to install Linux. If you go the route of burning your own CDs, this chapter helps you find Linux distributions you can download and describes tools you can use to verify their contents.
✦ ✦ ✦
15_579495 ch08.qxd 12/27/04 9:58 PM Page 273
I
n September 2003, the world’s leading Linux distribution,
Red Hat Linux, disappeared.
Red Hat Inc., the company that created Red Hat Linux, divided its development efforts in two directions: the Fedora Project, which produces the Fedora Core operating system, and Red
Hat Enterprise Linux. The split came from trying to better serve two diverse groups with one operating system. Wanting to make some money on the value that Red Hat Inc. adds to
Linux might have had something to do with it as well.
On the
DVD-ROM
Fedora Core 3 is included on the DVD that comes with this book. You can install the entire distribution from this DVD, using descriptions in Appendix A and the “Installing Fedora
Core” section later in this chapter. If you don’t have a DVD drive, you can obtain the same software on four CDs by downloading them from the Internet ( http://fedora.
redhat.com/download
) and burning them to CD as described in Appendix A.
Fedora Core and Red Hat Enterprise Linux both come from a base of code that stems from the Red Hat Linux legacy. Going forward, the two distributions have different goals and audiences and may drift farther apart over time.
Fedora Core is intended to include the latest Linux technology and be a proving ground for features slated to go into Red Hat
Enterprise Linux products. It is a freely distributed operating system for the Linux community.
✦ ✦ ✦ ✦
In This Chapter
Digging into
Fedora Core
Going forward with
Fedora Core
Installing Fedora
Core
✦ ✦ ✦ ✦
15_579495 ch08.qxd 12/27/04 9:58 PM Page 274
274
Part III ✦
Choosing and Installing a Linux Distribution
Although it is sponsored and directed by Red Hat Inc., the Fedora Project encourages community involvement. The latest Fedora Core will include many more features than Red Hat Enterprise Linux, but those features have less guarantee of stability and no guarantee of support.
Note
Fedora Core follows the legacy of Red Hat Linux. The final version of Red Hat Linux was version 9. Fedora Core 1 and Red Hat Enterprise Linux 3 followed Red Hat
Linux 9.
Red Hat Enterprise Linux (RHEL), which is actually represented by multiple products for desktop, server, and workstation computer systems, is licensed commercially.
Red Hat puts all its documentation, training, and support effort behind RHEL, which it sells to customers in the form of subscriptions. The intent is to have RHEL be a rock-solid Linux system that can be deployed across entire enterprises.
Despite the confusion it unleashed by dumping its flagship Red Hat Linux line and fears by some that Red Hat might become another Microsoft, Red Hat is still the dominant player when it comes to commercial Linux products. Many people have been happy to upgrade their critical Linux systems to Red Hat Enterprise Linux products.
To its credit, Red Hat has managed to become a profitable venture while making some remarkable contributions to the open source effort. Releasing its installer
(Anaconda) and software packaging tools (RPM Package Management) under the
GNU Public License (GPL), has enabled other Linux distributions to use and enhance those features. Within Red Hat Linux and now Fedora Core, Red Hat Inc. has worked hard to include only software that could be freely distributed (removing most software with patent and copyright issues).
Although Fedora is more of a testing facility than a guaranteed enterprise-quality operating system, for the purposes of this book, Fedora Core is a great way to evaluate and use technology that is in all Linux distributions from Red Hat. Features in
Fedora Core 3 are in Red Hat Enterprise Linux 4. Both distributions are discussed in this chapter, so you can determine which distribution is right for you.
There are many opinions on why Red Hat Linux and other distributions from Red
Hat Inc. have been so popular. The following sections describe some features of Red
Hat Linux distributions that are commonly believed to have led to its success and that add to the popularity of Fedora Core and Red Hat Enterprise Linux distributions.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 275
Chapter 8
✦
Running Fedora Core and Red Hat Enterprise Linux
275
When many Linux distributions still had you struggling from the command line to get the distribution installed, Red Hat created its own installer called Anaconda.
Anaconda includes both graphical and text-based procedures for installing Linux.
When you’re done installing Red Hat Linux, you have the following:
✦
A set of software packages installed that suits how you want to use your computer (as a desktop, workstation, server, or some custom configuration).
✦
Standard information, such as date, time, time zone, and language set.
✦
A configured mouse, keyboard, video card, and monitor.
✦
An appropriately partitioned hard disk.
✦
A configured network card and firewall, to immediately connect to a LAN.
✦
A configured boot loader, to define how Linux starts up.
Besides being fairly intuitive to use, Anaconda is loaded with features to make it easy to manage the installation of many Red Hat systems. For example, these power features are built into the Anaconda installer:
✦
— After booting the install process, the actual Fedora or
RHEL distribution can be on a network server that is accessible via a Web server (http), FTP server (ftp), or UNIX file server (NFS).
✦
— It’s not so bad to sit there and click through the answers to run the installation of one Fedora Core system, but if you’re doing dozens or hundreds of installs (especially on similar computers), automating that task can be a major time-saver. Anaconda supports kickstart installs, for which you use a preconfigured kickstart file to answer the questions that come up during a Red Hat installation. If you answer all the questions in the file, you can launch the installation and have it run from start to finish without you in attendance.
✦
— With an existing Fedora system installed, Anaconda enables you to easily upgrade to a newer Fedora system. A lot of nice features for saving backups of configuration files and logging the upgrade activities are built into that process. During an upgrade, Anaconda takes into consideration any dependency issues, so the upgraded software packages will have all the libraries and commands that the features in those packages need.
You’ll find a detailed description of installing Fedora using the Anaconda installer at the end of this chapter.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 276
276
Part III ✦
Choosing and Installing a Linux Distribution
All Red Hat Linux distributions use the RPM Package Management (RPM) software packaging format to store and maintain software that the distributions use. Fedora
Core and RHEL contain a set of tools for installing, upgrading, maintaining, and querying software packages in RPM format. Essentially, the RPM software packages that are installed are maintained in a database, so you can list the contents of packages, view descriptions, and even check for tampering of the files in those packages.
Using RPM, add-on software can also be easily included in and maintained for
Fedora systems. So users who once had to know how to deal with tarballs and makefiles to compile their own software can now simply install an RPM package to get the features they want. With other Linux distributions (such as SUSE and
Mandrake) also using RPM packaging, your RPM tool skills can help you manage software on those distributions as well.
Because of the popularity of Red Hat Linux systems, lots of software repositories and third-party software management tools have been created to further automate and simplify handling software in Red Hat systems. Tools such as yum ( www.linux.
duke.edu/projects/yum ) and apt4rpm ( http://apt4rpm.sourceforge.net
) are available for updating selected software. AutoRPM ( www.autorpm.org
) was created to automatically get RPM updates from Red Hat and install them on a single system or a cluster of machines.
Early Linux systems required that someone installing Linux know a lot about their hardware and the Linux drivers needed for that hardware to work. The kudzu feature was created by Red Hat to detect and configure a lot of computer hardware automatically. This feature is a great boost to those who don’t want to worry about finding and selecting the drivers needed for their computer hardware.
Note
Kudzu runs during your initial Red Hat installation to detect your system’s hardware.
It also runs each time you start your Fedora or RHEL system so that if you add or remove hardware and restart the system, it can try to determine what the hardware is and offer you the opportunity to configure it or remove the driver, as appropriate.
The highly touted hardware detection done by the KNOPPIX bootable Linux distribution is based on the kudzu libraries from Red Hat Inc.
To add a level of consistency to the desktops on its Linux systems, Red Hat created a look-and-feel that is pretty much the same for both GNOME and KDE. Of course there are some differences in color and logos, but a user can expect to find menus, panels, workspaces, and other desktop features in Fedora Core and RHEL systems to be very similar.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 277
Chapter 8
✦
Running Fedora Core and Red Hat Enterprise Linux
277
Red Hat created a set of simplified, graphical tools for configuring and administering many basic administrative features in Red Hat systems. Using these tools, you can add printers, configure your network, add users, set up your sound card, and tune up your video card, to name a few of the features they cover.
Red Hat’s graphical configuration tools (which are described in Chapter 4) can be launched from the System Tools or Systems Settings menu or from the command line.
Recently, the beginnings of these configuration tools’ command names changed from redhat-config to system-config . For example, the tool to configure your network in Fedora is now called config-network ).
system-config-network (instead of redhat-
With the original Red Hat Linux, you could have the exact same Linux system for free (to run in your home or small business) that was being used in large-scale enterprise deployments. For just a few dollars, you could add official Red Hat support for that system, which included official security patches and upgrade paths for the future.
Today, with the different free (Fedora Core) and subscription-based (RHEL) Linuxes from Red Hat, some of the same basic advantages hold true — if you are a bit more adventurous. Because Red Hat Linux is such a successful operating system, many who have developed skills in using and deploying Red Hat Linux have rallied to support Fedora in areas where Red Hat Inc. has bowed out. The following sections explore some of those support efforts.
In April 2004, Red Hat Inc. officially ended support for Red Hat Linux 9, the last release of Red Hat Linux systems. That meant that Red Hat would no longer provide errata packages or gather bug reports for any Red Hat Linux systems. From Red
Hat’s perspective, you either had to upgrade to RHEL or go on your own with Fedora.
The Fedora Legacy Project ( www.fedoralegacy.org
) came up with a third possibility: extend the lives of select Red Hat Linux systems.
Fedora Legacy Project’s charter is to offer software patches for select Red Hat
Linux and Fedora Core systems beyond the end of life set by Red Hat Inc. These critical fixes and security patches are necessary for an operating system to remain stable for at least two to three years. Without this support, companies and consultants who want to use Fedora Core to sell with their hardware or software products can’t expect to have a stable OS to rely on for more than a few months.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 278
278
Part III ✦
Choosing and Installing a Linux Distribution
As of this writing, Red Hat Linux 7.2, 7.3, 8, and 9 releases all have Fedora Legacy
Project software repositories from which you can download available critical software updates. By following a few simple steps from the Fedora Legacy download page
( www.fedoralegacy.org/download
), you can use yum or apt tools to configure your system to automatically download and install selected packages.
Fedora Legacy Project’s Web site provides a lot of information, from a mailing list and IRC channel you can join to overview material you can read about the project.
A ton of open source software is available in the world that is not included in Fedora
Core. To coordinate the gathering and testing of open source, third-party software, the Fedora Extras Project ( www.fedora.us
) was formed by people outside Red Hat
Inc. (with Red Hat’s blessing).
Unlike Fedora Legacy repositories, which consist of updates to software already in the Fedora distribution, the Fedora Extras Project encourages people to build their software into RPM packages that can easily be installed in Fedora Core and Red Hat
Linux systems. Fedora Extras provides guidelines for producing these packages and then performs quality-assurance testing and security verification on them before adding them to the Fedora tree for anyone to download and use. To find sites that have packages included in Fedora Extras, check out the list of Fedora Extras mirror sites ( www.fedora.us/wiki/FedoraMirrorList ).
The Fedora Channels page ( www.fedora.us/wiki/FedoraChannels ) also includes software channels available for Fedora (and other Red Hat Linux systems).
Although there is great value in having a central organization coordinating and testing the software packages available for Fedora, the particular package you might want may not be available through Fedora Extras for one reason or another. Two other places you can check for RPM packages of third-party software available to use with Fedora are:
✦
www.fedoratracker.org
— Use this site to search known repositories of Fedora third-party software for the packages you are interested in. You can search by package name, description, or Fedora release. The site offers clear descriptions of the different software packages available (more than 18,000 packages at the time of this writing, and many more are sure to be available by the time you read this). This site is not officially associated with the Fedora Project.
✦
http://rpm.livna.org
— When Fedora.us merged with
Red Hat Inc. to form the Fedora Project, some third-party software maintained by Fedora.us didn’t meet Red Hat’s standards for distribution. In particular, there are licensing and patent issues surrounding some multimedia players
15_579495 ch08.qxd 12/27/04 9:58 PM Page 279
Chapter 8
✦
Running Fedora Core and Red Hat Enterprise Linux
279
Caution
and codecs. Many of these contentious packages have been moved to repositories associated with the RPM Livna.org site. Most people will use rpm.livna.
org in tandem with the Fedora.us repository to get a full range of Fedora Core software.
The whole issue of software patents is a sticky one. The FedoraTracker.org site does a good job of warning you when software you turn up in searches may violate
DCMA restrictions in the U.S. or electronic patents. You should know that installing software that violates legitimate patents can result in the owners of those patents seeking compensation.
Since Fedora came into existence, many individuals and organizations have rallied to support Fedora going forward. If you want to get into the flow of the Fedora community, I recommend starting with the Fedora Project’s own mailing lists. You can choose the Fedora mailing list that interests you from the Red Hat Mailing Lists page
( http://redhat.com/mailman/listinfo ). Start with the fedora-list or fedoraannounce-list mailing list.
Many other Fedora resources are also available on the Web, and Appendix B includes a list of many of them.
Red Hat sets out the charter for the Fedora Project on its home page ( http:// fedora.redhat.com
):
The Fedora Project is a Red-Hat-sponsored and community-supported open-source project. It is also a proving ground for new technology that may eventually make its way into Red Hat products. It is not a supported product of Red Hat Inc.
What that means exactly is still being sorted out more than a year after the launching of the Fedora Project. What it has meant so far has been three versions of Fedora
Core that have brought in development of different technologies than were included in Red Hat Enterprise Linux distributions.
Red Hat has stuck to its plan to release Fedora two to three times per year. So far, releases have stayed closer to the two-per-year pace average that was the standard for producing Red Hat Linux releases. It has also stuck to its promise to include
Fedora technology in its commercial products:
Each new release of our supported products will be based in part on a recent release of Fedora Core.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 280
280
Part III ✦
Choosing and Installing a Linux Distribution
Software in Red Hat Enterprise Linux 3 matched almost exactly the same packages that were in Fedora Core 1. The same is expected to be true with Fedora Core 3 software when Red Hat completes Red Hat Enterprise Linux 4. As for including the
Fedora community in Fedora development, Red Hat states on the Fedora home page:
Red Hat will retain editorial control over Fedora Core — but will explicitly include external developers in the process of making technical decisions that align with our project objectives. This is an evolutionary, not revolutionary change; by depending on and contributing to Open Source software since the inception of Red Hat Linux, Red Hat has always shared control over the software with external developers. Red Hat will now more explicitly share control for packaging with external developers in our new project: The Fedora Project.
Although there is no formal procedure in place as of this writing, Red Hat has stated that it expects to give people outside Red Hat more substantial roles in Fedora planning and development process based on how well they contribute to the community:
For more information on the objectives of the Fedora Project, go to http:// fedora.redhat.com/about/objectives.html
.
As you might guess, the community of people who have hitched their wagons to the
Red Hat train had some concerns about the Fedora/RHEL split. Some of the biggest concerns of the community are summed up by the following questions:
✦
Fedora has been set up as a project for shaking bugs out of software before that software goes into Red Hat’s commercial Linux products. Red Hat has gone to great lengths to make sure people know that Red Hat is not guaranteeing or supporting Fedora. If that’s the case, why should Red Hat care if Fedora is a fully integrated distribution once the parts it needs are close enough to start putting into RHEL?
✦
Right now, Red Hat is calling all the shots when it comes to features, schedules, and other critical parts of Fedora. Although Red
Hat claims it will allow more community involvement in critical parts of the project, so far it has not. Why should the community support a Linux system over which it has no control?
The funny thing is that despite the confusing and frustrating aspects of the transition, many, many people in the open source community are still supporting the
Fedora effort. I think that really is an indication of how well-regarded Red Hat’s contributions to open source have been. The company is still trusted (somewhat) to offer some real value to the open source community as it also pursues its own commercial agenda.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 281
Chapter 8
✦
Running Fedora Core and Red Hat Enterprise Linux
281
That said, I’ll end this section with an excellent and (I believe) rather realistic reflection of how the transition to Fedora looked to the open source community.
The following is a post to the fedora-devel-list mailing list that includes a fictitious
IRC session among the open source community, Fedora.us, and Red Hat Inc. by
Konstantin Ryabitsev. (Go here for the full post: http://lwn.net/Articles/
83360
.)
Let me, err, relay how things are looking from outside of RH in the format everyone will understand...
--- BEGIN IRC LOG ---
<rh_pr> We are announcing Red Hat Project! A community-based distribution!
<oss_crowd> rh_pr: Neat.
<rh_dev> rh_pr: Uh... I’m not ready.
* rh_pr is away: promoting rhel
<oss_crowd> rh_dev: what do we do?
<rh_dev> oss_crowd: I’m not sure.
<rh_legal> rh_dev: don’t do anything until I say it’s ok.
<oss_crowd> rh_dev: what can we do to help with Red Hat Project?
<rh_dev> oss_crowd: uh... file bugs and help test things.
<oss_crowd> rh_dev: didn’t we always do that?
<rh_sales> hey, all, if you really want a stable system, don’t use fedora project. It will eat your brane. Buy RHEL instead.
<rh_dev> rh_sales: stfu
--- rh_pr removes voice from rh_sales
<fedora_us> hey, all, check out our neat community-driven system for red hat development
<oss_crowd> fedora_us: ooooh!
<rh_pr> fedora_us: I like your name
--- fedora_rh joined the channel
<rh_legal> much better
<rh_pr> We are announcing Fedora Project! A community-driven distribution!
<oss_crowd> rh_pr: Neat!
* fedora_rh waves
<fedora_us> I’m not dead yet.
<fedora_rh> fedora_us: don’t confuse things.
<fedora_us> fedora_rh: does this mean we’re merging?
<fedora_rh> fedora_us: maybe
<rh_legal> fedora_rh: don’t do anything until I say it’s ok.
--- fedora_us joined #limbo
<oss_crowd> fedora_rh: so, what can we do to help?
<fedora_rh> oss_crowd: uh... file bugs and help test things.
<oss_crowd> sigh... didn’t we always do that?
<fedora_rh> oss_crowd: I know, let’s all go in the circle and say our names.
* oss_crowd goes in the circle and says their names. This lasts several months.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 282
282
Part III ✦
Choosing and Installing a Linux Distribution
<fedora_rh> So, there will be the following features in the next release of Fedora Core.
<oss_crowd> Uh... Hold on. Who gets to decide?
<rh_sales> We do. That stuff will be neato for RHEL-4.
<oss_crowd> MMkay, then. When do _we_ get to suggest things?
<fedora_rh> oss_crowd: feel free to talk among yourselves.
* oss_crowd talks among themselves about new features.
<fedora_rh> btw, feature X will be disabled in the release.
* oss_crowd glares at fedora_rh
<oss_crowd> fedora_rh: nice of you to tell us while we were sitting here talking.
<rh_dev> oss_crowd: sorry, it’s just not happening.
<oss_crowd> rh_dev: when do we get to decide what’s happening?
<rh_dev> oss_crowd: Dunno, I’ll ask rh_legal
<rh_legal> rh_dev: ugh, /msg me
<rh_sales> rh_dev: let’s not do anything rash here.
* fedora_us gets tired of sitting in #limbo
<oss_crowd> fedora_rh: I want to see more of the “community” part of the whole “community-based” thing
<oss_crowd> rh_dev: how about at least a publicly accessible CVS/SVN tree?
<rh_dev> oss_crowd: Yeah, that would be cool.
<oss_crowd> rh_dev: finally, some movement. When is that going to be up?
* rh_dev is away: talking to rh_legal
* oss_crowd tries to occupy themselves and do things like fedoranews and fedorapeople.
<oss_crowd> Uh... ping?
<fedora_uh> oss_crowd: what’s up?
<oss_crowd> fedora_rh: We’re feeling kinda useless. What exactly is our role, again?
<fedora_rh> oss_crowd: well, it would be really helpful if you could test some things and file the bugs.
<oss_crowd> fedora_rh: ugh. We ALWAYS did that.
.
.
.
--- END IRC LOG ---
Even after the third release of Fedora Core, there is still no certainty about its future.
The Linux operating system Fedora Core, sponsored by Red Hat, is included on this book’s DVD. The rest of this chapter leads you through its installation.
Before you install Fedora on your computer, ensure that your computer hardware supports it. You should also choose a method of installing Fedora Core. Those topics are discussed in the following sections.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 283
Chapter 8
✦
Running Fedora Core and Red Hat Enterprise Linux
283
Choosing your computer hardware may not really be a choice. You may just have an old PC lying around on which you want to try Fedora. Or you may have a killer workstation with some extra disk space and want to try Fedora out on a separate partition or whole disk. To install the PC version of Fedora (the version on the accompanying DVD) successfully, the computer must have the following:
✦
— The Pentium-class PC needs to be at least 200 MHz for text mode and 400 MHz Pentium II for GUI.
✦
— You need at least 64MB of RAM to install Fedora. If you are running in graphical mode, you need at least 192MB. The recommended RAM for graphical mode is 256MB.
✦
— You need to be able to boot up the installation process from a DVD or CD (the latter requires that you get Fedora Core installation
CDs as described at http://fedora.redhat.com/download ). If you can’t boot from a DVD or CD, there are ways to start the installation from a hard disk or using a PXE install, as the following section, “Choosing an Installation
Method,” explains.
✦
— Following is the required minimum disk space for five different installations. In each case, you will want to have more disk space than the minimums listed here:
— 1.9GB
— 2.4GB
— 870MB
(Custom) — 5.3GB
(Custom) — 520MB
✦
— You need a keyboard and monitor at least during installation. (You can operate Fedora quite well over a LAN using either a shell interface from a network login or an X terminal.)
Although not included with this book, Fedora Linux versions are available for the
AMD64 architecture. Red Hat Enterprise Linux versions (which you have to purchase from Red Hat Inc.) are available for other hardware, such as Intel Itanium,
IBM PowerPC, and IBM mainframe. The Fedora distribution that comes with this book and the installation procedures presented here are specific to PCs.
Note
Most of the software described in this book will work the same in any of those hardware environments. (Check out http://redhat.com/mirrors for sites that offer
Fedora Linux for different computer hardware architectures.)
The list of hardware supported by previous versions of Red Hat Linux is available on the Internet at www.redhat.com/hardware .
15_579495 ch08.qxd 12/27/04 9:58 PM Page 284
284
Part III ✦
Choosing and Installing a Linux Distribution
Note
To begin installing Fedora Core, you also need to have the
Linux Bible 2005 Edition
DVD that comes with this book (or a set of installation CDs that you obtain yourself), and you must either be dedicating your entire hard disk (or an added hard disk) to
Linux, have a preconfigured Linux partition, or have sufficient free space on your hard disk outside any existing Windows partition.
If you are not dedicating your whole hard disk to Fedora Core and you don’t understand partitioning, refer to Chapter 7, which describes how to set up partitioning to allow multiple computer operating systems to coexist on the same hard drive.
You can also install Fedora from any of several different types of media. You can still start the install process by booting the installation DVD. After booting the install process, however, you can type
at the boot prompt, which offers you the choice of installing Fedora from the following locations:
✦
— This is the most common method of installing Fedora Core and the one you get by typing
and pressing Enter from the Fedora installation boot prompt. Use this section for both DVD and CD installs. (You may need to change the BIOS if the DVD or CD doesn’t boot.) All packages needed to complete the installation are on the DVD that comes with this book.
✦
— Lets you install from a Web page address ( http:// ).
✦
— Lets you install from an FTP site ( ftp://
).
✦
— Allows you to install from any shared directory on another computer on your network using the Network File System (NFS) facility.
✦
— If you can place a copy of the Fedora Linux distribution on your hard drive, you can install it from there. (The distribution should be on a hard drive partition to which you are
not
installing.)
Although most computers enable you to install Fedora in the default mode (graphical), there may be times when your video card does not support that mode. Also, although the install process detects most computer hardware, there may be times when your hard disk, Ethernet card, or other critical piece of hardware cannot be detected and will require you to enter special information at boot time.
The following is a list of commands that you could type at the installation boot prompt to change installation modes to start the Fedora Core install process. You would typically try these modes only if the default mode failed (that is, if the screen was garbled or installation failed at some point). For a list of other supported modes, refer to the
/usr/share/doc/anaconda*/ command-line.txt
file or press F2 to see short descriptions of some of these types.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 285
Chapter 8
✦
Running Fedora Core and Red Hat Enterprise Linux
285
Command
linux text linux lowres linux nofb linux noprobe linux mediacheck linux rescue linux expert linux askmethod linux updates
Description
Runs installation in a text-based mode. Do this if installation doesn’t seem to recognize your graphics card.
Runs installation in 640
×
480 screen resolution for graphics cards that can’t support the higher resolution.
Turns off frame buffer.
Installation won’t probe to determine your hardware; you need to load any special drivers that might be needed to install it. Normally, installation auto-probes to determine what hardware you have on your computer.
Check your DVD or CDs before installing. Because media checking is done next in the normal installation process, do this only to test the media on a computer you are not installing on.
Boots from CD, mounts your hard disk, and lets you access useful utilities to correct problems that are preventing your Linux system from operating properly. (Not really an installation mode.)
Bypasses probing so you can choose your mouse, video memory, and other values that would otherwise be chosen for you. Use if you believe that the installation process is not properly auto-probing your hardware.
Has the installation process ask where to install from (local CD, NFS image, FTP, HTTP, or hard disk).
To install from an update disk.
You can add other options to the linux boot command to identify particular hardware that is not being detected properly. For example, to specify the number of cylinders, heads, and sectors for your hard disk (if you believe the boot process is not detecting these values properly), you could pass the information to the kernel as follows: linux hd=720,32,64
.
In this example, the kernel is told that the hard disk has 720 cylinders, 32 heads, and 64 sectors. You can find this information in the documentation that comes with your hard disk
(or stamped on the hard disk itself on a sticker near the serial number).
There are also other boot options you can add to the installation prompt to instruct the installation boot prompt how to start the installation. Many of these options are described in Chapter 11.
Unlike earlier Fedora and Red Hat Linux versions, Fedora Core 3 doesn’t support floppy disk boot images because the Linux 2.6 kernel is too large to fit on a floppy disk. So if you don’t have a bootable CD or DVD drive, you will need to start the install process from some other medium such as a PXE server or hard drive.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 286
286
Part III ✦
Choosing and Installing a Linux Distribution
If you’re installing Fedora on many computers with similar configurations, you can save yourself some time by using the kickstart installation, which enables you to create a set of answers to the questions Fedora Core asks you during installation.
No specific installation guide is provided with the Fedora Project. However, the Red
Hat Linux Installation Guide is available from any Red Hat FTP site (such as ftp.
redhat.com
). The location on the ftp.redhat.com
server of the Red Hat Linux 9
Installation Guide is pub/redhat/linux/9/en/doc/RH-DOCS/rhl-ig-x86-en-9/index.html
Another document you may find useful before installing is the Fedora Linux
Reference Guide (also listed in the RH-DOCS directory, as rhl-rg-en-9.0
). You’ll need to check for yourself to find out whether the Fedora Project eventually updates the reference guides for Fedora Core.
Are you doing a new install or an upgrade? If you are upgrading an existing Red Hat
Linux or Fedora system to the latest version, the installation process will try to leave your data files and configuration files intact as much as possible. This type of installation takes longer than a new install. A new install simply erases all data on the Linux partitions (or whole hard disk) that you choose.
Note
If you are upgrading an existing Fedora Linux system to this release, you should consider first removing any unwanted packages from your old Fedora Linux system.
The fewer to be checked during an upgrade, the faster the upgrade installation
(and the less space used).
You can upgrade to Fedora Core 3 from previous Fedora or Red Hat Linux systems
(such as Red Hat Linux 8 or 9). You cannot upgrade to Fedora Core 2 from a Red Hat
Enterprise Linux system.
Caution
To upgrade, you must have at least a Linux 2.0 kernel installed. With an upgrade, all of your configuration files are saved as filename.rpmsave
(for example, the hosts file is saved as hosts.rpmsave
). The locations of those files, as well as other upgrade information, is written to /tmp/upgrade.log
. The upgrade installs the new kernel, any changed software packages, and any packages that the installed packages depend on being there. Your data files and configuration information should remain intact. By clicking the Customize box, you can choose which packages to upgrade.
If you are installing a dual-boot system that includes a Windows operating system, install the Windows system first and the Fedora Core system afterward. Some
Windows systems blow away the Master Boot Record (MBR), making the Fedora
Core partition inaccessible.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 287
Chapter 8
✦
Running Fedora Core and Red Hat Enterprise Linux
287
If, when installing Windows or Fedora, you find that the other operating system is no longer available on your boot screen, don’t panic and don’t immediately reinstall. You can usually recover from the problem by booting with the Fedora Linux emergency boot disk and then using either the grub-install or lilo command to reinsert the proper MBR. If you are uncomfortable working in emergency mode, seek out an expert to help you.
Red Hat provides a description of how to configure a dual-boot system at www.
redhat.com/docs/manuals/linux/RHL-9-Manual/install-guide/ ch-x86-dualboot.html
.
Caution
Once you have selected the right type of installation for your needs, you can begin the installation procedure. Throughout most of the procedure, you can click Back to make changes to earlier screens. However, once you are warned that packages are about to be written to hard disk, there’s no turning back. Most items that you configure can be changed after Fedora is installed.
It is quite possible that your entire hard disk is devoted to a Windows 95, 98, 2000,
ME, NT, or XP operating system, and you may want to keep much of that information after Fedora Core is installed. Personal Desktop, Workstation, and Custom install classes retain existing partitions (by default), but they don’t let you take space from existing DOS partitions without destroying them. Some good commercial products are available that you can use to resize your hard disk. In particular, I recommend Partition Magic ( www.partitionmagic.com/partitionmagic
).
Tip
Ready to install? Here’s what to do:
(If you are not able to boot from the DVD, obtain an installation CD set as described earlier in this chapter and continue with this procedure by inserting the first CD into the drive.)
If you see the Fedora installation screen, continue to the next step.
If you don’t see the installation screen, your DVD or CD-ROM drive may not be bootable. You may be able to make the drive bootable, though. Here’s how: Restart the computer. Immediately, you should see a message telling you how to go into setup, such as by pressing the F1, F2, or Del key. Enter setup and look for an option such as Boot Options or Boot From. If the value is
A: First, Then C:
, change it to
CD-ROM First, Then C: or something similar. Save the changes and try to install again.
At the boot prompt, press Enter to start the install in graphical mode. If your computer won’t let you install in graphical mode (16-bit color, 800
×
600 resolution, framebuffer), refer to the “Choosing
Different Install Modes” sidebar.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 288
288
Part III ✦
Choosing and Installing a Linux Distribution
If you’re asked to check your installation media, press Enter. If the DVD is damaged, this step saves you the trouble of getting deep into the install and then failing. Once the DVD is checked, select Skip to continue.
When the welcome screen appears, click Release Notes to see information about this version of Fedora Linux. Click Next when you’re ready to continue.
Move the arrow keys to the language you want and then select Next. (Later, you will be able to add additional languages.)
Some layouts enable dead keys (on by default). Dead keys enable you to use characters with special markings (such as circumflexes and umlauts).
Select either Install Fedora Core for a new install or
Upgrade an Existing Installation to upgrade an existing version of Fedora.
Caution
to as classes):
Choose one of the following types (also referred
— Installs software appropriate for a home or office personal computer or laptop computer. This includes the GNOME desktop
(no KDE) and various desktop-related tools (word processors, Internet tools, and so on). Server tools, software development tools, and many system administration tools are not installed.
— Similar to a Personal Desktop installation but adds tools for system administration and software development. (Server software is not installed.)
Any Linux partitions or free space on your hard disk(s) will be assigned to the new installation with the Personal Desktop or Workstation types of installation. Any
Windows partitions (VFAT or FAT32 file system types) will not be touched by this install. After installation, you will be able to boot Linux or Windows. If there is no free space outside your Windows partition, you must run Partition Magic, the parted utility, the FIPS program (described later) or other disk-resizing software before proceeding, or you will lose your Windows installation.
Caution
— Server installs the software packages that you would typically need for a Linux server (in particular, Web server, file server, and print server). It does not include many other server types (DHCP, mail, DNS,
FTP, SQL, or news servers). The default server install does not include a
GUI (so you’d better know how to use the shell). This install type also erases all hard disks and assigns them to Linux by default.
This is a big one. In case you didn’t catch the previous paragraph, the Server type install erases the entire hard disk by default! If you have an existing Windows partition that you want to keep, change the Automatic Partitioning option that appears next either to only remove the Linux Partitions or to only use existing free space.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 289
Chapter 8
✦
Running Fedora Core and Red Hat Enterprise Linux
289
Note
— You are given the choice of configuring your own partitions and selecting your own software packages. Everything and
Minimum installs are available under the Custom System selection.
If you are just trying out Linux, an Everything custom install gives you all the desktop, server, and development tools that come with Fedora Linux. If you have the disk space, an Everything install saves you the trouble of installing packages you need later. If you plan to use the computer as an Internet server, be selective about which packages you install. Some software packages can represent security risks if they are installed and not configured properly.
The steps will now continue through a Custom System installation. (With other installation selections, you can simply skip over steps you are not prompted for.)
Although different install classes choose different partitioning methods by default, in all cases you can see and change the partitioning that was chosen for you.
Note
You have two choices:
— All Linux partitions on all hard disks are erased and used for the installation. The installation process automatically handles the partitioning. (It does give you a chance to review your partitioning, however.)
— The Disk Druid utility is run to let you partition your hard disk.
If you select Disk Druid for partitioning, refer to the section on partitioning your hard disk in Chapter 7 for details on using those partitioning tools.
Click Next to continue.
following:
Choose from the
— Windows and other non-
Linux partitions remain intact with this selection.
— This erases the entire hard disk.
— This works only if you have enough free space on your hard disk that is not currently assigned to any partition.
If you have multiple hard disks, you can select which of those disks should be used for your Fedora Core installation. Turn the Review check box on to see how Linux is choosing to partition your hard disk. Click Next to continue.
You can change any of the partitions you choose providing you have at least one root ( / ) partition that can hold the entire installation and one swap partition. A small
/boot partition (about 100MB) is also recommended.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 290
290
Part III ✦
Choosing and Installing a Linux Distribution
Note
The swap partition is often set to twice the size of the amount of RAM on your computer (for example, for 128MB RAM you could use 256MB of swap). Linux uses swap space when active processes have filled up your system’s RAM. At that point, an inactive process is moved to swap space. You get a performance hit when the inactive process is moved to swap and another hit when that process restarts (moves back to RAM). For example, you might notice a delay on a busy system when you reopen a window that has been minimized for a long time.
When RAM and swap fill up, no other processes can start until something closes. Bottom line: Add RAM to get better performance; add swap space if processes are failing to start. Red Hat suggests a minimum of 32MB and maximum of 2GB of swap space.
Click the Next button (and select OK to accept any changes) to continue.
All bootable partitions and default boot loader options are displayed. By default, the install process uses the GRUB boot loader, installs the boot loader in the master boot record of the computer, and chooses Fedora as your default operating system to boot.
If you keep the GRUB boot loader, you have the option of adding a GRUB password.
The password protects your system from having potentially dangerous options sent to the kernel by someone without that password. This does not have to be the same password you use to log in later. (The GRUB boot loader is described in Chapter 7.)
The names shown for each bootable partition will appear on the boot loader screen when the system starts. Change a partition name by clicking it and selecting Edit. To change the location of the boot loader, click Configure
Advanced Boot Loader Options, and continue to the next step. If you do not want to install a boot loader (because you don’t want to change the current boot loader), click Change Boot Loader and select Do Not Install a Boot Loader.
(If the defaults are okay, skip the next step.)
select one of the following:
To choose where to store the boot loader,
— This is the preferred place for GRUB. It causes GRUB to control the boot process for all operating systems installed on the hard disk.
— If another boot loader is being used on your computer, you can have GRUB installed on your Linux partition
(first sector). This lets you have the other boot loader refer to your
GRUB boot loader to boot Fedora Linux.
You can choose to add kernel parameters (which may be needed if your computer can’t detect certain hardware). Some of the kernel parameters you can use are described in Chapter 11 in descriptions of boot options. You can select to use linear mode (which was once required to boot from a partition on the disk that is above cylinder 1024 but is now rarely needed). Continue to the next step.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 291
Chapter 8
✦
Running Fedora Core and Red Hat Enterprise Linux
291
Cross-
Reference
This applies only to a local area network. If you will use only dial-up networking, skip this section by clicking Next. If your computer is not yet connected to a LAN, you also should skip this section.
Network address information is assigned to your computer in two basic ways: statically (you type it) or dynamically (a DHCP server provides that information from the network at boot time). One Network Device appears for each network card you have installed on your computer. The first Ethernet interface is eth0, the second is eth1, and so on. Repeat the setup for each card by selecting each card and clicking Edit.
Chapter 5 discusses IP addresses, netmasks, and other information you need to set up your LAN.
With the Edit Interface eth0 dialog box displayed, add the following:
— If your IP address is assigned automatically from a DHCP server, a check mark should appear here. With DHCP checked, you don’t have to set other values on this page. Remove the check mark to set your own IP address.
— If you set your own IP address, this is the four-part, dotseparated number that represents your computer to the network. How
IP addresses are formed and how you choose them is more than can be said in a few sentences (see Chapter 5 for a more complete description).
An example of a private IP address is 192.168.0.1.
— The netmask is used to determine what part of an IP address represents the network and what part represents a particular host computer. An example of a netmask for a Class C network is 255.255.255.0.
— Indicate whether you want the network to start at boot time (you probably do if you have a LAN).
Click OK, and then add the following information on the main screen:
— The name identifying your computer within your domain. For example, if your computer were named baskets in the handsonhistory.com
domain, your full hostname may be baskets.
handsonhistory.com
. You can either set the domain name yourself
(manually) or have it assigned automatically, if that information is being assigned by a DHCP server (automatically via DHCP).
— The IP number of the computer that acts as a gateway to networks outside your LAN. It represents a host computer or router that routes packets between your LAN and the Internet.
— The IP address of the host that translates computer names you request into IP addresses. It is referred to as a Domain Name
System (DNS) server. You may also have Secondary and Tertiary name servers in case the first one can’t be reached. (Most ISPs will give you two DNS server addresses.)
Click Next to continue.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 292
292
Part III ✦
Choosing and Installing a Linux Distribution
Tip
The use of a firewall has significant impact on the security of your computer. If you are connected to the Internet or to another public network, a firewall can limit the ways an intruder may break into your Linux system. Here are your choices:
— Select this security level if you are not connected to a public network and do not want to deny requests for services from any computer on your local network. Of course, you can still restrict access to services by starting up only the services you want to offer and by using configuration files to restrict access to individual services.
— Select this security level if you are connecting your
Linux system to the Internet for Web browsing and file downloading
(FTP). By default, only services needed to enable Web browsing and basic network setup, DNS replies, and DHCP (to serve addresses) are allowed at this level.
If you enable the firewall and you know you want to enable access to particular services, you can click the appropriate check boxes and allow incoming requests for the following services: SSH (secure shell to allow remote login),
Telnet (an insecure method of remote login), WWW (act as a Web server),
Mail (act as a mail server), and/or FTP (act as an FTP server). You can also add a comma-separated list of port numbers to the Other Ports box to open access to those ports, which effectively allows requests to services associated with those port numbers. (The /etc/services file lists which services are associated with which port numbers.)
If you have a LAN that consists of trusted computers, you can click the box representing your interface to that LAN (probably eth0 ). Clicking the box allows access to any services you care to share with the computers on your LAN.
Click Next to continue.
Adding firewall rules here results in rules being added to the /etc/sysconfig/ iptables file. The rules are run from the
/etc/init.d/iptables startup script when you boot your system.
The default is your installation language. You can install support for additional languages by clicking the check boxes next to the languages you want. Click the Select All button to install all supported languages to your system. When you are done, click Next to continue.
Select one from the list. To see a more specific view of your location, click World and choose your continent. From the UTC Offset tab, you can choose a time zone according to the number of hours away from
Greenwich Mean Time (GMT), known as the UTC offset.
The root password provides complete control of your
Fedora Linux system. Without it, and before you add other users, you will have no access to your own system. Enter the password, and then type it again in the Confirm box. (Remember the root user’s password and keep it confidential! Don’t lose it!) Click Next to continue.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 293
Chapter 8
✦
Running Fedora Core and Red Hat Enterprise Linux
293
Note
Tip
If you are enabling Security Enhanced Linux (SELinux) on your computer, the security structure of your computer changes. The root user may no longer have complete control of the computer, but instead there may be policies set that prevent any one user from having complete control.
Groups of packages are selected by default depending on the type of installation you chose earlier. In general, either more workstationoriented or server-oriented packages are selected. Pick the ones you want.
You can override your package selections by choosing Mimimal or Everything install groups. Disk space requirements for those install types are described earlier in this chapter.
Because each group represents several packages, you can click the Details button next to each group to select more specifically the packages within that group. Because Workstation and Personal Desktop installations don’t add any server packages, this is a good opportunity to add server packages for the services you expect to use. Click Next to continue.
You can still back out now, and the disk will not have changed.
Click Next to proceed. (To quit without changes, eject the CD and restart the computer.) Now the file systems are created and the packages are installed.
This typically takes from 20 to 60 minutes to complete, although it can take much longer on older computers.
If you are using the DVD, you do not need to change media. If you are installing from the four-CD set, you are prompted to insert additional installation CDs as they are needed.
You may be asked to configure your monitor. If it was probed properly, you should be able to just continue.
When you see the Congratulations screen, you are done.
Note the links to Fedora Core information, eject the CD, and click Exit.
If you installed GRUB, you will see a graphical boot screen that displays the bootable partitions. Press the up or down arrow key to choose the partition you want to boot, and press Enter. If Linux is the default partition, you can simply wait a few moments and it will boot automatically.
The first time your system boots after installation, the Fedora Setup Agent runs to do some initial configuration of your system. The next section explains how Fedora
Setup Agent works.
The first time you boot Fedora Core after it is installed, the Fedora Setup Agent runs to configure some initial settings for your computer.
15_579495 ch08.qxd 12/27/04 9:58 PM Page 294
294
Part III ✦
Choosing and Installing a Linux Distribution
Note
The Fedora Setup Agent runs automatically only if you have configured Fedora to boot to a graphical login prompt. To start it from a text login, log in as root and switch to init state 5 temporarily (type init 5). Log in to the graphical prompt. From a Terminal window, as root user, type
#
rm /etc/sysconfig/firstboot
#
/usr/sbin/firstboot
The Welcome screen displays. From it, step through screens to configure date and time, your monitor, user accounts, and additional software.
After throwing its devoted following into turmoil by dropping the well-known Red
Hat Linux name, Red Hat Inc. has settled its development efforts into the free Fedora
Project and commercial Red Hat Enterprise Linux.
Fedora Core and Red Hat Enterprise Linux distributions distinguish themselves from other Linux distributions with their simplified installer (called Anaconda), graphical configuration tools, and RPM Package Management tools. Fedora Core is freely available, whereas Red Hat Enterprise Linux is available on a paid subscription basis.
Fedora Core is included on the DVD that comes with this book. You can install the complete Fedora Core distribution by following the detailed instructions included in this chapter.
✦ ✦ ✦
16_579495 ch09.qxd 12/27/04 10:09 PM Page 295
On the
CD-ROM
D
ebian GNU/Linux is a creation of the Debian Project.
Founded in 1993 by Ian Murdock, the Debian Project is an association of individuals who have made a common cause to create a free, coherent, and complete operating system.
The Debian GNU/Linux network install CD is contained on the CD that comes with this book. You can install Debian from that CD as described in this chapter. You can do a minimal Debian install with just that CD or a complete Debian install with a connection to the Internet (recommended). This installation is suited for setting up a Web server (LAMP server) and a mail server (see Chapters 23 and 24, respectively).
The principles of the Debian Project are defined in the Debian
Social Contract. This contract is a commitment to the free software community that basically states:
✦
All software within the Debian system will remain free, as defined in the Debian Free Software Guidelines (DFSG).
✦
The Debian Project will contribute to the free software community by licensing any software developed for the
Debian system in accordance with the DFSG, developing the best system it can, and by sharing improvements and fixes with the original developers of any programs incorporated into Debian GNU/Linux.
✦
Problems will not be hidden from users, and any bug reports filed against Debian components will be made promptly available to the public through the Debian Bug
Tracking System (BTS).
✦
The Debian Project will focus on the needs of its users and on the principles of free software.
✦
Provisions will be made for the support of programs that do not meet the standards in the DFSG because some users may depend on these programs to make effective use of the system. The bug tracking and support systems will always include mechanisms for handling these programs when they are provided with the Debian system.
✦ ✦ ✦ ✦
In This Chapter
Inside Debian
Installing Debian
Managing your
Debian system
✦ ✦ ✦ ✦
16_579495 ch09.qxd 12/27/04 10:09 PM Page 296
296
Part III ✦
Choosing and Installing a Linux Distribution
Like most modern operating systems, software programs in Debian GNU/Linux are bundled into packages for easy distribution and management. The package format and management tools used in Debian GNU/Linux were created by the Debian
Project and are arguably the most sophisticated of their type. Additionally, careful adherence to packaging policies and quality-control measures ensure compatibility and help make upgrades go smoothly. Debian is one of very few operating system distributions in which all components (except the kernel) can be upgraded without rebooting the system.
Debian packages come in two forms: binary and source. Binary packages contain files that can be extracted directly onto the system by the package management tools. Source packages contain source code and build instructions that the Debian build tools use to create binary packages.
In addition to program data files, Debian packages contain control data that enable the package management tools to support advanced features:
✦
A main control file contains version and package interrelationship data. The version can be compared to an installed version of the same package to determine whether an upgrade is needed. The interrelationship data tell the package management tools which packages must or cannot be installed at the same time as this package.
Note
Package interrelationship fields include Depends , Conflicts , Replaces ,
Provides
,
Recommends
,
Suggests
, and
Enhances
. For a complete list of control file fields, see http://debian.org/doc/debian-policy/ch-control fields.html
.
✦
Optional preinst , postinst , prerm , and postrm files can instruct the packaging tools to perform functions before or after package installation or removal. Most packages containing daemons (such as Apache HTTPD) include a postinst script that starts the daemon automatically after installation.
✦
A conffiles file can designate specific files in the package as configuration files, which are not automatically overwritten during upgrades. By default, all files under the /etc/ directory are configuration files.
Two special package types, meta and virtual, also exist. Meta packages are standard binary packages that depend on a number of other packages. These can be used as a convenient method for installing a set of related packages.
16_579495 ch09.qxd 12/27/04 10:09 PM Page 297
Chapter 9
✦
Running Debian GNU/Linux
297
Virtual packages do not actually exist as files but can be referenced in the package interrelationship fields. They are most commonly used in cases where more than one package fulfills a specific requirement. Packages with this requirement can reference the virtual package in their
Depends field, and packages that satisfy this dependency reference it in their Provides field. Because most programs providing a virtual package are mutually exclusive, they also include the virtual package in their
Conflicts field to prevent the installation of conflicting packages.
Perhaps the most interesting and well-known part of the Debian package management system is APT, the Advanced Package Tool. APT, through the apt-get binary, maintains a database of packages available in the repositories that it is configured to check and can handle automatically downloading new or upgraded packages.
When installing or upgrading packages, APT downloads the necessary files to a local cache directory and then instructs the dpkg tool to take the appropriate actions.
Most basic package management functions are performed by dpkg , although not always at the direct request of the user. This tool handles medium-level package installation and removal and also manages the package status database. That database contains information about every package known to dpkg
, including the package meta information and two other important fields: the package state and selection state.
Note
As its name suggests, the package state indicates the present state of the package, which is one of the following:
✦
— The package is known but is not installed on the system.
✦
— An attempt was made to install the package, but an error prevented it from finishing.
✦
— The files have been extracted from the package, but any postextract configuration steps have not yet been performed.
✦
— The postextract configuration was started, but an error prevented it from finishing.
✦
— The package is fully installed and configured.
✦
— The package was removed, but the configuration files still exist on the system.
When the same version of a package that’s in the config-files state is installed, any files that may have been manually removed will not be extracted. You can work around this by either purging the package (using dpkg --purge first) or by passing the --force-confmiss option to dpkg .
16_579495 ch09.qxd 12/27/04 10:09 PM Page 298
298
Part III ✦
Choosing and Installing a Linux Distribution
The package selection state indicates what state you want the package to be in.
Changes to package status through dpkg happen immediately when using the
--install , --remove , and --purge options on a package, but other uses and tools will instead set this flag and then process any pending changes in a batch.
The package selection state is one of the following:
✦
— The package should be installed.
✦
— The package files should be removed, with the exception of configuration files.
✦
— All package files and configuration files should be removed.
✦
— dpkg should not do anything with the package unless explicitly told to do so with the --force-hold argument.
Some packages are designed to enable you to select configuration options as they are being installed. This configuration is managed through the debconf utility.
Debconf supports a number of different interfaces, including a command prompt and a menu-based interface. A database of configuration options is also maintained by debconf, allowing it to automatically answer repeated questions, such as those you might encounter while upgrading or reinstalling a package.
Examples of how to use these utilities are included in the “Managing Your Debian
System” section later in this chapter.
In Debian terms, a distribution is a collection of specific package versions. From time to time, a distribution is declared ready for release and becomes a release. In practice, these two terms are often used interchangeably when referring to Debian distributions that have reached the “stable” milestone.
Debian distributions are given code names (recent ones include potato, woody, and sarge) to identify their archive directory on the Debian servers and while active will be referenced by a release tag. There are three release tags, each one pointing to one of the three active releases. The tags — unstable, testing, and stable — identify the state of the release within the release cycle.
New packages, and new versions of packages, are uploaded to the Debian archive and are imported into the unstable distribution. This distribution always contains the newest version of every package, which means that changes have not yet been thoroughly tested to verify that installing them will not cause unexpected behavior.
Once a package has been in unstable for a few days and testing shows that it has not had any significant bugs filed against it, it is imported into the testing distribution. The testing distribution remains very similar to unstable until it is frozen in preparation for release as the next stable distribution. When testing is in the frozen state, only changes that are necessary to fix significant bugs are imported.
16_579495 ch09.qxd 12/27/04 10:09 PM Page 299
Chapter 9
✦
Running Debian GNU/Linux
299
After all release-critical bugs have been fixed in the frozen testing distribution, the release manager declares the release ready and it replaces the stable distribution.
The previous stable version becomes obsolete (but remains on the Debian archive for a reasonable period of time), a new testing distribution is created from the changes that went into unstable while testing was frozen, and the process begins again.
The CD that comes with this book contains a modified Debian network install CD and is intended for use with this tutorial. To complete more than a minimal installation, you will need an Internet connection or a local Debian software repository.
You can use other CD sets, including the official ones from the Debian Project, but doing so may still result in the need for APT to download additional packages from the Internet to complete installation.
To run Debian, you need at least a 386 processor and 32MB of RAM. For a server or a graphical workstation, you should plan on having at least 128MB of memory and a
Pentium-class processor.
A minimal set of packages requires 250MB of disk space, and a normal installation of desktop applications can require a few gigabytes. Additional space will be needed to store any data files that you want to keep on the system.
Most ISA and PCI network cards are supported under Linux, although ISA models are not usually detected automatically by the installer. Inexpensive cards based on
RealTek 8139 chipsets can be found at most PC dealers and will work fine for lowdemand applications. Intel PRO/100 and PRO/1000 adapters are supported in Linux and will work well in high-demand applications, as will cards based on the “tulip” chipsets and most 3com network cards.
Many newer systems include software-based modems that are not supported by the manufacturer under Linux. If you require a dial-up connection for Internet access, see Chapter 5 and check out http://tldp.org/HOWTO/Modem-HOWTO-2.html
before you start the installation process.
Many other devices, such as sound and video capture cards, can also be used under Linux. For more information about hardware compatibility, see the Hardware
Compatibility HOWTO at http://tldp.org/HOWTO/Hardware-HOWTO/
.
In most cases, workstation users will want to run the X Window System (X11). The ability to run X11 depends on compatibility with the video chipset on your video card or mainboard. Debian 3.1 includes version 4.3.0 of the XFree86 X11 System.
You can find a list of video chipsets supported in this release at http://xfree86.
org/4.3.0/
.
16_579495 ch09.qxd 12/27/04 10:09 PM Page 300
300
Part III ✦
Choosing and Installing a Linux Distribution
A Linux server installation generally consists of only the minimum set of packages required to provide the service for which it was designed. In particular, this means that servers do not usually have a graphical interface installed.
Note
Server hardware is generally more expensive than workstation hardware, although you can still run smaller servers on less-expensive desktop hardware. If you are planning to store important data on your server, then you will want to look into a
RAID array for storage. A number of inexpensive ATA RAID controllers work well under Linux.
More information about ATA RAID compatibility is available at http://linux mafia.com/faq/Hardware/sata.html
and http://ibiblio.org/pub/
Linux/docs/HOWTO/other-formats/html_single/Hardware-HOWTO.html
#IDERAID .
Higher-end servers will, of course, require more expensive hardware. In applications such as mail servers where you will have a lot of disk activity, plan on splitting the disk-intensive tasks across multiple arrays. When it comes to CPU and RAM, more of both is good, but most applications benefit more from extra RAM than they do from multiple CPUs.
The Debian installation process consists of two stages.
The first stage boots from the installation medium (generally a CD); configures hardware drivers, disk partitions, and file systems; and then copies a set of essential packages known as the base system. Here’s the procedure:
Boot the CD that comes with this book and type debian to begin the installation from the initial boot screen.
After the installer has finished booting, you are presented with the series of menus that make up the installation process. Use the arrow keys to navigate through the menus and select your language, region, and keyboard mapping.
Depending on whether a network card was detected in your system, you may be prompted to set up the network for your new Debian system. By default, the installer attempts to use DHCP to configure the IP addressing on the network card. If you configured it to skip DHCP, or if the DHCP configuration fails, you are prompted to enter the IP address, network mask, default gateway, and
DNS server addresses.
16_579495 ch09.qxd 12/27/04 10:09 PM Page 301
Chapter 9
✦
Running Debian GNU/Linux
301
Cross-
Reference
Note
See Chapter 7 for information about IP addresses, network masks, and other material related to setting up a network card connection.
Provide a hostname (a single-word name that you give to your system, such as debian , littlebeigebox , or yoda ) and a domain name. If you do not have your own domain name, you can make one up, such as myhouse.local
.
Configure your disk partitions for Debian. If you haven’t already done so, read
Chapter 7 for more information about partitioning.
If you already have partitions on your drive and have room for more, you are given the option to use this space for your Debian system. Another option is to erase the entire disk and use the whole thing for Debian. Either of these two options takes you through the guided partitioning, which is covered in this section.
A third option, manually editing the partition, enables you to be more exacting about your partition setup, but you should not try this without help or at least without reading Chapter 7.
The guided partitioning section presents three partitioning schemes. Each of the options includes a suitable amount of swap space but has different benefits based on your situation. You must select one from the list before you proceed. See the “Selecting a Partition Scheme” sidebar for more information.
When installing to small disk drives, use ext2 file systems instead of ext3. The journaling feature in ext3 requires that a portion of the disk be set aside for the journal, but the feature is of limited usefulness on small file systems. You can change file system types by going into the partition properties.
With your partition configuration chosen, select Finish Partitioning and Write
Changes to Disk. This is your last chance to cancel changes that could cause damage to any other operating systems you may have on the disk, so check the screen carefully before proceeding!
The installer writes the partitions to disk and creates the necessary file systems. After they have been prepared and mounted, the base system is extracted from the CD and installed to the target partitions.
The final step is to install GRUB, the boot loader. The default setting is to install to the master boot record (MBR), which is generally the best option.
Accept the defaults and continue. The installer ejects the CD and prompts you to proceed with stage 2.
Remove the CD and continue.
16_579495 ch09.qxd 12/27/04 10:09 PM Page 302
302
Part III ✦
Choosing and Installing a Linux Distribution
The guided partitioning feature allows you to select one of three templates to use to create your partitions. Use these guidelines to select the template that is correct for you.
✦
All files in one partition. Makes a single Linux partition for files. This is the easiest option to manage because you don’t have to worry about balancing the sizes of your partitions. This can also be dangerous because users have the capability to fill up the entire disk, which can cause problems for the operating system. Do not use this option unless you are prepared to monitor disk space carefully.
✦
Desktop machine. Gives the operating system its own space and gives home directories their own space. This option is a good trade-off between the convenience of a single partition and the increased safety of the multiuser scheme. However, the
/tmp/ directory is still part of the operating system partition, meaning that it is still fairly easy for people who habitually use that directory to fill up the operating system partition.
✦
Multi-user system. Creates separate partitions for the root file system,
/usr/
,
/var/
,
/tmp/
, and
/home/
. Use only this option when running a server on your system. It may also be a good choice for systems that will be used by more than just you, your relatives, and your close friends. The trade-off is that you may run out of room on a given partition even though the others have plenty of space, which means that you will need to plan carefully.
In some situations, you may need to adjust the partition sizes selected by the multiuser partitioning scheme to put more room where you are likely to need it:
✦
If you are planning to compile a lot of large software packages, you’ll need to have plenty of space in the
/usr/ partition.
✦
Active servers (especially Web and mail servers) may need extra room in
/var/ for log files. Mail servers also use this space for the mail queue, and the default mail system also stores incoming mail here (you may also want to consider making
/var/mail/ a separate partition in these cases).
✦
Web browsers such as Mozilla use
/tmp/ for storing files while they are downloaded.
This file system must be big enough to hold any large files that you want to download through there, plus any other files that may be there at the same time.
Note that with the multiuser partitioning scheme, the
/home/ partition generally ends up receiving most of the space on larger disks. This usually makes it a good place to “borrow” space from when you want to make other partitions larger. However, because partman has already mapped out the partitions, you actually need to delete
/home/ and then readd it after you increase the size of the other partition. If there are other partitions between
/home/ and the one that you are increasing in size, you also need to delete them, and then add them back in an appropriate order.
16_579495 ch09.qxd 12/27/04 10:09 PM Page 303
Chapter 9
✦
Running Debian GNU/Linux
303
The second stage boots from the newly installed packages and completes the configuration.
Your computer should reset on its own, and boot to the GRUB menu. GRUB should have already highlighted the default entry for Debian, so hit Enter and give the system a few moments to boot.
You are asked whether your system clock is set to GMT. Select Yes only if your computer will not be running any other operating systems. Then select your time zone from a list.
The base system includes an empty password for the root (superuser) account, which means that you want to set one here. Select a password that you will remember, but that others will not be able to easily guess.
Add a nonadministrative account that you can use for your day-to-day tasks on the server. Enter your name, your desired username (this should not contain any spaces or punctuation other than dashes, must not start with a number, and is generally all in lowercase), and a password for this account.
Select the installation medium that you want to use to install the remainder of the system. Insert your installation CD in the drive, select cdrom from the list, and press Enter. It takes a few moments to retrieve the list of packages available on the CD.
If you have more Debian CDs, you can have the installer check them for available packages as well.
You have the option of adding another APT source. If you have an Internet connection and want to do more than a minimal install or have the installer check for updated packages, choose either the HTTP or FTP methods (HTTP is recommended), and then select a country and a mirror server from the list.
You are prompted for any HTTP proxy configuration, which may be necessary on some corporate or school networks. If you aren’t sure, check with your support desk. If it does not apply, just leave it empty. APT retrieves a list of packages from the site that you selected.
The installer attempts to retrieve a list of security updates from the Debian security archive.
You are presented with a list of predefined package sets (known as “tasks”) that you can select for installation. Package installation is covered in greater detail later, so it’s recommended that you do not select any tasks from this list now.
APT downloads any updated packages, and debconf prompts you to configure any packages that are in the half-installed state.
16_579495 ch09.qxd 12/27/04 10:09 PM Page 304
304
Part III ✦
Choosing and Installing a Linux Distribution
Assuming that you did not select any tasks, the only package needing configuration is the Exim mail transfer agent. When the Configuring Exim screen appears, you choose from a list of default configurations; here are the two most likely options:
•
— This option configures your server to accept incoming mail and to deliver outgoing mail directly to the servers for the recipient domain. This configuration is useful if you are running a simple mail server or if you are using mutt or pine to check your mail locally.
•
— Select this option if you do not need locally generated messages to be sent to a central mail host for processing. Your system will not be configured with the capability to send messages, but this configuration still enables you to check your mail using programs such as Mozilla, Evolution, and Sylpheed that include support for sending messages using the SMTP protocol.
This is also the option you want if you will soon be setting up this system to act as a mail server based on the instructions in Chapter 24.
Enter the mail name for this system (the default is generally what you want), and choose the user to whom you want system messages to go. In most cases, you want to select the user account that was added earlier.
Note
You now have a fully functional Debian GNU/Linux system. The server does not yet have any extra packages installed but is ready to be used for the LAMP and mail server examples in this book (which you can find in Chapters 23 and 24, respectively). There’s no graphical interface installed yet, which means that all interaction will be through the command line. Take some time, as needed, to browse through
Chapter 2 and familiarize yourself with the command line before continuing with the next section.
You can install a complete desktop for Debian using the desktop section on tasksel later in the chapter for more information.
task. See the
Some of the basic tasks that you may encounter while running Debian GNU/Linux include package installation, configuration, and removal, as well as handling some special situations that you may come across.
All these steps require that you be logged in as the superuser (root). If you have just finished installing the system, you can log in as root from the login prompt.
16_579495 ch09.qxd 12/27/04 10:09 PM Page 305
Chapter 9
✦
Running Debian GNU/Linux
305
Debian includes a set of tools for managing most types of network interfaces, including Ethernet, PPP, wireless, and even ATM. You may find that you need to add or change network settings after the system has been installed.
On Debian systems, standard network connections are configured in the /etc/ network/interfaces file. If you have a network card configured to obtain an IP address automatically, this file will look like this:
# This file describes the network interfaces available on
# your system and how to activate them. For more information,
# see interfaces(5).
# The loopback network interface auto lo iface lo inet loopback
# The primary network interface auto eth0 iface eth0 inet dhcp
Caution
Note
Do not modify the loopback entry unless you are absolutely certain that you know what you are doing.
In some cases, such as when the system will be acting as a server, you want to configure your network interface with a fixed IP address. To do so, edit /etc/network/ interfaces and replace the iface eth0 inet dhcp line. Use the following block as a template, replacing the parameters with the correct settings for your network: iface eth0 inet static address 192.168.1.220
netmask 255.255.255.0
gateway 192.168.1.1
You can obtain IP network settings from your ISP or network administrator.
Wireless interfaces can also be configured using the interfaces file, but require that the wireless-tools package be installed. Use dpkg or apt-get to install the wirelesstools package. Then, add the necessary parameters to the entry for your wireless network interface. This example shows the settings for a wireless network with an access point (managed mode) set to the ESSID Home, and operating on channel 11: iface eth0 inet dhcp wireless_essid Home wireless_mode Managed wireless_channel 11
16_579495 ch09.qxd 12/27/04 10:09 PM Page 306
306
Part III ✦
Choosing and Installing a Linux Distribution
Note
If your wireless network is using encryption, you will need to specify a wireless_key parameter. You can find a complete list of wireless options in the iwconfig man page.
Dial-up connections can be managed using the pppconfig utility. Simply run pppconfig, and you are provided with a menu from which you can create, modify, and delete dial-up connection parameters. You specify connections by name when dialing, so be sure to give it a name that is easy to type.
Dial a connection using the pon command, replacing
peer
assigned to your connection: with the name you
#
pon
peer
You can disconnect using the poff command and can view logs (for diagnosing problems or determining status) using the plog command.
Some DSL and cable modem providers require that you use PPPoE (PPP over
Ethernet) to connect to their systems. PPPoE connections are managed using the pppoeconf program.
For most users, APT will be the primary tool for installing, removing, and upgrading packages. This section shows how to use the apt-get and apt-cache utilities.
The configuration file /etc/apt/sources.list
contains a list of Debian package repositories that APT will use. Like most configuration files on a Linux system, this file is a plain-text file that can be viewed using any text editor or pager. To view its contents, run the following:
#
pager /etc/apt/sources.list
deb cdrom:[Debian GNU/Linux _Sarge_ NetInst]/ stable main deb http://ftp.us.debian.org/debian/ stable main deb-src http://ftp.us.debian.org/debian/ stable main deb http://security.debian.org/ stable/updates main
Your output will differ from this example’s, of course, but the kind of information remains the same. The first part of each line indicates whether the repository is to be used for binary packages (indicated by the deb prefix) or source packages
( deb-src ). The rest of the line defines the method (in this case, cdrom or http ), the location, the distribution ( stable ), and the sections ( main ). If you want to use software from the contrib and non-free sections, you can use a text editor to add them after main .
16_579495 ch09.qxd 12/27/04 10:09 PM Page 307
Chapter 9
✦
Running Debian GNU/Linux
307
Note
Run man sources.list
on any Debian system for more information.
If you aren’t going to have your Debian CD available all the time, you may want to remove the cdrom: entry from the file. Use a text editor to edit the file:
#
editor /etc/apt/sources.list
Note
Then update the package database as described in the following section.
Astute readers may notice that the pager and editor commands used in this section are not standard UNIX commands. Both are pointers to programs and are managed using Debian’s alternatives system, which is discussed later in this chapter.
Because the lists of packages available in the Debian package repositories may change from time to time, you need to instruct APT to download these lists and update its database from time to time. To perform this process, run the following command:
#
apt-get update
You generally want to run this command before installing new packages so that you do not download an older version. Run it before checking for upgrades as well.
When looking for new packages to install, you may not always know what package you want. The package database maintained by APT includes package descriptions and other fields that can be searched using the apt-cache utility:
#
apt-cache search tetris
bsdgames -- a collection of classic textual unix games pytris -- two-player networked console tetris clone stax -- collection of puzzle games similar to Tetris Attack.
Tip
Specifying multiple keywords in a search prevents it from listing packages that do not contain all of the keywords you specify. This enables you to do very specific searches such as word processor
.
You can also use this utility to find out more information about a specific package in the repositories:
#
apt-cache show bsdgames
Package: pytris
Priority: optional
Section: games
Installed-Size: 101
Maintainer: Radovan Garabik
16_579495 ch09.qxd 12/27/04 10:09 PM Page 308
308
Part III ✦
Choosing and Installing a Linux Distribution
Note
Architecture: i386
Version: 0.96
Depends: python (>=2.1), libc6 (>= 2.2.4-4)
Filename: pool/main/p/pytris/pytris_0.96_i386.deb
Size: 16304
MD5sum: 70eb8ad6f5a8a901a95eb37f7336fc57
Description: two-player networked console tetris clone two-player networked console based tetris clone, written in python, similar to xtet42.
To view information about a specific package that is already installed on your system, use dpkg
, as discussed later in this chapter.
Once you know the name of the package you want to install, use the install method to download it and any packages on which it depends. For example, the ssh package is very useful for remotely accessing systems and is probably one of the first programs that you will want to install:
#
apt-get install ssh
Note
On this command, APT retrieves and installs the ssh package. If they are required, a list of additional packages is displayed by APT. If you choose to continue, APT will download and install those packages along with the package you requested.
When installing packages that support automatic configuration through debconf
, you’re prompted to answer the appropriate configuration questions. While the
Debian package developers have gone to great lengths to ensure that the default options for these questions will work in most situations, it’s best to read the questions thoroughly to be sure that the defaults work for you.
APT can also be used to remove packages from your system. Unlike dpkg
, which removes only the package you tell it to remove, apt-get also removes any packages that depend on the package you are removing. This is best used in conjunction with the -s performed: option to simulate what would happen if the removal were actually
#
apt-get -s remove python2.3
Reading Package Lists... Done
Building Dependency Tree... Done
The following packages will be REMOVED: bittornado python python2.3 python2.3-dev
0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
Remv pytris (0.96 Debian:testing)
Remv python (2.3.4-1 Debian:testing)
Remv python2.3-dev (2.3.4-5 Debian:testing)
Remv python2.3 (2.3.4-5 Debian:testing)
16_579495 ch09.qxd 12/27/04 10:09 PM Page 309
Chapter 9
✦
Running Debian GNU/Linux
309
In this example, several other packages depend on the python2.3 package and would also need to be removed. To proceed with removing python2.3 and all packages that depend on it, run the command again without the -s flag.
Note
As new versions of packages become available, you can instruct APT to download and install them, automatically replacing the older versions. This is as simple as updating your package list, followed by a simple command:
#
apt-get upgrade
When upgrading to a newer distribution, use dist-upgrade instead of upgrade
.
This will change the rules that APT uses when deciding which actions to take, making it expect major changes in dependencies and handle them appropriately.
As mentioned earlier, the dpkg utility is the primary package management tool in
Debian. Most other package management tools within the system, including APT, use dpkg to perform the midlevel work, and dpkg in turn uses dpkg-deb and dpkg-query to handle a number of the low-level functions.
Far too many dpkg commands exist to list in this section, but the most common ones are explained in the following sections. In most cases, there are both short and long commands to perform the same function. Use whichever is easier for you to remember.
Packages can be installed with dpkg using the -i or --install to the
.deb
flags and the path file containing the package. The path must be accessible as a file system path (HTTP, FTP, and other methods are not supported), and more than one package can be specified:
#
dpkg --install /home/wayne/lsof_4.71-1_i386.deb
Package removal through dpkg is also straightforward and is done with the -r
--remove commands. When configuration files are to be removed, the
-P or
-or purge command can be used instead. Both commands can also be used to specify multiple packages to remove:
#
dpkg --remove lsof
or...
#
dpkg --purge lsof
16_579495 ch09.qxd 12/27/04 10:09 PM Page 310
310
Part III ✦
Choosing and Installing a Linux Distribution
You will often need to obtain more information about packages that are already installed on your system. Because these operations do not modify the package database, they can be done as a non-root user.
To list all packages known to dpkg, use the -l or --list commands:
$
dpkg --list
Note
You can restrict the list by specifying a glob pattern:
$
dpkg --list “*lsof*”
The quotes are used to prevent the shell from replacing the wildcard with a list of matching files in the current directory. For more information about wildcards, see the glob man page.
To view detailed information about a specific package, use the -s command: or --status
$
dpkg --status lsof
Package: lsof
Status: install ok installed
Priority: standard
Section: utils
...
The origin package for a file can be determined using the -S command: or --search
$
dpkg --search /bin/ls
coreutils: /bin/ls
The list of files in an installed package can be viewed using the -L command: or --listfiles
$
dpkg --listfiles lsof
/.
/usr
/usr/sbin
/usr/bin
/usr/bin/lsof
...
Package files can be examined prior to installation using the --info ( -I ) and
--contents ( -c ) command:
16_579495 ch09.qxd 12/27/04 10:09 PM Page 311
Chapter 9
✦
Running Debian GNU/Linux
311
$
dpkg --info lsof_4.71-1_i386.deb
new debian package, version 2.0.
size 319058 bytes: control archive= 1534 bytes.
557 bytes, 16 lines control
2246 bytes, 32 lines md5sums
Package: lsof
Version: 4.71-1
...
$
dpkg --contents lsof_4.71-1_i386.deb
drwxr-xr-x root/root 0 2004-04-03 07:34:41 ./ drwxr-xr-x root/root 0 2004-04-03 07:34:36 ./usr/ drwxr-xr-x root/root 0 2004-04-03 07:34:39 ./usr/bin/
...
Caution
Some package sets are too large to be managed practically through meta packages, so tasks have been created as an alternative. Tasks are installed and removed using the tasksel utility. When run without any arguments, tasksel presents a menu from which you can select tasks to install or remove.
Do not install any tasks if you plan to use this system in conjunction with the server examples in Chapters 23 and 24.
Caution
Additional options are available from the command line:
✦
To see a list of known tasks, run tasksel --list-tasks
.
✦
To list the packages that are installed by a task, run tasksel --taskpackages <
task name
> .
When a task is removed, all programs associated with that task, whether installed manually or as part of that task, are removed!
To install the desktop task, which includes GNOME, KDE, and XFCE environments, run the following:
#
tasksel install desktop
In cases where there is more than one installed program that provides a specific function, package maintainers have the option of utilizing Debian’s alternatives system. The alternatives system manages which program is executed when you run a specific command. For instance, the ed, nano, and nvi packages each provide a text editor. An alternative maintained in the system guarantees that a text editor is accessible through the generic editor command, regardless of which combination of these packages is installed.
16_579495 ch09.qxd 12/27/04 10:09 PM Page 312
312
Part III ✦
Choosing and Installing a Linux Distribution
The system administrator can designate which program is referenced in the alternatives database, through the use of the update-alternatives command:
#
update-alternatives --config editor
These are alternatives that provide ‘editor’.
Selection Alternative
-----------------------------------------------
1 /bin/ed
*+ 2 /bin/nano
3 /usr/bin/nvi
Press enter to keep the default[*], or type selection number:
2
Note
You can also use the --all command with update-alternatives to configure every entry in the alternatives database, one at a time. You can find more details in the update-alternatives man page.
By default, all alternatives are in automatic mode, meaning that the system automatically selects a suitable program from the available candidates. Installing a new candidate program generally results in the automatic updating of the appropriate alternatives. Manually configuring an alternative disables automatic mode, preventing the system from changing these settings without prior knowledge of the system administrator.
The Debian package management tools also provide a mechanism for renaming specific files in a package and for overriding the ownership and permission settings on files. Unlike when these changes are made manually using mv
, chmod
, or chown
, changes made through the Debian tools remain in place across package upgrades and re-installations.
For example, if you wanted to replace
/usr/bin/users without modifying the coreutils package, you could divert it to /usr/bin/users.distrib
:
#
dpkg-divert --local --rename --add /usr/bin/users
Adding `local diversion of /usr/bin/users to
/usr/bin/users.distrib’
Removing the diversion returns the original filename:
# dpkg-divert --remove /usr/bin/users
Removing `local diversion of /usr/bin/users to
/usr/bin/users.distrib’
Stat overrides are useful when you want to disable access to a program, or when you want to make it set-UID. For instance, to disable access to the wall program:
# dpkg-statoverride --update --add root root 0000 /usr/bin/wall
16_579495 ch09.qxd 12/27/04 10:09 PM Page 313
Chapter 9
✦
Running Debian GNU/Linux
313
Note
This sets the owner and group of /usr/bin/wall permissions on the file.
to root and root and disables all
You can find more information about file permissions in the “Understanding File
Permissions” section of Chapter 2.
Unlike dpkg-divert , dpkg-statoverride does not keep track of the original file permissions. As a result, removing an override does not restore the old permissions.
After removing the override, you need to either set the permissions manually or reinstall the package that contained the file:
#
dpkg-statoverride --remove /usr/bin/wall
#
apt-get --reinstall install bsdutils
Reading Package Lists... Done
Building Dependency Tree... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
Need to get 0B/62.5kB of archives.
After unpacking 0B of additional disk space will be used.
Do you want to continue? [Y/n]
Y
(Reading database ... 16542 files and directories currently installed.)
Preparing to replace bsdutils 1:2.12-10 (using
.../bsdutils_1%3a2.12-10_i386.deb) ...
Unpacking replacement bsdutils ...
Setting up bsdutils (2.12-10) ...
All packages that include support for configuration management through debconf are configured as they are being installed. If you want to change a configuration option later, you can do so using the dpkg-reconfigure utility. For instance, you can change the configuration options for ssh using the following command:
#
dpkg-reconfigure ssh
Note
Every configuration parameter is assigned a priority by the package maintainer.
This allows debconf to select the default values for settings below a specific priority. By default, you will only be prompted to answer questions of medium, high, or critical priority; low-priority questions are answered automatically. You can change this by reconfiguring the debconf package:
#
dpkg-reconfigure debconf
Advanced users who are maintaining multiple systems may want to create a database of configuration settings that can be distributed to every computer (or to sets of computers) to reduce the number of repeated steps. This process is documented in the debconf and debconf.conf man pages.
16_579495 ch09.qxd 12/27/04 10:09 PM Page 314
314
Part III ✦
Choosing and Installing a Linux Distribution
The reliability of Debian GNU/Linux, combined with the large number of high-quality packages available for it, make Debian a great choice for both workstations and servers. The carefully executed releases and the capability to upgrade most software without rebooting serve to further increase its suitability as a server operating system.
APT is a primary tool for installing, removing, and upgrading packages. This chapter explored how to use the apt-get and apt-cache utilities for package management.
Also discussed were the installation of package sets (tasks) using the tasksel utility and managing package configuration with the dpkg-reconfigure utility.
✦ ✦ ✦
17_579495 ch10.qxd 12/27/04 10:08 PM Page 315
F
or the past few years, SUSE has been the most popular
Linux distribution in Europe. Since the U.S. networking company Novell, Inc. purchased SUSE in November 2003,
SUSE has been positioning itself to challenge Red Hat to become the dominant Linux distribution for large enterprise computing environments worldwide.
On the
DVD-ROM
The DVD that comes with this book contains the CD image of SUSE 9.2, disk 1. You can burn that image to CD as described in Appendix A and install it as described later in this chapter.
Like Red Hat Linux, SUSE is an excellent first Linux for people who prefer to work from a graphical desktop rather than from the command line. Likewise, Novell’s Linux product line is geared toward enterprise computing, so the skills you gain using SUSE will scale beyond your home Linux system.
SUSE has a slick graphical installer that leads you through installation and intuitive administrative tools, consolidated under a facility called YaST. SUSE and its parent company
Novell offer a range of Linux products and support plans that scale up to enterprise computing, as well as free, binary versions of SUSE that you can use with limited support.
This chapter describes the features and approach to Linux that set SUSE apart from other Linux distributions. It also explains how to install the SUSE 9.2 distribution that is included with this book.
✦ ✦ ✦ ✦
In This Chapter
Understanding SUSE
What’s in SUSE
Getting support for SUSE
Installing SUSE
✦ ✦ ✦ ✦
17_579495 ch10.qxd 12/27/04 10:08 PM Page 316
316
Part III ✦
Choosing and Installing a Linux Distribution
If you are looking for the stability and support required of a Linux system on which you can bet your business, SUSE offers impressive, stable Linux products backed by a company (Novell, Inc.) that has been selling enterprise solutions for a long time. SUSE’s product offerings range from personal desktop systems to enterprisequality servers.
SUSE began as a German version of Slackware in 1992, on 40 floppy disks, and was first officially released on CD (SUSE Linux 1.0) in 1994. Founded by Hubert Mantel,
Burchard Steinbild, Roland Dyroff, and Thomas Fehr, SUSE set out as a separate distribution from Slackware to enhance the software in the areas of installation and administration.
Although SUSE had success and respect with its Linux distribution, it was not profitable, and Novell’s $210 million offer for SUSE was seen as a good thing both for
SUSE and for Linux in general. SUSE was running short on cash, and Novell was looking for a way to regain its stature as a growth company in the enterprise and network computing arena.
In the 1980s and early 1990s, Novell was the world’s number-one computer networking company. Before the Internet took hold, Novell’s NetWare servers and
IPX/SPX protocols were the most popular ways of connecting PCs together on
LANs. International training, support, and sales teams brought Novell products to businesses and organizations around the world.
Despite Novell’s huge lead in the network computing market, file and printer sharing features in Windows and late entry into the TCP/IP (Internet) arena caused Novell to lose its market dominance in the 1990s. Although its NetWare products contained excellent features for directory services and managing network resources, Novell didn’t have end-to-end computing solutions. NetWare relied on Windows for client computers and lacked high-end server products.
Novell’s association with the UNIX operating system in the early 1990s makes an interesting footnote in the history of Linux. Novell purchased UNIX System V source code from AT&T and set out to make its resulting UnixWare product (a UNIX desktop product for x86 processors) a competitor to Microsoft’s growing dominance on the desktop. The effort was half-hearted, and Novell soon gave the UNIX trademark to the Open Group and sold the UNIX source code to SCO.
Novell’s purchase of SUSE marks its second major attempt to fill in its product line with a UNIX-like desktop and server product. From the early returns, it appears that
Novell is doing a better job with Linux than it did with UNIX.
17_579495 ch10.qxd 12/27/04 10:08 PM Page 317
Chapter 10
✦
Running SUSE Linux
317
Unlike distributions geared toward more technical users, such as Gentoo and
Slackware, you can configure and launch most major features of SUSE by selecting menus on the desktop. New Linux users should find SUSE to be very comfortable for daily use and basic administration.
Like Red Hat Enterprise Linux, SUSE is made to have a more cohesive look-and-feel than most Linux distributions that are geared toward Linux enthusiasts. In other words, you aren’t required to put together a lot of SUSE by hand just to get it working. Although there are personal editions of SUSE that are fine for home users, SUSE is ultimately aimed more toward enterprise computing.
Let’s explore what SUSE Linux offers you.
A set of modules that can be used for configuring your SUSE system is gathered together under the YaST facility. Because many of the features needed in a Linux installer are also needed to configure a running system (network, security, software, and other setup features), YaST does double duty as an installer and an administrative tool.
YaST (which stands for Yet Another Setup Tool) was, until recently, proprietary code that was not available as open source. However, to gain wider acceptance for
YaST among major computing clients as a framework for managing a range of computing services, Novell released YaST under the GNU Public License in March 2004.
YaST makes obvious what you need to do to install Linux. Hardware detection is done before your eyes. You can set up your disk partitions graphically (no need to remember options to the fdisk command). Setting up the GRUB boot loader is done for you, with the option to modify it yourself.
One of the nice features of YaST installation is that you can scan the configuration process without stepping through every feature. If you scan through the mouse, keyboard, installation mode, partitioning, and other information and they look okay, you can click Accept and just keep going. Or you can change any of those settings you choose. (The “Installing SUSE” section later in this chapter details the installation process with YaST.)
Because YaST offers both graphical (QT) and text-based (ncurses) interfaces, you can use YaST as a configuration tool from the desktop or the shell. To start YaST from the desktop, click the SUSE button on the desktop panel and select System
➪
YaST. Figure 10-1 shows what the graphical version of the YaST utility looks like.
17_579495 ch10.qxd 12/27/04 10:08 PM Page 318
318
Part III ✦
Choosing and Installing a Linux Distribution
Figure 10-1:
Configure common Linux features using the YaST utility.
Launching the YaST utility actually involves running the /sbin/yast2 command.
When you run
/sbin/yast2
, YaST starts in text mode by default. (An alternative is to run kdesu /sbin/yast2 from a Terminal window, which starts YaST in graphical mode.) Figure 10-2 shows what YaST looks like when started in text mode from a
Terminal window.
Figure 10-2:
Use the arrow and Tab keys to navigate
YaST in text mode.
17_579495 ch10.qxd 12/27/04 10:08 PM Page 319
Chapter 10
✦
Running SUSE Linux
319
YaST offers you some intuitive tools for configuring your system and comes preconfigured, so you start with a nice set of defaults. YaST also does a good job detecting your hardware, finding partitions, and the like, so a new user can often just accept the settings YaST chooses. Here are some examples of what YaST does for you:
✦
You don’t have to check through
/etc configuration files or run lsmod to see how your hardware has been configured in SUSE. From the
Hardware section, you can select icons representing your CD drives, graphics cards, printers, joysticks, scanners, sound cards, and mice. Click the Hardware information icon to see your full list of detected hardware.
✦
Like Red Hat Linux, SUSE stores much of the information it uses to configure services at boot time in files in the /etc/ sysconfig directory. The information in those files is in the form VARIABLE=
”VALUE” .
Under the YaST System icon, you can select the sysconfig Editor, which lets you select each file, and then view and possibly change each variable so that you don’t have to guess what variables are available for each configuration.
For more advanced system administrators, this is a great way to fine-tune the startup services for your system.
SUSE also includes a System Configuration Profile Management (SCPM) applet, which lets you store and manage a collection of system settings so it can be used again later.
✦
YaST detects your dial-up modem, Ethernet card,
DSL modem, or ISDN hardware, and gives you the opportunity to configure each piece of hardware. SUSE also does a much better job than most distributions at getting Winmodems working in Linux, which is particularly useful for using dial-up features on laptops that have cheap, built-in modems.
✦
With a connection to your LAN or WAN, YaST provides some helpful graphical tools for configuring some services that can be unintuitive to do from the command line.
✦
Security settings in Linux are often among the most unintuitive features to configure, while at the same time being among the most important. Although features such as iptables work great for most
Linux gurus for setting up a firewall, people who are accustomed to graphical interfaces may find them challenging.
From the YaST Security and Users selection, the Firewall icon enables you to step through your network interfaces and add access to those services you want by name (such as Web Server, Mail Server, and Other Services) or by port number. It even enables you to do initial setup of more complex firewall features, such as packet forwarding, IP Masquerading, and logging.
17_579495 ch10.qxd 12/27/04 10:08 PM Page 320
320
Part III ✦
Choosing and Installing a Linux Distribution
To make your way around the graphical YaST interface, you only need to click the mouse and use the Tab key to move between fields. For the text-based YaST interface, you can use the Tab and arrow keys to move among the selections and the
Enter key to select the currently highlighted item.
Like Red Hat Linux, SUSE packages its software using the RPM package management file format and related tools. RPM contains a lot of features for adding, removing, and managing software in SUSE. Although software packages in the Red Hat and
SUSE distributions are different, the tools you use for managing packages in those two distributions are the same.
You use the rpm its features: utility to work with RPM software packages. Here’s a list of some of
✦
You can use the rpm command to add a software package to SUSE, and it doesn’t care if the package is in the local directory, CD, or remote computer (providing you have network access to that computer). A remote package can be available on a Web server ( http:// ) or
FTP server ( ftp://
). Here’s an example of using an rpm command to install a software package from an FTP server:
#
rpm -iv ftp://ftp.linuxtoys.net/pub/suse/9.1/abc.i586.rpm
In this example, the -i option says to install the package, and the -v option says to give verbose output as the package is installed. The fictitious package
( abc.i586.rpm
) is installed from an FTP repository. If there are dependency or access issues, rpm informs you and fails. Otherwise, the package is installed.
(The -U
-U option is often used instead of the -i option to install RPMs because succeeds even if the package is already installed. The
-U says to upgrade the package.)
✦
One of the best features of the RPM facility is that you can find out a lot of information about the software packages that are installed. The query option ( -q ) lets you list package names, descriptions, and contents in various ways. Here are a few examples:
#
rpm -qa xmms
#
rpm -ql xmms | less
#
rpm -qi xmms | less
The first example ( -qa ) searches for the xmms package and reports the current version of the package that is installed. In the second, -ql the xmms package and then pipes that output to the less lists all files in command to page through it. And finally, the xmms package.
-qi displays a description and other information about
✦
age. The
-V
Use rpm to verify the contents of an RPM packoption enables you to check whether any of the files in a package have been tampered with. Here is an example:
17_579495 ch10.qxd 12/27/04 10:08 PM Page 321
Chapter 10
✦
Running SUSE Linux
321
#
rpm -V aaa_base
..5....T c /etc/inittab
S.5....T /etc/profile.d/alias.ash
-V checks whether any of the contents of the aaa_base package (which contains some basic system configuration files) has been modified. The output shows that the inittab and alias.ash
files have been modified from the originals. The 5 indicates that the md5sum of the files differ, while the T indicates that the time stamp on the file differs. On the alias.ash
file, the S shows that the size of the file is different.
The rpm command has many other options as well. To find out more about them, type
from any shell.
As of version 7.1, SUSE Linux includes an automatic update agent. The YaST Online
Update (YOU) utility is built right into the YaST facility and offers an easy way to get updates, security patches, and bug fixes for SUSE by downloading and installing them from software repositories over the network.
From within YaST, select YOU. YaST shows you the location of mirror sites and then enables you to begin retrieving software updates with a single click. It presents you with a list of patches from which you can choose. Security patches are in red, all recommended patches are selected, and optional patches are shown (unselected).
It’s easy to see all available patches and read their descriptions to determine if you want them.
After you have selected the updates you want and clicked OK, you can watch the progress as each patch and updated package is downloaded and installed. Having security-related patches and other fixes separated and being able to read all about each software update and patch right on the YaST window before you start downloading are features that set YOU apart from methods of doing upgrades from other
Linux distributions.
SUSE has an excellent support database and full-time support staff. You can search many of the articles on the site for free and check out the FAQs. Paid support options are available as well.
The SUSE Linux Portal ( http://portal.suse.com
) is the place to search for answers about using SUSE. To try the free search engine at the site, just select
Search. You don’t need a user account to search articles related to the SUSE Linux personal or professional editions, although you do need one to search articles related to Linux business products from SUSE.
17_579495 ch10.qxd 12/27/04 10:08 PM Page 322
322
Part III ✦
Choosing and Installing a Linux Distribution
Note
To get an account, select the Sign Up Here link from the SUSE Linux Portal page. If you have purchased your SUSE distribution, you can use that account to register your SUSE product. Having a registered SUSE product lets you use your account to get free installation information and other support services.
At the time of this writing, SUSE was offering a free 30-day evaluation for SUSE
Linux Enterprise Server if you wanted to download it. That evaluation included installation support and upgrade protection. Check the Novell ( www.novell.com
) and SUSE ( www.suse.com
) Web sites to see if any evaluation specials are available at the moment.
The SUSE installation procedure described here is for the SUSE Linux Personal-CD edition. This edition is available free of charge. Functionally, it is almost exactly the same as the boxed set version that SUSE sells, with only a few items removed that are not covered under a license in which they can be redistributed.
Note
The DVD that comes with this book includes the first CD in the SUSE Linux Personal-
CD edition that you can copy and use. If you want to download the latest Personal-CD yourself, go to the SUSE download page ( www.suse.com/us/private/download/ index.html
). In either case, you will have to burn the CD image to a CD yourself.
(See Appendix A for information on how to do that.)
If you like SUSE and want a commercial version, select the Online Store link at the
SUSE.com site. You can purchase a boxed set of the Personal edition, which includes installation support and hardcopy documentation, or you can choose one of the other editions, such as the SUSE Linux Professional or SUSE Linux Enterprise Server editions, which also include support and documentation.
The installation description in this chapter covers installs on Intel x86 PCs. If you have AMD 64-bit or Intel Extended Memory 64 Technology systems, you need to purchase the SUSE Linux Professional boxed set, which includes installation media for both of those types of hardware.
To install SUSE, you need at least 96MB of main memory. The entire SUSE Personal-
CD installation requires about 1.8GB of disk space, although you can get by with less by deselecting packages during installation. Installation should work on any
Pentium-class x86 PC.
The description here tells how to install by booting the installation CD and installing the software from that medium. If you don’t have a bootable CD, you can create a boot floppy from the floppy image on the CD. To see available boot images and descriptions of how to create boot floppies, refer to the README file in the /boot directory on the SUSE installation CD.
17_579495 ch10.qxd 12/27/04 10:08 PM Page 323
Chapter 10
✦
Running SUSE Linux
323
Although you need a boot CD or floppy disk to begin the installation, the actual software you are installing can reside in other locations. If you have a network card installed on your computer, SUSE software can be gathered from the following types of locations:
✦
— From the installation boot prompt, identify the location of the directory on an FTP server that contains the contents of the SUSE packages. For example, to install from the
/install directory from the FTP server at 10.0.0.1, type the following at the boot prompt:
install=ftp://10.0.0.1/install
✦
— To use a Web (http) server instead of an FTP server, you would type the following:
install=http://10.0.0.1/install
✦
— To use an NFS server instead of an FTP server, you would type the following:
install=nfs://10.0.0.1/install
Other installation media that are supported include hard disk (with the SUSE software installed on a different hard disk or partition on the local computer) and Samba
(where the software is on an SMB share from a Windows or other Linux system).
Note
Here are the steps for installing the SUSE Linux Personal-CD edition on your hard disk:
Reboot the computer. The SUSE installation boot screen appears.
Because this install is from the local CD, highlight Installation and press Enter. The YaST screen appears to begin installation.
Sometimes installation can fail because the computer hardware doesn’t support certain features, such as power management (ACPI or APM) or DMA on hard drives or removable media. For those cases, you can try starting installation by selecting
ACPI Disabled (which turns off ACPI) or Safe Settings (which turns off ACPI and APM as well as turning off DMA for any IDE CD, DVD, or hard drives).
Select your language and click Accept. Installation Settings appear.
The next few steps let you view and (optionally) change the installation settings
SUSE recommends.
Select System to view information about the computer hardware that
SUSE detected. You can select Save to File to have that information saved to a file on your hard disk. Click OK to return to Installation Settings.
New Installation is the only mode available with the Personal Edition.
17_579495 ch10.qxd 12/27/04 10:08 PM Page 324
324
Part III ✦
Choosing and Installing a Linux Distribution
Select the language/country associated with the keyboard you are using.
If your mouse was not detected properly, select Mouse and change it to one of the mouse/connection types that appear. SUSE supports USB, serial,
PS/2, and bus mouse connections. A variety of two-button, three-button, and wheel mice are supported.
Partitioning is very important, especially if you want to protect any data currently on your hard disk. Select Partitioning. SUSE recommends a partitioning scheme. (If your disk is already partitioned, SUSE tries to use that scheme.) You can simply accept that scheme (choose Accept Proposal As-Is and click Next) or elect to create a custom partition setup.
The Expert partitioning selection enables you to use a partitioning interface that is very similar to Disk Druid. See the description of partitioning in
Chapter 7 for information on partitioning your hard disk. If you ever plan to move your partitions around with a tool such as Partition Magic, you should assign your Linux partition to ext3 file system type. (If you are an expert and want to use the fdisk command described there, press Ctrl+Alt+F2 to get to a shell, run fdisk, and then press Ctrl+Alt+F7 to return to the graphical installer.)
Select Software to see a list of packages available to install on your hard disk. Most of the packages in the Personal Edition are desktop-oriented.
Package selections fall under these headings:
•
— X Window System, window managers, graphics libraries, and so on.
•
— The KDE desktop and related applications.
•
— The SUSE help system and related tools.
•
— Office productivity tools, including wine for running MS Windows applications.
Check boxes indicate which packages you want to install. It’s a good idea to look through this list to see what you are getting. If you change any of the selections, click the Check Dependencies box to make sure that all packages other packages depend on are being installed. Figure 10-3 shows the YaST module for adding, removing, and finding out about software packages.
The YaST software packages module used during installation is the same one used on a running SUSE system (in Figure 10-3, it’s shown on a running SUSE system). In either case, you can find out a lot of information about packages that interest you. With a package selected, click tabs in the box at the bottomright corner of the screen to see its description, technical data (its size, packager, etc.), dependencies, and version numbers.
Select Booting to see the information that is added to your boot loader
(GRUB, by default, but you can use the LILO boot loader as well). The boot loader includes the information needed to boot Linux: the location of the boot loader, default operating system to boot, and other information.
17_579495 ch10.qxd 12/27/04 10:08 PM Page 325
Chapter 10
✦
Running SUSE Linux
325
Figure 10-3:
Install and remove software using the YaST software module.
Caution
If you are sharing your hard disk with other operating systems (such as Windows or another version of Linux), consider putting your boot loader on floppy disk. In that way, you can test out the boot loader without actually changing the permanent master boot record on your hard disk. If the boot loader doesn’t work, simply remove the floppy disk to reboot the original way.
Select the time zone in which you’re located.
Select the default language to use. (You can add support for other languages later, if you like.)
Normally you’d use the default (5) to boot to a full multiuser, networked desktop system with a graphical login screen. The other common default is 3, which provides a text-based login screen but is otherwise the same. (If you choose 3, you can start the GUI after login by typing the startx command.)
If the Installation settings all look okay, click Accept to begin the install process. Remember that this is your last chance to back out! When the green warning box appears, click No to abort the install process or Yes,
Install to start the installation.
If you click Yes, SUSE formats your hard disk and installs the selected packages. After installation finishes, SUSE reboots. (You can remove the CD or not, as you choose. SUSE will, by default, boot to hard disk even with the CD in.)
17_579495 ch10.qxd 12/27/04 10:08 PM Page 326
326
Part III ✦
Choosing and Installing a Linux Distribution
Although SUSE is now installed, the first time SUSE boots from hard disk you are immediately presented with a screen that asks you to do some basic configuration. With the YaST root password screen in front of you, continue to the next step.
Enter the root password (twice). Enter up to eight characters.
DES is the default encryption type used to protect your password. (You can select Expert Options to choose MD5 or Blowfish instead.) Refer to Chapter 6 for suggestions on choosing a good password.
YaST probes to find any network cards, DSL connections, ISDN adapters, or modems connected to your computer. Select any of those items that appear on the screen, as appropriate, to configure it.
After you are done, click Next. SUSE sets up and lets you test your network connections.
Normally, you will use your home computer in standalone mode, as it relates to user accounts. However, in a business setting, you may use NIS or LDAP to get user account lists that allow access to yours and other computers on your LAN. If the latter is the case, select Network
Client and choose either NIS (a common facility used by UNIX systems to share configuration files) or LDAP (a standard directory service, used to share address books and other kinds of information on a network), depending on what your company supports. Then click Next.
You will want to add at least one user account, as prompted, for your computer. Right now, you only have the root user account set up for use on a standalone machine. Using that account for e-mail, Web browsing, or other common tasks is considered bad security practice. So you should add at least one user account for nonadministrative use of your computer. Add your full name, a short, one-word login name, and a password to protect that account. Then click Next.
When you are done, YaST writes the system configuration information to your computer. It then displays the Release Notes for your current version of SUSE.
Click Next to continue.
You now have the opportunity to configure other hardware devices to use with your system. Select to configure your graphics card, printer, sound card, or TV card. After graphics configuration, you should test your display as prompted. If the settings you choose don’t work, select
Ctrl+Alt+Backspace to exit and try to configure it again.
When you are done configuring hardware, click Accept. The settings are written to hard disk. An Installation Completed screen appears.
Click Finish. The system reboots and is ready for you to log in.
17_579495 ch10.qxd 12/27/04 10:08 PM Page 327
Chapter 10
✦
Running SUSE Linux
327
If you created a user account during the preceding installation, SUSE should automatically log you in as that user and present you with the KDE desktop. (If you are presented with a graphical login screen instead, log in as that user now.) Here are a few things to help you get started using SUSE:
✦
— The desktop edition of SUSE described here includes a set of easily accessible desktop applications. On the desktop, try the
Office icon to open OpenOffice.org to work with documents, spreadsheets, presentations, drawings, Web pages, or a variety of other content types.
From the SUSE icon on the panel, select from among dozens of applications to try out.
✦
— A desktop icon takes you right to the SUSE Linux Portal (provided you have an Internet connection). You can search the support database for keywords relating to SUSE problems or read the FAQs without having an account. Sign up for a support account to get more benefits. Benefits include the capability to make support requests and get automatic patch support.
For additional support options, visit support.novell.com/linux .
✦
— A Network Browsing icon on the desktop enables you to immediately begin browsing your LAN for Windows shared files (using Samba and SMB). On the panel, click the Web browser icon to open Mozilla Navigator or the e-mail icon to open Evolution e-mail client. SUSE also includes clients for online chat and Usenet news.
✦
— Get to the YaST administration tool by selecting
System
➪
YaST from the SUSE menu. You can reconfigure your system hardware and software from the YaST Control Center.
If you want to configure your desktop (change backgrounds, screensavers, or themes), use the KDE control center as you would with any KDE desktop. You can launch the control center from the SUSE menu (select Control Center).
SUSE is generally considered to be the best choice for enterprise-quality Linux systems, along with Red Hat Enterprise Linux. Its graphical installation and administrative tools (implemented in a facility called YaST) set it apart from other Linux distributions that are geared more toward technical users.
17_579495 ch10.qxd 12/27/04 10:08 PM Page 328
328
Part III ✦
Choosing and Installing a Linux Distribution
Since SUSE was acquired by Novell in 2003, SUSE Linux has become part of a larger, enterprise-ready product line. Boxed sets of SUSE are available in Personal,
Professional, and Enterprise versions. Support offerings are available at many different levels. With Novell’s worldwide sales and training organization, SUSE Linux has the backing it needs to compete to become the world’s most popular commercial Linux system.
Because so much work has gone into the YaST installer and administrative interface, even an inexperienced user can be up and running on a newly installed SUSE system within an hour. Afterward, it’s easy to begin using a variety of desktop and personal productivity applications from the SUSE desktop.
✦ ✦ ✦
18_579495 ch11.qxd 12/27/04 10:09 PM Page 329
A
computer’s operating system usually resides on the hard disk — but it doesn’t have to. When a computer boots up, it typically checks first if there is a CD, floppy disk, or DVD in a drive and tries to boot from there (depending on
BIOS settings). So, with up to 700MB (CD) or 4.7GB (DVD) of space on those media, why not use them to boot whole operating systems?
Well, that’s exactly what bootable Linux distributions (also called live CDs) such as KNOPPIX do. In the case of KNOPPIX, one CD holds up to 2GB of compressed software for you to run that uncompresses on-the-fly. Start it up and you can try out all the features of a well-stocked Linux system, without touching the contents of your hard disk.
On the
DVD-ROM
KNOPPIX is included on the DVD that comes with this book.
In fact, it is the default option. Insert the DVD into your PC’s
DVD drive and, when you see the boot screen, press Enter.
KNOPPIX should just start up, and you can begin using it as described in this chapter.
If you have never used Linux before, KNOPPIX gives you the chance to do so in a very safe way. If you are experienced with
Linux, KNOPPIX can be used as a tool to take Linux with you everywhere, troubleshoot a computer, or check if a computer will run Linux. In any case, you can use this chapter to take a little tour of some great Linux features you can try out with
KNOPPIX.
If you are impatient, you don’t have to read any further. In most cases, you can just insert your DVD into your PC, reboot the computer, and start using KNOPPIX. However, if you have the time, read on a bit more.
✦ ✦ ✦ ✦
In This Chapter
Understanding
KNOPPIX
Starting KNOPPIX
Using KNOPPIX
✦ ✦ ✦ ✦
18_579495 ch11.qxd 12/27/04 10:09 PM Page 330
330
Part III ✦
Choosing and Installing a Linux Distribution
Created by Klaus Knopper, KNOPPIX is a bootable Linux that includes a nice selection of open source software. Although it can also be delivered on DVD (as we did with this book) or other bootable media, the distribution is made to fit on a single, bootable CD. KNOPPIX is often considered to be the best bootable Linux available.
Note
Note
KNOPPIX boots right up to a full-featured desktop system complete with hundreds of desktop applications. It includes some powerful server and power user features.
In fact, there are so many features, I won’t even try to mention them all here, but just take a look at the following list of some of KNOPPIX’s major components:
If you find that you are missing the NVIDIA graphics driver, Flash plug-in, or Quanta
HTML editor you need, don’t worry. KNOPPIX includes a KNOPPIX-Live Installer that lets you install selected software features from the network and run them live from
KNOPPIX. I’ll describe the KNOPPIX-Live Installer later in this chapter.
✦
— A full-featured KDE desktop (which runs on the X Window System) that includes tools for configuring the desktop and a bunch of applications tailored for the KDE environment. (See Chapter 3 for descriptions of KDE.)
If you prefer the GNOME desktop environment, there are several customized versions of KNOPPIX that include GNOME. Most notable is the Gnoppix ( www.gnoppix.org
) distribution, which uses GNOME as its default desktop.
✦
— The OpenOffice.org suite of office productivity tools so that you can create documents, graphics, presentations, spreadsheets, and most anything you expect to be able to do with office applications. With KNOPPIX,
I can give a presentation created in OpenOffice.org software anywhere that I have access to a PC. (See Chapter 20 for descriptions of OpenOffice.org productivity applications.)
✦
— Web browsers (Mozilla browser, Konqueror, and Lynx), e-mail clients (Kmail, Mozilla mail, and mutt), a chat client (XChat IRC), a news reader
(KNode), an instant messaging client (Gaim), and many more applications for using the Internet. (See Chapter 21 for descriptions of popular Web browsers and mail clients.)
✦
— Applications for playing music (xmms and KsCD), editing music (Audacity and Rosegarden), watching TV (xawtv), playing movies
(xine), working with graphics (GIMP and xscanimage), using Webcams (gqcam), and displaying images (KView and Kuickshow). (Chapter 19 covers music and video players.)
✦
— A few dozen diverting board games, card games, strategy games, and puzzles to play. Try Potato Guy to keep the young ones busy, and Kasteroids for the older kids. (Chapter 22 talks about KDE and other games that you can run with KNOPPIX.)
18_579495 ch11.qxd 12/27/04 10:09 PM Page 331
Chapter 11
✦
Running KNOPPIX
331
Note
✦
— A nice set of system and network administration tools that enables you to do some pretty advanced setup, monitoring, and debugging of your computer and network. (The Knoppix-STD distribution is configured specifically as a rescue CD to do almost anything you could imagine to check and fix your computer and network.)
✦
— A few of the powerful server projects available for Linux, many of which don’t require a lot of disk space: a Web server (Apache), FTP server
(FTPd), file server (NFS), Window file/print server (Samba), proxy server
(Squid), DNS server (bind9), login server (sshd), and DHCP server (dhcpd).
Using KNOPPIX (or any other bootable server Linux systems described in Chapter 18) as a server opens some amazing possibilities for serving the data from a Windows or other operating system to a network, while completely bypassing that operating system on the computer’s hard disk.
✦
— A good set of tools for developing software across a variety of programming environments.
Note
KNOPPIX is based on Debian Linux, so a Debian user will be particularly comfortable with the selection and organization of features. KNOPPIX software packages are also done in deb package format, so you can use apt, dpkg, and related tools to list and otherwise manage the packages.
Refer to Chapter 9 for information on using apt and dpkg tools for managing software in Debian. Even if you don’t install any new software, those tools provide an excellent way to search, list, or even upgrade software packages that are running in KNOPPIX.
The features just described are ones that come with many different Linux distributions. What makes them special with KNOPPIX is that you can often be up and using those features within a few minutes — without having to repartition your disk, install software, or do any configuration. For just trying out Linux or using it for some special, quick task you want to do, KNOPPIX is quite awesome.
Some features, however, are specific to KNOPPIX (as compared to a Linux system you would run from a hard disk). Many of those special features are there to help you through issues that relate to the fact that you are not working in a permanent setup. In particular, KNOPPIX includes the following:
✦
— The capability to properly detect and configure hardware is one of the best features. During the boot-up procedure,
KNOPPIX finds most common PC hardware components and loads the proper modules so it can use them. Its hwsetup tool relies on the Red Hat libkudzu facility to identify hardware, load appropriate modules, and create necessary device files.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 332
332
Part III ✦
Choosing and Installing a Linux Distribution
For hardware that can’t be detected, there are many boot options you can add to properly identify (or skip over) selected hardware devices. Some of them deal with particularly sticky issues related to video cards and running on laptop computers. (See Tables 11-1 through 11-3.)
✦
— Instead of just dropping you to a command line,
KNOPPIX does its best to start up a complete KDE desktop environment. Along the way, it adds some nice features, such as desktop icons giving you access to your computer’s hard disk partitions.
✦
— Some hardware either can’t be perfectly detected or requires some extra setup. You can access KNOPPIX-specific configuration tools for configuring your printer, TV card, sound card, network connections, and other features by clicking the desktop icon that looks like a squished penguin.
✦
— You don’t have to lose the configuration you have done for
KNOPPIX every time you reboot. Click the configuration icon to save your configuration — including your personal desktop configuration, files on the desktop, network settings, and graphics setup (X) — to floppy disk.
✦
— You also can use the configuration icon to create a persistent KNOPPIX home directory on your hard disk or other medium so that you can store and reuse your desktop setup information and any data you save from session to session. (See the “Creating a Persistent Home Directory” section later in this chapter for details on setting up a persistent desktop.)
✦
— If you are using KNOPPIX from a computer with Linux installed, it automatically uses a swap partition that is set up there. On DOS and Windows systems, KNOPPIX enables you to create an extra swap area if you have space on an available DOS partition. (The mkdosswapfile command is used for this purpose.)
✦
— KNOPPIX cannot include Microsoft Windows drivers for using Windows file systems (NTFS), but it provides a utility that enables you to install those drivers (providing you have legal rights to use them). The drivers enable you to safely read and write files from your hard disk if you are booting KNOPPIX from a PC with Windows installed.
For example, say that you have your entire music collection, images downloaded from your digital camera, and personal Web pages on your hard disk on a computer that was set up to be booted by Microsoft Windows XP. You boot KNOPPIX instead (notice that Microsoft Windows is not running at all).
Suddenly your hard disk is just a place that holds a lot of files. You can now use applications that come with KNOPPIX to open the files on your hard disk to play the music, view or manipulate images, and display or change Web pages.
A testament to how well KNOPPIX is respected is how many other bootable Linux distributions are based on it. The KNOPPIX project even provides a KNOPPIX-customize package that lets anyone make his own customized KNOPPIX. There are specialized
KNOPPIX derivatives that can be used to rescue a broken computer, play a range of multimedia content, or run a specific application.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 333
Chapter 11
✦
Running KNOPPIX
333
Cross-
Reference
See Chapter 17 for information on using a bootable Linux as a firewall/router and
Chapter 18 for descriptions of many other bootable Linux distributions.
Note
For most people, KNOPPIX is a special-use Linux system. It’s a great way to try Linux or to access a computer that isn’t set up the way you like. However, there are a few challenges with using KNOPPIX that you should keep in mind:
✦
— Unless you save your data to some other media
(which you can do, as I describe later in this chapter), the entire KNOPPIX system goes away when you reboot. That means files on the desktop, installed software, system configuration, and anything else you do during your KNOPPIX session will be gone unless you explicitly save that information to a hard disk or some removable medium (floppy, CD, and so on).
✦
— KNOPPIX is made to be able to run without touching your hard disk, so when you save files to KNOPPIX, they are (by default) stored in your computer’s memory (RAM). On my desktop system, which has 512MB of RAM, KNOPPIX assigned about 3MB to the root ( / ) partition and 396MB to ramdisk (to provide space in the /var and /home directories, where data is normally stored). So there is only about 100MB left to hold all the running applications.
✦
— Even with today’s faster CD and DVD drives, it’s still slower getting data from CDs and DVDs than it is getting them from a local hard disk. Almost every component needed to run KNOPPIX (commands, libraries, and so on) is grabbed from the CD or DVD and decompressed onthe-fly. So it can take a bit longer to run commands with KNOPPIX than it would to run them from hard disk. (Watch the blinking light on your CD or
DVD drive to see how often KNOPPIX goes there to get data.)
✦
— Because KNOPPIX relies so heavily on data from the CD or DVD, you can’t remove it while you are using the system. So, if you have only one drive for removable media, you can’t use it to access a music
CD, install from another software disk, or burn data while you are using
KNOPPIX.
Tiny multimedia players such as GeeXboX and MoviX can run totally from memory because they have very limited, specific functions. So you can put in a music CD or video CD or DVD to play content after the bootable Linux is loaded.
I must admit that the challenges described here are more of an explanation of how
KNOPPIX works than they are problems with KNOPPIX itself. The idea that you can run a full-blown desktop and server operating system from a single CD (with nearly
2GB of available applications) is an awesome concept for someone who still remembers DOS and character terminals.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 334
334
Part III ✦
Choosing and Installing a Linux Distribution
KNOPPIX was created by Klaus Knopper in Germany. Knopper follows in the great tradition of naming a distribution using a part of the creator’s own name with “ix” or “ux” stuck on the end.
While a groundswell of interest and support has appeared for KNOPPIX in the past year or so, Knopper himself thinks of KNOPPIX more as a collection of tools he needs than as a full Linux distribution. Knopper works to provide only software that can be distributed freely, for both noncommercial and commercial use. So he doesn’t even include some free software (such as browser plug-ins) that might restrict free redistribution, although he doesn’t object to including non–open source software that can still be freely distributed.
There is no big company behind KNOPPIX, and development efforts continue to be headed up by Knopper himself. There are, however, many people who contribute bug reports and enhancements requests (see www.knoppix.net/bugs ), and there are other developers who have helped create software specifically for KNOPPIX
(in particular, Fabian Franz who, among other things, has contributed significant work to KNOPPIX installer-related features).
The only official KNOPPIX Web site is Knopper’s own personal site: www.knopper.
net/knoppix . The closest thing to an official community is a mailing list ( mailman.
linuxtag.org/mailman/listinfo/debian-knoppix ) set up at LinuxTag.org with
Knopper’s blessing. LinuxTag hosts the LinuxTag Conference and Expo, which is a leading Linux and free software conference in Europe. For the 2004 conference,
LinuxTag produced a special edition of KNOPPIX on DVD that held more than 5GB of software.
If you are looking for a way to get information and become involved with others who use and develop the system, the Knoppix.net site offers a very active forum and links to information about other KNOPPIX resources. It’s a great place not only to get your questions answered, but also to find a wealth of links to FAQs, HOWTOs, and related projects. There is also an IRC channel (#knoppix on irc.freenode.net
) and a Wiki used primarily to gather documentation ( www.knoppix.net/docs/ ).
If you are considering creating your own customized distribution, tools for that purpose are currently under development and may be included with versions of
KNOPPIX by the time you read this text. In the meantime, you can check out some remaster tools at http://debian.tu-bs.de/knoppix/remaster/ . You can find out about versions that have already been created from the KNOPPIX Customizations page: www.knoppix.net/docs/index.php/KnoppixCustomizations .
Because there is so much you can do with KNOPPIX, it’s hard to narrow my mind enough to give a few specific examples. So, let’s start with a few concepts to help think about what you can do with KNOPPIX:
18_579495 ch11.qxd 12/27/04 10:09 PM Page 335
Chapter 11
✦
Running KNOPPIX
335
✦
— You don’t have to carry around a laptop or whole PC to make sure you have the software you need. Instead, you can use any PC that is available (with the exception of some unsupported hardware) and boot your whole computing environment with a single CD or floppy. By customizing your own KNOPPIX, you can add your own data and pick and choose applications as well.
✦
— You can bypass the operating system and other software on any computer and use the applications on your KNOPPIX disk to manage the data on that computer.
Of course, these concepts are not exclusive to KNOPPIX because you could conceptually do the same thing with any boot floppy since the days of DOS (as well as any other bootable Linux). The difference is that KNOPPIX does those things so well. It lets you take over a computer, not just with a tiny rescue disk capable of running a few obtuse commands, but with at full-scale desktop, server, and administrative tool kit operating system. With that in mind, here are some ways people are using
KNOPPIX:
✦
— A demo can lack some punch when you have to spend an hour installing before you can make your point. With KNOPPIX, it can take about five minutes from the time you tell your friend about Linux to the time you have a complete desktop system running on his PC. And in the process, you don’t have to worry about harming anything on his computer because you don’t even need to touch his hard disk.
✦
— Instead of getting halfway through an install to see if your PC is capable of running Linux, you can boot KNOPPIX. If it works, you can check to see what drivers were loaded to deal with your hardware
(type
from a shell) and then go ahead and install any Linux you like to the hard disk.
✦
— Many tools for tracking down and fixing problems on both Linux and Windows systems are included in KNOPPIX. There is also a Knoppix-STD edition that includes dozens more tools for rescuing broken systems and tracing network problems (see www.knoppix-std.org
).
✦
— If a Web server, file server, or firewall has been hacked or otherwise broken, you might be able to use KNOPPIX to safely server the data from a KNOPPIX boot disk while you fix the problem.
✦
— For those of us who have gotten used to using
Linux, it’s a pain to go somewhere and have to do work or make a presentation on a computer that doesn’t have the tools you need. By bringing the whole operating system, all your software tools and sometimes even your data (with a customized CD, separate floppy, or downloaded files), your computing environment can be the same wherever you go.
Now that you have some idea of what to do with KNOPPIX, let’s get started.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 336
336
Part III ✦
Choosing and Installing a Linux Distribution
It’s supposed to be easy to start KNOPPIX. With KNOPPIX in hand, all you really need is a PC that meets the minimum specifications.
If you are ready to start KNOPPIX, there are a few things I recommend.
✦
— You need a PC that meets the minimal processor and memory requirements I describe a bit later. There are no hard disk space requirements since you don’t need to touch the hard disk. However, to get better performance on low-RAM systems, you might want to create a swap partition on hard disk to enable you to run more processes (as described later).
✦
— KNOPPIX is going to take over operation of the PC, so you need to be sure that it’s okay to reboot it. Make sure that nobody else is currently using the computer or relying on it to be accessible over a network.
✦
— It isn’t necessary, but if your computer has an Ethernet card and a connection to the Internet, you can immediately start using KNOPPIX to browse the Web and otherwise take advantage of its communications tools. KNOPPIX will try to detect a DHCP server (to get an IP address and other information) and automatically configure itself to use the Internet or other network that is available.
The system requirements for running KNOPPIX are much lower than you need for most of the latest Linux systems. According to Klaus Knopper, you need:
✦
— Intel-compatible i486 or better.
✦
— 20MB (for text mode), 82MB (for graphics mode with KDE), or 128MB
(to also run most office applications).
✦
— KNOPPIX is able to boot from drives that are IDE/ATAPI, Firewire, USB, or SCSI (provided that your computer can boot from those devices). Otherwise, you can create a boot floppy to start the process of booting KNOPPIX (described later). If you have a DVD drive, you can boot KNOPPIX directly from the DVD that comes with this book.
✦
— Must be SVGA-compatible.
✦
— Supports any standard serial mouse, PS/2 mouse, or IMPS/
2-compatible USB mouse.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 337
Chapter 11
✦
Running KNOPPIX
337
Note
If you have a PC in front of you that meets the requirements, you can get started by following these steps:
Insert your KNOPPIX DVD or CD into the appropriate drive.
Reboot the computer. After a few moments, you will see the boot screen.
Although the boot screens look different for the Linux Bible DVD and a regular
KNOPPIX CD, you can proceed with the boot process the same way.
Press Enter. If all goes well, you should see the KNOPPIX desktop, and you can proceed to the “Using KNOPPIX” section. If KNOPPIX doesn’t boot up properly or if you want to tune it further before it boots, continue on to the next section.
By understanding a bit about the boot process you will, in most cases, be able to overcome any problems you might have installing KNOPPIX. Here are some things you should know:
✦
— Your computer’s BIOS has a particular order in which it looks for bootable operating systems. A typical order would be floppy, CD or
DVD, and hard disk. If your computer skips over the KNOPPIX boot disk and boots right from hard disk, make sure that the boot order in the BIOS is set to boot from CD or DVD. To change the BIOS, restart the computer and as it first boots the hardware enter Setup (quickly) as instructed (usually by pressing
F1, F2, or DEL). Look for a selection to change the boot order so that your CD or DVD boots before the hard disk.
✦
— If your computer still can’t boot from CD or DVD, you can create two floppy boot disks to start the boot process. To create the floppy boot disks from a running KNOPPIX system, run the mkbootfloppy command that is on the KNOPPIX disk (it automatically finds the floppy images and tells you when to put in the floppy disks). To create KNOPPIX floppy disks on other operating systems, refer to the KNOPPIX Boot Floppy
How To ( www.knoppix.net/docs/index.php/BootFloppyHowTo ).
✦
— Instead of just letting the boot process autodetect and configure everything about your hardware, you can add options to the boot prompt that will override what KNOPPIX autoconfiguration might do. Press F2 from the boot prompt to see additional boot options.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 338
338
Part III ✦
Choosing and Installing a Linux Distribution
Note
Some boot options are available with which you can try to overcome different issues at boot time. KNOPPIX refers to these options as
cheat codes.
For a more complete list, refer to the file knoppix-cheatcodes.txt
, which you’ll find in the
KNOPPIX directory when you mount the CD or the DVD that comes with this book on any operating system.
Many boot options can be used with different Linux systems. So if you are having trouble installing or booting a different Linux distribution, you can try any of these options to see if they work. Instead of the word “knoppix,” you will probably use a different word to launch the install or boot process for other distributions (such as
“linux” for Red Hat Linux systems or “morphix” for Morphix Live-CD, depending on the distribution).
When KNOPPIX first begins the boot process, you see the boot screen, with the boot: prompt at the bottom. The following tables provide boot prompt options that can help you get KNOPPIX running the way you like. Table 11-1 shows options to use when you want specific features turned on that may not be turned on by default when you boot.
Option
knoppix lang=
??
knoppix blind knoppix brltty=type,port,table knoppix wheelmouse knoppix nowheelmouse knoppix keyboard=us xkeyboard=us knoppix dma knoppix alsa knoppix alsa=es1938
Table 11-1
Feature
knoppix desktop=
??
Choose a specific language/keyboard. Replace
??
with one of the following: cn
, de
, da
, es
, fr
, it
, nl, pl
, ru
, sk
, tr
, tw
, or us
.
Instead of using the KDE desktop (kde), replace
??
with one of the following window managers: fluxbox, icewm, larswm, twm, wmaker, or xfce.
Start BrailleTerminal (running without X).
Add parameters to use for the Braille device.
For a wheel mouse, enable IMPS/2 protocol.
For a regular PS/2 mouse, force PS/2 protocol.
Assign different keyboard drivers to use with text (shell) and graphical (X).
Turn on DMA acceleration for all IDE drives.
Select either of these two notations to select to use the ALSA driver (do at your own risk).
18_579495 ch11.qxd 12/27/04 10:09 PM Page 339
Chapter 11
✦
Running KNOPPIX
339
If there is hardware being improperly detected or configured, you can have KNOP-
PIX skip over that hardware. Table 11-2 contains options for skipping or turning off various hardware features:
Option
knoppix atapicd knoppix noagp knoppix noapic knoppix acpi=off knoppix noapm knoppix noaudio knoppix nodhcp knoppix fstab knoppix firewire knoppix nopcmcia knoppix noscsi knoppix noswap knoppix nousb knoppix pnpbios=off knoppix failsafe
Table 11-2
Result
No SCSI-Emulation for IDE CD-ROMs.
No detection of AGP graphics card.
Disable Advanced Programmable Interrupt Controller
(can overcome some problems on SMP computers).
Disable Advanced Configuration and Power Interface (ACPI).
No Advanced Power Management support. (With a working acpi
, apm a time.) will be off by default. Only one can be active at
No sound support.
Don’t try to start your network connection automatically via DHCP.
Don’t read the fstab or check.
file to find file systems to mount
No detection of Firewire devices.
No detection of PCMCIA card slots.
No detection of SCSI devices.
No detection of swap partitions.
No detection of USB devices.
Don’t initialize plug-and-play (PnP) in the BIOS.
Do almost no hardware detection.
Table 11-3 lists options that may help if you are having trouble with your video card. Several of these options are particularly useful if you are having trouble with
X on a laptop.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 340
340
Part III ✦
Choosing and Installing a Linux Distribution
Option
Table 11-3
knoppix noddc knoppix screen=
??
knoppix xvrefresh=60 knoppix xhrefresh=80 knoppix xserver=
??
knoppix xmodule=
??
knoppix 2 knoppix vga=normal knoppix fb1280x1024 knoppix fb1024x768 knoppix fb800x600
Result
No Display Data Channel (DDC) detection of monitor.
Pick X screen resolution. Replace
??
with 640
×
480,
800
×
600, 1024
×
768, 1280
×
1024, or any other resolution supported by your video card.
Set vertical refresh rate to 60 Hz for X (or other value as specified by monitor’s manual).
Set horizontal refresh rate to 80 Hz for X (or other value as specified by monitor’s manual).
Replace
??
with
X-Server: XFree86 or
XF86_SVGA
.
Select the specific driver to use for your video card. Replace
??
with one of the following: ati , fbdev , i810 , mga , nv , radeon
, savage
, s3radeon
, svga
, or i810
.
Runlevel 2, Textmode only.
No-framebuffer mode, but X.
Use fixed framebuffer graphics (1).
Use fixed framebuffer graphics (2).
Use fixed framebuffer graphics (3).
Several boot options exist that tell KNOPPIX to look for a customized home directory or configuration information on hard disk or floppy. See the “Customize KNOPPIX” section later in this chapter for information on how to both customize KNOPPIX and tell KNOPPIX where to look for customized information at boot time. (Unless they were created from KNOPPIX, most other Linux distributions will not use these boot options.)
Other boot options are described in the knoppix-cheatcodes.txt
file mentioned earlier. Things you can do with boot options include changing the splash screen when KNOPPIX boots, running in expert mode so you can load your own drivers, selecting to run either a 2.4 or 2.6 kernel, testing your computer’s RAM, and trying to overcome special problems with laptop computers.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 341
Chapter 11
✦
Running KNOPPIX
341
Testing the CD
If you suspect that you have a bad KNOPPIX CD, I recommend you run this from the boot prompt:
knoppix testcd
If you are still not able to boot KNOPPIX at this point, it might be that your hardware is either not supported or is broken in some way. To further pursue the problem, I recommend that you check out an appropriate forum at www.knoppix.net
.
Running KNOPPIX from RAM
To improve performance, KNOPPIX offers a way to run the entire KNOPPIX distribution from RAM (provided you have enough available) or install it on hard disk and run it from there. Provided that you have more than 1GB of RAM, you can run
KNOPPIX entirely from RAM (so you can remove the KNOPPIX DVD or CD and use that drive while you run KNOPPIX) by typing the following from the boot prompt:
knoppix toram
Installing KNOPPIX to Hard Disk
You can run KNOPPIX entirely from hard disk if your hard disk is either a FAT or
EXT2 file system type and contains at least 800MB of space. To do this, you must know the name of the hard disk partition you are installing on. For example, to use the first partition on the first IDE drive you would use /dev/hda1 . In that case, to copy KNOPPIX to that disk partition you would type this at the boot prompt:
knoppix tohd=/dev/hda1
You can watch as KNOPPIX is copied to your hard disk partition, and then boots automatically from there. The next time you want to boot KNOPPIX, you can boot it from hard disk again by inserting the KNOPPIX medium and typing the following:
knoppix fromhd=/dev/hda1
With KNOPPIX running from your hard disk, you can safely eject your CD or DVD and use it for other things (type
). Refer to the knoppix-cheatcodes.
txt file for information on other things you can do from the KNOPPIX boot prompt.
Rather than go over how to use the features in KNOPPIX that are common to many
Linux systems (KDE, Internet tools, word processors, and so on), I’ll give you a quick tour of the special features in KNOPPIX. If your computer booted KNOPPIX properly, you should see a screen that is similar to the one shown in Figure 11-1.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 342
342
Part III ✦
Choosing and Installing a Linux Distribution
Figure 11-1:
KNOPPIX boots to a full KDE desktop that is ready to run.
I’ve opened a couple of applications to illustrate some things, and the following sections explore what you typically get when KNOPPIX comes.
KDE is the default desktop environment that comes with KNOPPIX. You can change that at the boot prompt to use one of several window managers instead, or get a
Gnoppix disk instead to use the GNOME environments. But, as delivered, the desktop looks similar to what you see in Figure 11-1.
The KNOPPIX version of KDE matches pretty closely the descriptions in Chapter 3, although there are a few items related to the KNOPPIX KDE desktop that are worth noting:
✦
— To get information about KNOPPIX, click the KNOPPIX icon
(choose a language, and then find links to FAQs, Knopper.Net, and general
KNOPPIX information) or the LinuxTag icon (to read the licenses). There is also the requisite Trash icon.
✦
— Any CD, DVD, floppy, or other removable medium drive is displayed as an icon on the desktop. Of course, this includes the drive holding the KNOPPIX disk, which you can get to directly to do such things as find boot images or KNOPPIX documentation.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 343
Chapter 11
✦
Running KNOPPIX
343
Hard disk partitions are also represented by icons on your KNOPPIX desktop.
Click one of those icons and you can access (read-only) the files on that hard disk partition. This is a great feature for getting the information you need without, by default, letting you change or otherwise damage the data on the computer. To make a disk writable, right-click on the disk icon and select
Actions
➪
Change read/write mode. If you are not able to write to the disk, refer to the section on making disks writable later in this chapter.
✦
— KNOPPIX loads the KDE Panel with applets and launchers for a few useful applications. Click the K button to display the menu containing most KDE applications for you to select. The Web Browser icon launches the
Konqueror browser, which is the KDE file manager as well.
✦
— Click the squished penguin icon in the KDE Panel to see a menu of configuration tools specific to KNOPPIX. This is where you can tune up your TV card, configure printers, get your network connection going, and even start a few servers. I describe some of these subjects — in particular, how to save data and configuration information across sessions with this otherwise ethereal operating system — later in this chapter.
✦
— From the KDE menu, you can launch applications as you would from any desktop operating system. Just to illustrate that, I launched a simple game (Penguin Mastermind) and a music player (XMMS) for Figure 11-1.
Running KNOPPIX, at this point, is just like running any other Linux system with a KDE desktop, with one major exception. By default, you can’t save any data permanently. There are a few ways around this issue, especially if you expect to use
KNOPPIX on a regular basis. Refer to sections on creating persistent desktops and opening disks for writing later in this chapter.
If you have an Ethernet card and a connection to a network that has a DHCP server, your KNOPPIX system should just start up and offer immediate access to that network (and possibly the Internet if it offers such a connection). If not, KNOPPIX offers several tools for configuring your network connection, including:
✦
— From the squished penguin, select Network/Internet
➪
/dev/modem connection setup. The menus that appear help you create a dialup connection to the Internet, or other TCP/IP network, using a serial modem,
USB modem, IRDA cellphone/PDA, or Bluetooth cellphone/PDA.
✦
— From the squished penguin, select Network/Internet
➪
ADSL
/PPPOE configuration. It will help you connect your broadband ADSL router to connect to the Internet.
✦
— From the squished penguin, select Network/Internet
➪
GPRS connection to set up a connection via your cellphone provider.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 344
344
Part III ✦
Choosing and Installing a Linux Distribution
✦
— From the squished penguin, select Network/Internet
➪
Network card to configure your Ethernet card (assuming you don’t just want to use
DHCP to get your network address).
✦
— From the squished penguin, select Network/Internet
➪
ISDN to use
ISDN to connect to the network.
✦
— From the squished penguin, select Network/Internet
➪
Wavelan to use a wireless Ethernet card to connect to the network.
In addition to the interfaces available here, you can use the wvdialconf command to create your dial-out connection as described in Chapter 5.
Despite the fact that KNOPPIX includes a wide range of software applications, there may be some special software package you want to use with it that isn’t included.
KNOPPIX has a feature for installing software while you are running from the CD that is called the KNOPPIX-Live Installer.
To use the KNOPPIX-Live Installer, click the squished penguin on the KNOPPIX panel and select Utilities
➪
Install software. After being warned that this is still experimental software, a list of software that you can install with KNOPPIX-Live
Installer appears. The list includes software that can’t be freely distributed, such as Flash plug-ins for your browser or NVIDIA drivers for your video cards.
Select the software package you want to install. KNOPPIX will try to use the Debian installer to download the selected packages and install them on your computer.
Remember that the software is being installed in the version of KNOPPIX that is running in RAM. So, the software will disappear the next time you reboot, unless you do something to preserve your data (such as creating a persistent desktop before you install the software you want to keep).
When you reboot your computer with KNOPPIX, you not only lose KNOPPIX itself, but you lose any data and configuration information you may have created along the way. That’s because, by default, KNOPPIX runs from your system’s RAM and a nonwritable CD or DVD. Using tools and procedures that come with KNOPPIX, there are ways in which you can keep that information going forward.
KNOPPIX happily gives you a login name (knoppix) and a home directory ( /home/ knoppix
), each time you boot from KNOPPIX. You can save files to that directory, as well as change your desktop and system configuration information (which is stored in that directory and in
/etc files). The problem is that those directories are in RAM, so they disappear when you reboot.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 345
Chapter 11
✦
Running KNOPPIX
345
The following sections give you some ideas about how to save what you do in your
KNOPPIX session to use in future sessions.
Although hard disk partitions are mounted read-only by default, you can make them read/write if you like. Then you can store any data you want to save on those partitions. (You can simply drag and drop files to those partitions.)
Caution
If your hard disk partitions are Linux partitions, it’s pretty easy to do this. With older Windows systems that use VFAT partitions, it’s not too hard either. With NTFS partitions, things get a bit trickier:
Up to this point, there’s not much risk of damaging any data on your hard disk. Once you make your disks writable, you have the potential for deleting or changing that data. Keep that in mind if the computer doesn’t belong to you of if you are not used to using Linux. Regardless of which user you are logged in as, KNOPPIX does not prevent you from changing any file in a writable hard disk partition.
Mounting Linux Partitions for Writing
KNOPPIX usually identifies all hard disk partitions and adds entries for each one in your
/etc/fstab file. If you click the icon representing that partition, the partition is automatically mounted and a folder opens to the root of that directory.
The name of each partition (hda1, hda2, and so forth for IDE partitions; sda1, sda2, and so on for SCSI disk partitions) is shown on the desktop icon. With that information, here is how you can make any of those partitions writable:
Click the hard disk partition you want to write to on the KNOPPIX desktop. A folder opens, displaying the top directory in that partition.
When you know which partition you want to write to, close all folders or shells that have that partition open. (With the partition open, you can’t remount it.)
Open a Terminal from the panel and become root user by typing
$
cd
$
su -
#
Make sure that the partition you want to mount as writable is unmounted. For example, to unmount the second IDE hard disk partition (hda2), type
#
umount /dev/hda2
If the command completes quietly or if it says “not mounted,” you are fine. If it says “device is busy,” there is still a shell or folder window that is holding that partition open. Before you can continue, you must close whatever is holding the partition open and make sure the umount completes.
Next, you need to mount the partition so it is writable. Here’s how:
#
mount -orw /dev/hda2
18_579495 ch11.qxd 12/27/04 10:09 PM Page 346
346
Part III ✦
Choosing and Installing a Linux Distribution
At this point you can open the folder to the partition (hda2 in our example) or open a shell and write to that directory (
/mnt/hda2 and any subdirectories). To make that change permanent (in the KNOPPIX sense), you need to change the /etc/fstab add rw to the entry for the partition so it is mounted read/write by default. Again, to with the example of /dev/hda2 , an entry in read/write could look as follows:
/etc/fstab to mount that partition
/dev/hda2 /mnt/hda2 ext3 noauto,users,exec,rw 0 0
With that change, simply typing
mounts the directory with read/write permissions. You can save that change permanently, as described in the “Keeping Your KNOPPIX Configuration” section later in this chapter.
Mounting Windows Partitions for Writing
Getting your Windows partitions mounted for writing is a bit tougher. Although using FAT and VFAT file systems works pretty much the same as described for Linux partitions (provided they are properly detected and configured in /etc/fstab ), the drivers for using NTFS file systems (the current default for Windows) are unreliable for writing.
If you have legal Windows drivers on your hard disk (which you should if you are booting KNOPPIX from an otherwise-Windows machine), KNOPPIX provides a reliable way to set up your NTFS partitions to be read/write accessible from KNOPPIX.
Here’s how:
Caution
You must make sure that you have the legal right to use Microsoft NTFS-related drivers to use this procedure.
Click the squished penguin logo in the panel, and then select Utilities
➪
Captive NTFS. The Captive Microsoft Windows Drivers Acquire window appears.
Click Forward. The Local Disks Drivers Scan window appears, ready to look for the drivers KNOPPIX needs to access the NTFS partitions for writing.
Click Forward to look for the drivers. If the drivers are found, you can continue. If not, it asks for a location on the network where it can get the drivers.
If that is not available, it offers the opportunity to get the Microsoft Windows
XP Service Pack, if you are legally allowed to get that.
Once the necessary drivers are installed, you can mount the NTFS partition using the mount command with the captive-ntfs file system type. For example, if your NTFS partition is on hda1, you could type the following (as root user):
#
umount /dev/hda1
#
mkdir /mnt/captive-LABEL_C
#
mount -t captive-ntfs /dev/hda1 /mnt/captive-Label_C
18_579495 ch11.qxd 12/27/04 10:09 PM Page 347
Chapter 11
✦
Running KNOPPIX
347
Now you should be able to access the NTFS partition from the /mnt/captive-
LABEL_C directory.
If you are going to use the computer more than once with KNOPPIX (or if you just want more storage space for files than your computer has available in RAM) you can assign your KNOPPIX home directory ( /home/knoppix ) to use some of the available space on your hard drive. That can be done by either:
✦
Assigning an entire partition to be used for your home directory.
✦
Assigning a part of that partition for your home directory, in the form of an image file.
You can also put your persistent home directory on rewritable, removable media, such as a memory stick. Once you create that area to use as your home directory, you can tell KNOPPIX to use it every time you restart KNOPPIX. Here’s what you do:
Click the squished penguin in the panel, and then select Configure
➪
Create a
Persistent KNOPPIX Home Directory. A window appears, asking if you are ready to create a persistent home directory.
Click Yes to continue. You are asked which partition you want to use for your persistent home directory.
Select the partition you want from the list and click OK. You are asked if you want to use the entire partition and format it as a Linux file system or just create an image.
Don’t click Yes unless you are prepared to erase an entire partition! Click No
(the safer route) to just add an image file on a directory where you have space.
If you are creating the image file, you are asked how big to make it.
Type the number of megabytes to assign to your home directory. Be sure that that much space is available on the partition. (When the partition is mounted later, you can type df -h to see how much space is available on it.) You are asked if you want to save the home directory in an encrypted format.
Select No, to not have the directory selected as encrypted (if you choose
Yes, you’ll have to specify a long password that you will need to access the persistent home directory at boot time). The partition or image file should be created now.
When I ran this procedure to create a 100MB image on the hda5 partition, it created the file
/mnt/hda5/knoppix.img
, which had 97MB of available space. To see how to use that directory, see the “Restarting KNOPPIX” section later in this chapter.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 348
348
Part III ✦
Choosing and Installing a Linux Distribution
After you have gone through all the work to configure your desktop, printer, network, disks, and other preferences for your KNOPPIX setup, it’s a shame to lose all that on your next reboot. Well, KNOPPIX offers a way that you can save your configuration information and reuse if for your next session. That saved information can be stored on a floppy disk or any other medium that is accessible (such as your hard disk) the next time you reboot KNOPPIX. Here’s how:
From the squished penguin icon on the panel, click Configure
➪
Save KNOPPIX configuration.
Choose the configuration files to save. You can choose to save your personal configuration (from /home/knoppix .kde
and .mozilla
directories), files on the desktop, your network configuration, X configuration, and other system configuration files (from /etc ).
Choose to save your configuration files to your floppy disk or to any available disk partition that is writable. Choosing floppy can make the configuration portable, whereas using the hard disk makes the configuration easily reusable on the same machine.
If you are saving to floppy, insert the floppy and click OK. The data will be saved to floppy disk.
Note
The results from this action are that the knoppix.sh
created on floppy disk. The configs.tbz
and configs.tbz
files are file contains all the saved configuration files from your /home and /etc directories. The knoppix.sh
file is a script that tells KNOPPIX how to install those files when KNOPPIX boots up. The next time you start KNOPPIX, you can use the configuration files, as described in the next section.
Those who create their own customized KNOPPIX boot disks can simply add their knoppix.sh
and config.tbz
files to the top-level directory of the CD, so KNOPPIX will just boot to their personalized configuration without worrying about an extra floppy or other medium.
You can start KNOPPIX anytime by just inserting your KNOPPIX CD or DVD and restarting your computer. However, if you want to take advantage of the persistent desktop you set up or the saved configuration information, you need to add some options to the KNOPPIX boot prompt. Here’s how:
Insert your KNOPPIX CD or DVD into the computer and reboot. You should see the KNOPPIX boot prompt.
Press F3 (before KNOPPIX boots) to see if there are any additional boot options that are required.
If you have a configuration floppy boot disk (or other removable media created in an earlier procedure), insert that disk now.
18_579495 ch11.qxd 12/27/04 10:09 PM Page 349
Chapter 11
✦
Running KNOPPIX
349
At the boot prompt, type one of the following command lines, which are different ways to load your configuration files: boot:
knoppix floppyconfig
boot:
knoppix myconf=/dev/hda1
boot:
knoppix myconf=/dev/sda1
boot:
knoppix myconf=scan
These KNOPPIX boot commands, respectively, get configuration information from the floppy disk, look for that information on the first IDE drive partition
(
/dev/hda1
), look for it on the first SCSI drive partition (
/dev/sda1
), or scan all available drives to find the information. To boot to a persistent desktop
(assuming you set one up earlier), you could instead type: boot:
knoppix home=/dev/hda1/knoppix.img
boot:
knoppix home=/dev/sda1/knoppix.img
boot:
knoppix home=scan
The previous boot commands, respectively, assign the KNOPPIX home directory ( /home/knoppix ) to the /dev/hda1/knoppix.img
knoppix.img
file, to the /dev/sda1/ file, or to the image file found by scanning all available directories for that file. You could also combine one from each of the two preceding command sets to both read your configuration files and assign a persistent desktop, as follows: boot:
knoppix floppyconfig home=/dev/hda1/knoppix.img
Now you are ready to continue your KNOPPIX session where you left off last time, with the same configuration and data files available.
KNOPPIX offers what many feel is the best bootable Linux today. It gives you a fully configured Linux desktop system available virtually anywhere you can find a bootable PC.
Besides its desktop features, KNOPPIX contains software needed to use many server, programming, and troubleshooting features of Linux as well. Despite the fact that KNOPPIX runs as a bootable system in RAM, by default, there are ways to configure it to save data and configuration information across multiple boot sessions.
KNOPPIX is particularly valuable as a tool for accessing a damaged computer so that you can troubleshoot it. With a KNOPPIX disk booted on a computer that was installed to use Microsoft Windows or other operating system, you can use KNOPPIX to access and work with data on that computer’s hard disk.
✦ ✦ ✦
18_579495 ch11.qxd 12/27/04 10:09 PM Page 350
19_579495 ch12.qxd 12/27/04 10:07 PM Page 351
Y
ellow Dog Linux is the premier Linux distribution for the PowerPC platform. Offered by Terra Soft Solutions
( www.terrasoftsolutions.com
), Yellow Dog Linux provides unparalleled concentration on the needs of the PowerPC users.
Because most Linux distributions focus on the Intel/AMD (x86) platform, it’s sometimes startling to realize that there’s a major
Linux distribution, with a passionate community of its own, providing a strong presence in the world of PowerPCs.
On the
DVD-ROM
Yellow Dog Linux is not included on the Linux Bible DVD that comes with this book. You can purchase it from Terra
Soft Solutions ( www.terrasoftsolutions.com/store
) or download the four-CD installation set from a Yellow Dog
Linux mirror site (for a list of mirror sites, see: http:// yellowdoglinux.com/resources/ftp_mirrors.
shtml
). See Appendix A for information on burning CDs.
Terra Soft Solutions has focused its efforts on making Yellow
Dog Linux work for a wide range of Apple products, resulting in less chance of hardware incompatibilities. This is one of the distribution’s strengths. Another heartening note is that Terra
Soft Solutions is an Apple Authorized OEM Value Added Reseller with permission from Apple to install Linux on Apple hardware, retaining any hardware warranties provided by Apple.
Mac OS X, in the form of Aqua, is considered one of the most advanced graphical user interfaces on the market today. With a sophisticated interface available on the Apple platform, a user might question putting Linux on Apple hardware, but there are many valid reasons to install Linux on the PowerPC architecture, including:
✦
— Commercial applications usually have a higher price of ownership than their open source counterparts for similar functionality. For instance, the latest word processor on the Mac OS X platform can cost hundreds of dollars, whereas the open source alternatives are generally free. The free software available for Linux far exceeds that available for the Mac OS X platform.
✦ ✦ ✦ ✦
In This Chapter
Digging into Yellow
Dog Linux
Installing Yellow
Dog Linux
Running Mac-on-Linux
✦ ✦ ✦ ✦
19_579495 ch12.qxd 12/27/04 10:07 PM Page 352
352
Part III ✦
Choosing and Installing a Linux Distribution
Note
While some of the more popular open source programs are available for Mac OS X, they may require a port of the software, as opposed to a recompile. Porting applications is a more complicated process and can be very frustrating for many users.
Porting is outside the sphere of this book.
✦
— Linux is well known for its low operation requirements. You can use Yellow Dog Linux on machines that aren’t necessarily supported by the latest Mac OS X version and still run the latest Linux applications.
✦
— Linux is widely deployed, especially for back-office functions.
By using Yellow Dog Linux (often referred to as YDL), you can mix PowerPC hardware with Intel hardware in the same production environment, with application and operating system uniformity, reducing costs associated with the support of two different operating systems. Because Linux is open source and widely available, you also reduce your dependence on one entity for your operating systems.
✦
— Yellow Dog Linux has the support of thousands of programmers who constantly develop patches and updates for software, as opposed to depending on a commercial entity to release patches.
✦
— Linux (and particularly Fedora Core, on which
Yellow Dog Linux is based) is so widely deployed, with more installations occurring every day, that it’s understood and managed by a large user/administrator group. Using a standard interface, it’s often easier for system administrators and users to complete tasks on a familiar system.
✦
— Mac-on-Linux software enables you to run Mac OS X
(10.1-10.3.3), Mac OS 7.5.2-9.2.2, or another instance of Linux within your active Yellow Dog Linux session, so you get the best of both worlds.
A few different versions of Yellow Dog Linux are available that cover a wide spectrum of current and legacy PowerPC hardware:
✦
— Terra Soft Solutions has released version 4.0, which is aimed at the desktop users who have hardware starting from G3 Blue and
White (300–450 MHz) all the way to the dual G5 Power Mac Towers. This is the
32-bit version of its distribution.
✦
— The prior version (October 1, 2004, and before) of
Yellow Dog, which supports the beige G3 hardware (66 MHz) and below product line (Old World ROM) as well as most of the same hardware that Yellow Dog
Linux 4.0 supports.
✦
— A planned variation of Yellow Dog based on the 64-bit Fedora Core version of Linux. This version is for high-performance computing and promises to offer high-performance support for Xserve G5s or cluster nodes. This is currently not available as a standalone product, but Terra Soft Solutions will preload it on hardware purchased through the company.
19_579495 ch12.qxd 12/27/04 10:07 PM Page 353
Chapter 12
✦
Running Yellow Dog Linux
353
Yellow Dog Linux offers a Fedora Core 2, RPM-based distribution that is highly compatible with most available open source software. By basing the Yellow Dog distribution on a widely deployed and used X86 distribution such as Red Hat’s
Fedora Core, Terra Soft Solutions has been able to quickly deploy a very uniform, user-friendly experience for its user base. This section takes a look at some of the highlights of the Yellow Dog distribution.
Yellow Dog Linux 4.0 offers four full CDs of software with some of the following applications:
✦
2.6.7 Linux Kernel
✦
X.org 6.6
✦
KDE 3.3 desktop (unified with GNOME to provide easy access to other desktop environments programs)
✦
GNOME 2.6.0 desktop (unified with KDE to provide easy access to other desktop environments programs)
✦
OpenOffice 1.1.1 (suite of productivity tools including a spreadsheet program, drawing program, presentation software, and a full-featured, Microsoft Wordcompatible word processor)
✦
More than 1,300 other application packages from programming tools to Web browsers.
The wide range of applications included on the Yellow Dog CDs is enough to keep even the most computer-savvy person happy, but many more choices are available on the Internet, so you should be able to find an application that fits your needs.
Fedora Core is the community-supported version of what was previously the ubiquitous Red Hat Linux distribution. As a derivative of Fedora Core, Yellow Dog Linux can offer the advantages of Fedora features on a MAC platform, including:
✦
Starting with software packages from the Fedora project helps Yellow Dog Linux avoid compatibility problems suffered by some Linux distributions. Users can also rely on well-known RPM packaging tools for adding, removing, and managing software.
✦
Yellow Dog takes advantage of the well-tested Anaconda installer for easy installation.
✦
By starting with the Fedora Core kudzu facility for detecting and configuring hardware, Yellow Dog has a stable foundation for probing equipment that has been extended to work with Mac hardware.
Cross-
Reference
Refer to Chapter 8 for more information on the Fedora Core project and some of the specifics regarding its implementation.
19_579495 ch12.qxd 12/27/04 10:07 PM Page 354
354
Part III ✦
Choosing and Installing a Linux Distribution
Before you can install Yellow Dog Linux, you need to get a copy of it from some of the many resources available. The first and most recommended avenue is to purchase it from the vendor. This has the dual effect of your acquiring the distribution from the source as well as supporting the company that creates Yellow Dog Linux so it can continue development for the PowerPC platform.
To purchase Yellow Dog Linux from Terra Soft Solutions, visit the Terra Soft Solutions
Web store at http://terrasoftsolutions.com/store/ . When purchasing from
Terra Soft Solutions, you receive the following in a box set:
✦
Four install CDs and four source CDs.
✦
Getting Started with Yellow Dog Linux,
a book that covers all the information a beginning Linux user would need to know to get a fully operational Yellow Dog
Linux system running.
✦
Optional 60 days of installation support (you can purchase the box set with or without support, depending on your needs and skill level with Linux).
✦
Other goodies (sticker, flexible flier depending on package purchased).
✦
The knowledge that you are supporting the company that created the product, allowing further development.
Alternatives to purchasing the Yellow Dog Linux box set include:
✦
This is Terra Soft Solutions online resource for Yellow Dog Linux users. You can get e-mail accounts and Web space as well as prerelease access to the latest version of Yellow Dog Linux before it is available for general release. The costs vary depending on which version you choose. More information is available at http://www.ydl.net/ .
✦
You can download the distribution from one of the many Linux mirrors as identified at http://yellowdoglinux.
com/resources/ftp_mirrors.shtml
and burn your own ISO.
✦
If you have a slow Internet connection and want to try
Yellow Dog, you can purchase burned CDs from various Linux stores on the
Internet. Use your favorite search engine to locate one near you.
Hardware support with the Linux operating system was a major issue in the past, but as Linux’s popularity has grown, many device makers have provided access to their hardware drivers or in some cases have created hardware drives for Linux.
While this is still an issue with hardware that is brand new in the X86 community,
19_579495 ch12.qxd 12/27/04 10:07 PM Page 355
Chapter 12
✦
Running Yellow Dog Linux
355 the effects are lessened with the PowerPC platform because all hardware is generally created to Apple’s exacting standards. Terra Soft Solutions’ focus on Apple hardware and generally fewer variations in hardware add up to support being much faster for the PowerPC platform.
One of the great things about Yellow Dog Linux is that as you dig into it (no pun intended), you discover that some of the hardware compatibility issues faced by the X86 Linux crowd (such as with Winmodems, the plethora of hardware configuration options, and so forth) are minimized or eliminated. With Terra Soft Solutions, a fully authorized Apple Value Added Reseller, you are assured that the hardware you are using will be supported. There are some notable hardware support differences with the release of YDL 4.0, but the fully capable 3.0.1 version covers any gaps of the 4.0 product.
In addition to being able to install Yellow Dog Linux on your own Apple hardware, you can purchase Apple hardware from Terra Soft Solutions with Yellow Dog Linux preinstalled.
Terra Soft Solutions has developed official lists of hardware configurations that have been specifically tested with Yellow Dog Linux ( http://yellowdoglinux.com/ support/hardware/breakdown/index.php
). The Yellow Dog 4.0 list includes:
✦
Power Mac G3 (Yosemite Blue and White 300–450 MHz G3)
✦
Power Mac G4 (Power Mac G4 PCI 350–400 MHz G4 and above)
✦
Power Mac G5 (1.6 GHz G5 and above)
✦ iMac (Rev A,B 233 MHz G3)
✦
PowerBook (Lombard 333–400 MHz G3, Pismo 400–500 MHz FW G3, Titanium
400 MHz–1 GHz G4, Powerbook 12" 867 MHz–1.33 GHz, and Powerbook 15–17"
1.0–1.5 GHz G4)
✦ iBook (300–366 MHz G3 — 800 MHz 1.2 GHz G4)
✦
HPC (Xserver Cluster Node 1.33 MHz G4, Single/Dual 1.33 GHz G4, Cluster
Node 2.0 GHz G5, and Single/Dual 2.0 GHz G5)
Most notably missing from Yellow Dog Linux 4.0 supported hardware is Old World
ROM or beige G3 and below hardware such as 8500s, 7200s, and Performa PowerPCs.
YDL 3.0.1 supports this hardware and most of the hardware currently supported by
Yellow Dog Linux 4.0. The hardware supported and tested for Yellow Dog Linux 3.0.1
includes:
✦
Power Mac 4400–9600
✦
Power Mac beige G3 models and blue-and-white G3 models
✦
Most hardware supported by Yellow Dog Linux 4.0
19_579495 ch12.qxd 12/27/04 10:07 PM Page 356
356
Part III ✦
Choosing and Installing a Linux Distribution
If you have older hardware that isn’t officially supported, you should still be able to use Yellow Dog Linux 4.0, but you’ll be running in an unsupported configuration, so caveat emptor. The reason for the dropping of older hardware is so that Terra
Soft Solutions could focus on the most likely configurations, instead of trying to support every possible system, of which the Old World ROM systems were particularly troublesome.
Before starting installation, back up any data you want to retain on external media
(CD, hard drive, and so on). This is a precautionary measure in case your system overwrites data that is important to you. The next step is to determine if you are going to multiboot Mac OS with Yellow Dog Linux or if you are going to install
Yellow Dog Linux as a standalone product. If you choose to multiboot, you must decide if you will use two hard drives or partition (or logically divide) a single hard drive to house both Linux and Mac OS.
Note
If you choose to use one hard drive to house both Mac OS and Yellow Dog Linux, you need to load Mac OS (X or 9) first and then create a partition for Yellow Dog
Linux as the first partition. In Mac OS X do the following:
Boot off the Mac OS X CD by holding down the C key with the Mac OS X
CD-ROM inserted (to boot off the CD-ROM).
From the Install menu, select Open Disk Utility.
Select your hard drive and then click the partition tab on the right side.
Choose how many partitions you want (2 partitions is a good selection for both Mac OS X and Yellow Dog Linux, or if you want to install Mac OS 9 or below and Mac OS X, you can choose the number of partitions needed.)
Choose the first gray partition that is untitled (it should be the top one).
In the Format menu, select Free Space for your Yellow Dog Linux partition.
Note that you can change the size of the partition if you don’t want to use the defaults by entering the size you want or by using the slider. You can also name the partition if you like.
Be sure to create a partition large enough for your Linux installation. The default sizes for some of the types of installations (discussed later in this chapter) are:
Personal Desktop — 2GB
Workstation — 2.5GB
Server — 1GB
Everything — 6GB
These are size estimations, and you will need more room for any other applications you want as well as for personal files, etc.
19_579495 ch12.qxd 12/27/04 10:07 PM Page 357
Chapter 12
✦
Running Yellow Dog Linux
357
Choose the second gray partition and leave it as the default (Mac OS Extended) for your Mac OS X partition. You can name this as well if you like and adjust the size according to your needs.
Click the Partition button and then quit the partition tool.
Resume your installation of Mac OS X as normal.
If you want to install Mac OS 9 or below in addition to Yellow Dog Linux on one hard drive, you can perform the following for a dual-booted machine:
Boot off the Mac OS CD by holding down the C key with the Mac OS CD-ROM inserted (to boot off the CD-ROM).
Double-click the Utilities or Disk Tools folder. Double-click the Drive Setup application.
Select your hard drive in the List of Drives in the Drive Setup window.
Click the Initialize button, and then click the Custom Setup button.
Choose how many partitions you want in the Custom Setup pop-up window
(2 partitions is a good selection for both Mac OS and Yellow Dog Linux, or
3 partitions for Mac OS, Mac OS X, and Yellow Dog Linux). You can use the slider bar to change the size of the partitions here.
Choose the top partition and select Unallocated in the menu that by default displays Mac OS Extended. The second partition should be Mac OS Standard for Mac OS, and if you are loading Mac OS X as well, the third partition should be Mac OS Extended (only available if you chose 3 partitions). Make sure to label the partitions appropriately.
Select OK and then Initialize.
Resume your installation of Mac OS as normal.
Because of the way the system boots, you should have the drive to which you plan to install Yellow Dog Linux as the first hard drive in the IDE chain, set as Master.
Mac OS or Mac OS X should be placed as the second drive in the chain and have the jumper set to Slave.
Then install the other versions of Mac OS (9 or below or X) onto the other hard drives. You only need to select a drive other than the first one during the install procedure. You must install Yellow Dog Linux as the last operating system and on the first drive.
19_579495 ch12.qxd 12/27/04 10:07 PM Page 358
358
Part III ✦
Choosing and Installing a Linux Distribution
All the planning noted previously applies to Yellow Dog Linux 3.0.1, but there is one special consideration to take into account. Yellow Dog Linux 4.0 supports only New
World ROM systems, which are the blue-and-white G3 and above systems.
Note
There are two versions of the G3, one that has a beige case and another that has the blue-and-white case.
If you are installing Yellow Dog on a New World ROM system, go right to the next section, “Beginning the Installation.”
If you are using an Old World ROM system, which are beige G3 systems and below, refer to the Yellow Dog Linux Web site ( http://www.yellowdoglinux.com
) for more information.
Note
After you have determined how you will boot your system (multiboot or single
Yellow Dog Linux boot) and have loaded Mac OS X or Mac OS 9 or below as appropriate, you can begin installing Yellow Dog Linux. This procedure focuses on Yellow
Dog Linux 4.0, but special notes on aspects of the 3.0.1 install are included where appropriate.
Insert Yellow Dog Linux CD 1 into your CD-ROM drive and press C to boot off the CD-ROM.
If you downloaded Yellow Dog or have a burned CD-R, you may want to check your media by appending mediacheck to the end of any of the install types
(see step 3 for install types). For example: install-safe mediacheck
This goes through all your media to determine if it is suitable for loading the operating system. This can save you a lot of time by determining that all of your CDs are good before you invest your time in the installation procedure.
Although it doesn’t show up in the Yellow Dog 3.0.1 text menu, you can still type
mediacheck after install or install-text to check your CD-ROMs.
After some cursory probing messages, you are prompted with a menu asking how you want to boot the CD-ROM. If you are using a New World ROM G3 or G4
(blue-and-white G3 and above machine), type
at the prompt to use the graphical user interface method of installation. If you are using a G5 machine, type
at the prompt to install using the graphical user interface. If you can’t get either of these methods to work, type
for G3 or G4 machines or
for G5 machines to use a generic video mode for installation. If neither of these methods works, you can type
for
G3 or G4 machines or
for G5 machines to install with the text installation method if you find that the graphical version doesn’t work for you.
19_579495 ch12.qxd 12/27/04 10:07 PM Page 359
Chapter 12
✦
Running Yellow Dog Linux
359
Note
Yellow Dog Linux 3.0.1 only has install
Choose install and install-text first, and if that doesn’t work, choose options available.
install-text after rebooting.
The system will have been probed prior to this point to determine the hardware configuration. After the text messages, you are presented with a welcome screen. (You can choose to review the release notes by clicking the Release
Notes button at the bottom-left side.) When you’re ready to move on, click the
Next button on the bottom-right side.
Select the language with which you are most comfortable. All future information presented by the installer will be in the language you select.
Choose the keyboard type that matches your current configuration.
Choose the type of installation you want. The options are:
•
— Most home users will want this installation because it contains the most appropriate software set for home or office users
(including laptops). Games, word processors, Internet tools, and other useful packages are included.
•
— Similar to the personal desktop type but includes tools for system administration as well as software development.
•
— Installs software needed for providing external services, including file and print, Web, and mail services. This is an advanced installation type and should be used only if you need it because you could misconfigure your system and create a security vulnerability. You can choose to install a graphical user interface as well, so if you don’t want the extra overhead of a GUI, you can go without one on this type.
•
— Provides the most flexibility because you can configure the partitions and software packages you want (everything!). This is your choice if you want to have more control over the installation. If you want to experience a large set of applications, you can choose this instead of installing applications one by one. You can also choose a more specific set of packages if this is to be a server used for external services, providing a higher level of security.
For this chapter, the Custom installation type is used and assumed.
Decide how you want to partition your hard drive. You have two choices:
•
— If you choose this method, click Next and you are presented with three options:
Deletes all previous Linux partitions and replaces only previously identified Linux partitions.
Use this only on New World ROM systems or on a single-drive Yellow Dog installation. If you use this option on a multiboot system, it removes
all
previous installations, including any Mac OS or
MAC OS X installation. If you use this on an Old World ROM system, regardless of the installation type, it destroys the installation and requires a reformat and reload of Mac OS.
19_579495 ch12.qxd 12/27/04 10:07 PM Page 360
360
Part III ✦
Choosing and Installing a Linux Distribution
Caution
Be extremely careful using the Remove All Partitions option, and if at all possible, avoid using it at all because you can accidentally destroy your Mac OS installation!
The one you want to use in most cases, because it won’t alter your Mac OS or Mac OS X installations and uses only the identified free space (as created previously). This is the option you should select if you are using Automatically partition.
•
— This is the more advanced option that allows you to create your partitions to your preference. Here is the sequence for creating new Linux partitions:
Choose the drive on which you want to install Yellow Dog Linux.
Choose New to create a new partition. You must create three partitions.
First, choose Filesystem Type
➪
Apple B