Upload
others
View
21
Download
0
Embed Size (px)
Citation preview
UBUNTU LINUXUBUNTU LINUX
THE INSIDER’S GUIDE TO:
UB
UN
TU LIN
UX
DO WHAT YOU NEVER THOUGHT POSSIBLE WITH UBUNTU LINUX
R I C H A R D B L U M
• Delve into the underlying applications and features of the Ubuntu Linux system
• Discover how to make the most of workstation and server applications
• Get helpful tips for modifying your environment and keeping your system running smoothly
Packed with valuable advice and secrets on every aspect of the Ubuntu Linux Distribution,
this comprehensive guide delivers in-depth information on the Ubuntu workstation,
server, and applications, and provides detailed coverage of Ubuntu Linux as a software
development platform. The featured tips and tricks delve into the underlying applications
and features of the Ubuntu Linux system so that you can get the most out of every
application and system feature.
RICHARD BLUM has worked in the IT industry for nearly two decades as both a systems and network administrator.
During this time he has administered UNIX, Linux, Novell, and Microsoft servers, and has helped design and maintain a
3,500-user network utilizing Cisco switches and routers. He is the author of several Linux books, including Professional
Linux Programming, Linux For Dummies, 8th Edition, and Linux Command Line and Shell Scripting Bible.
• Handling Files and File Properties (see Chapter 5)
• Understanding the OpenOffi ce Suite (see Chapter 7)
• Watching Web Clips and Editing Videos (see Chapter 12)
• Connecting to the Network (see Chapter 14)
• Working with Ubuntu Web Servers (see Chapter 21)
• Programming in Python® (see Chapter 26)
• Working with Ruby Code (see Chapter 29)
B L U M
ISBN 978-0-470-39508-0
READER LEVELIntermediate to Advanced
SHELVING CATEGORYOperating SystemsLinux
$54.99 USA$65.99 CANADA
®
® ®
®®
®
95080ffirs.indd 2 3/6/09 2:49:15 PM
Ubuntu® Linux® Secrets
95080ffirs.indd 1 3/6/09 2:49:15 PM
95080ffirs.indd 2 3/6/09 2:49:15 PM
Ubuntu® Linux® SecretsRichard Blum
95080ffirs.indd 3 3/6/09 2:49:16 PM
Ubuntu® Linux® Secrets
Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com
Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-0-470-39508-0
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Library of Congress Cataloging-in-Publication Data Blum, Richard, 1962– Ubuntu Linux secrets / Richard Blum. p. cm. Includes index. ISBN 978-0-470-39508-0 (paper/website) 1. Ubuntu (Electronic resource) 2. Linux. 3. Operating systems (Computers) I. Title. QA76.76.O63B5984 2009 005.4'32—dc22 2009005635
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation, warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional ser-vices. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or web site may provide or recommendations it may make. Further, readers should be aware that Internet web sites listed in this work may have changed or disappeared between when this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974 or outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Ubuntu is a regis-tered trademark of Canonical Limited. 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.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
95080ffirs.indd 4 3/6/09 2:49:16 PM
To my family. “By wisdom a house is built, and through understanding it is established; through knowledge its rooms are filled with rare and beautiful treasures.”
—Proverbs 24:3–4 (NIV)
95080ffirs.indd 5 3/6/09 2:49:16 PM
About the AuthorRichard Blum has worked in the IT industry for over 20 years as both a systems and network administrator. During that time he has administered UNIX, Linux, Novell, and Microsoft servers, as well as helped manage desktop workstations on a 3,500-user net-work. He has used Linux since the days of loading the system from floppy disks and has utilized Ubuntu workstations and servers in his environment.
Rich has a bachelor of science degree in electrical engineering and a master of science degree in management, specializing in management information systems, from Purdue University. He is the author of several Linux books, including Linux Command Line and Shell Script Bible, Professional Assembly Language Programming, Network Performance Open Source Toolkit, sendmail for Linux, Running qmail, Postfix, and Open Source E‑mail Security. He’s also a coauthor of Professional Linux Programming, and Linux for Dummies, 8th Edition. When he’s not being a computer nerd, Rich plays bass guitar for his church worship band and enjoys spending time with his wife, Barbara, and their two daughters, Katie Jane and Jessica.
95080ffirs.indd 6 3/6/09 2:49:16 PM
CreditsAcquisitions EditorJenny Watson
Senior Development EditorTom Dinse
Technical EditorWarren Wyrostek
Production EditorRebecca Coleman
Copy EditorPublication Services, Inc.
Editorial ManagerMary Beth Wakefield
Production ManagerTim Tate
Vice President and Executive Group PublisherRichard Swadley
Vice President and Executive PublisherBarry Pruett
Associate PublisherJim Minatel
Project Coordinator, CoverLynsey Stanford
CompositorMaureen Forys, Happenstance Type-O-Rama
ProofreaderWord One
IndexerRobert Swanson
Cover DesignerRyan Sneed
95080ffirs.indd 7 3/6/09 2:49:16 PM
AcknowledgmentsFirst, all glory and praise go to God, who through His Son makes all things possible and gives us the gift of eternal life.
Many thanks go to the great team of people at Wiley Publishing for their outstanding work on this project. Thanks to Jenny Watson, the acquisitions editor, for offering me the opportunity to work on this book. Also, thanks to Tom Dinse, the development editor, for keeping things on track and making this book more presentable. The technical editor, Warren Wyrostek, did an amazing job of double-checking all the work in this book, plus making suggestions to improve the content. Thanks, Warren, for your hard work and diligence. I would also like to thank Carole McClendon at Waterside Productions, Inc. for arranging this opportunity for me and for helping out in my writing career.
Finally, I would like to thank my parents, Mike and Joyce Blum, for their dedication and support while raising me, and my wife, Barbara and daughters, Katie Jane and Jessica, for their love, patience, and understanding, especially while I was writing this book.
95080ffirs.indd 8 3/6/09 2:49:16 PM
Contents at a Glance
Introduction ............................................................................................................................................ xxv
Part 1: Starting Out with Ubuntu ......................................................................1Chapter 1: What is Ubuntu? ...................................................................................................................... 3Chapter 2: Playing with the LiveCD ...................................................................................................... 25Chapter 3: Installing Ubuntu ...................................................................................................................47Chapter 4: Exploring the Desktop ...........................................................................................................79
Part 2: Starting Out with Ubuntu ................................................................. 107Chapter 5: File Management .................................................................................................................109Chapter 6: Working With Text .............................................................................................................. 135Chapter 7: The OpenOffice Suite ..........................................................................................................161Chapter 8: Network Applications ..........................................................................................................197Chapter 9: Evolution .............................................................................................................................. 227Chapter 10: Image Manipulation.......................................................................................................... 255Chapter 11: Using Audio ....................................................................................................................... 277Chapter 12: Using Video ....................................................................................................................... 295
PART 3: Managing Your Workstation ..........................................................313Chapter 13: Software Installs and Updates ..........................................................................................315Chapter 14: Networking ........................................................................................................................ 337Chapter 15: External Devices ............................................................................................................... 367Chapter 16: The Display ........................................................................................................................ 387Chapter 17: Users and Groups .............................................................................................................. 407Chapter 18: Basic Administration ........................................................................................................ 425Chapter 19: The Ubuntu Command Line .............................................................................................441
PART 4: Using the Ubuntu Server ................................................................ 467Chapter 20: DNS Server ........................................................................................................................ 469Chapter 21: Web Server ......................................................................................................................... 493Chapter 22: Samba and Print Server ....................................................................................................521Chapter 23: Email Server ...................................................................................................................... 547Chapter 24: Database Server ................................................................................................................ 579
95080ffirs.indd 9 3/6/09 2:49:16 PM
x Contents at a Glance
Part 5: Programming in Ubuntu ................................................................... 605Chapter 25: Shell Scripts ....................................................................................................................... 607Chapter 26: Perl and Python ................................................................................................................. 637Chapter 27: C Programming ................................................................................................................. 661Chapter 28: Java ..................................................................................................................................... 687Chapter 29: Ruby .....................................................................................................................................713Chapter 30: PHP ......................................................................................................................................741
Index .........................................................................................................................................................771
95080ffirs.indd 10 3/6/09 2:49:16 PM
Contents
Introduction ............................................................................................................................................ xxv
Part 1: Starting Out with Ubuntu ......................................................................1
Chapter 1: What is Ubuntu? ........................................................................................................... 3What Is Linux? ............................................................................................................................................ 4
The Linux Kernel ................................................................................................................................... 4The GNU Utilities ................................................................................................................................ 11The Linux Desktop Environment ....................................................................................................... 13
Linux Distributions ...................................................................................................................................19Core Linux Distributions ..................................................................................................................... 19Specialized Linux Distributions .......................................................................................................... 20The Linux LiveCD ............................................................................................................................... 21
What Is Ubuntu? ....................................................................................................................................... 22Ubuntu Versions .................................................................................................................................. 22Ubuntu Release Schedule ................................................................................................................... 23Ubuntu Cousins ................................................................................................................................... 24
Summary ................................................................................................................................................... 24
Chapter 2: Playing with the LiveCD ..........................................................................................25The Ubuntu LiveCD................................................................................................................................. 26Downloading Ubuntu .............................................................................................................................. 26
Downloading from the Web ................................................................................................................ 27Using BitTorrent to Download ............................................................................................................ 29Verifying the File ................................................................................................................................. 32
Creating the LiveCD ................................................................................................................................ 34Burning CDs in Linux .......................................................................................................................... 34Burning CDs in Mac OS X .................................................................................................................. 34Burning CDs in Windows .................................................................................................................... 36
Booting the LiveCD ................................................................................................................................. 36The Boot Process .................................................................................................................................. 37Using Ubuntu ....................................................................................................................................... 37The LiveCD Desktop ........................................................................................................................... 39Storing Files ......................................................................................................................................... 40
Running Ubuntu in Windows ................................................................................................................. 42The Wubi Project ................................................................................................................................. 43Installing in Windows .......................................................................................................................... 43Running Ubuntu in Windows ............................................................................................................. 44
Summary ................................................................................................................................................... 45
95080ftoc.indd 11 3/5/09 12:15:51 AM
xii Contents
Chapter 3: Installing Ubuntu ....................................................................................................... 47Preparing Your PC ................................................................................................................................... 48
System Requirements .......................................................................................................................... 48Creating a Place for Ubuntu ............................................................................................................... 51
Installing from the LiveCD ..................................................................................................................... 57Select a Language ............................................................................................................................... 58Select a Time Zone .............................................................................................................................. 58Select a Keyboard ................................................................................................................................ 58Prepare the Disk Space ....................................................................................................................... 60Create a Login ID ................................................................................................................................ 63Migrate Documents and Settings ....................................................................................................... 64Review Options .................................................................................................................................... 66
Installing from the Alternate Install CD ................................................................................................ 67Guided Partitions ................................................................................................................................. 68Manual Partitions ................................................................................................................................ 69
Server Installation .................................................................................................................................... 70Main Installation .................................................................................................................................. 70Server Programs .................................................................................................................................. 71
Upgrading Ubuntu ....................................................................................................................................75Summary ................................................................................................................................................... 77
Chapter 4: Exploring the Desktop .............................................................................................79Desktop Features ..................................................................................................................................... 80
The Top Panel ...................................................................................................................................... 81The Desktop Workspace ..................................................................................................................... 86The Bottom Panel ................................................................................................................................ 87
Modifying the Desktop ........................................................................................................................... 89Adding to the Panel Menus ................................................................................................................ 89Adding Panel Applets ......................................................................................................................... 92Adding Desktop Icons ......................................................................................................................... 96
Desktop Appearance ............................................................................................................................... 97The Desktop Theme ............................................................................................................................ 98The Background .................................................................................................................................. 99Fonts ................................................................................................................................................... 100Interface ............................................................................................................................................. 100Visual Effects ..................................................................................................................................... 101
Accessibility Features .............................................................................................................................101Preferred Applications ...................................................................................................................... 102Keyboard Features ............................................................................................................................ 104Mouse Features ................................................................................................................................. 104
Summary ................................................................................................................................................. 106
Part 2: Starting Out with Ubuntu ................................................................. 107
Chapter 5: File Management .....................................................................................................109The Linux Filesystem .............................................................................................................................110
Filepaths ............................................................................................................................................. 110Filenames ........................................................................................................................................... 113
95080ftoc.indd 12 3/5/09 12:15:52 AM
Contents xiii
Nautilus ....................................................................................................................................................113Nautilus Window Components ......................................................................................................... 113Browser Versus Spatial Mode .......................................................................................................... 119Modifying Nautilus Windows ........................................................................................................... 120
Handling Files ........................................................................................................................................ 125Creating New Files and Folders ....................................................................................................... 125Copying and Moving Files ................................................................................................................ 126Running Programs ............................................................................................................................. 126Deleting Files ..................................................................................................................................... 128
File Properties ........................................................................................................................................ 128Basic Properties ................................................................................................................................. 128Emblems ............................................................................................................................................. 129Permissions ........................................................................................................................................ 130Open With .......................................................................................................................................... 132Notes ................................................................................................................................................... 133
Summary ..................................................................................................................................................133
Chapter 6: Working With Text ..................................................................................................135The gedit Editor ..................................................................................................................................... 136
Starting gedit ..................................................................................................................................... 136Basic gedit Features .......................................................................................................................... 137Setting Preferences............................................................................................................................ 138
The Character Map .................................................................................................................................141The vim Editor .........................................................................................................................................143
The Basics of vim ............................................................................................................................... 143Editing Data ....................................................................................................................................... 145Copy and Paste .................................................................................................................................. 146Search and Substitute ....................................................................................................................... 146
The emacs Editor.....................................................................................................................................147Using emacs on the Console ............................................................................................................. 148Using emacs in GNOME ................................................................................................................... 152
The Tomboy Notes Application ............................................................................................................ 154Starting Tomboy Notes ..................................................................................................................... 154Creating Notes ................................................................................................................................... 155Editing Notes ..................................................................................................................................... 156Organizing Notes .............................................................................................................................. 157Changing Preferences ....................................................................................................................... 157Tomboy Add-ins ................................................................................................................................ 159
Summary ..................................................................................................................................................159
Chapter 7: The OpenOffice Suite .............................................................................................161The OpenOffice.org Suite ......................................................................................................................162Word Processing ......................................................................................................................................163
Writer Features .................................................................................................................................. 163Working with Writer Files ................................................................................................................. 167
Spreadsheets ............................................................................................................................................168The OpenOffice.org Calc Layout ..................................................................................................... 168Working with Calc Files .................................................................................................................... 173
95080ftoc.indd 13 3/5/09 12:15:52 AM
xiv Contents
Presentations ...........................................................................................................................................174Using the Presentation Wizard ......................................................................................................... 174Taking a Tour of OpenOffice.org Impress ....................................................................................... 176Working with Impress Files .............................................................................................................. 179
Database ..................................................................................................................................................180Getting Help from the Wizard .......................................................................................................... 180Taking a Tour of Base ....................................................................................................................... 183Working with Tables ......................................................................................................................... 184
Drawing ...................................................................................................................................................186Taking a Tour of OpenOffice.org Draw ........................................................................................... 186Working with Draw Files .................................................................................................................. 189
Math ........................................................................................................................................................ 190Starting Math ..................................................................................................................................... 190The Math Layout ............................................................................................................................... 191Working with Math ........................................................................................................................... 193
Summary ..................................................................................................................................................195
Chapter 8: Network Applications ............................................................................................197The Ubuntu Internet Software Suite .................................................................................................... 198Ekiga ....................................................................................................................................................... 198Firefox ..................................................................................................................................................... 200
Walking Through Firefox .................................................................................................................. 201Configuring Firefox ........................................................................................................................... 203Working with Add-ons ...................................................................................................................... 210
Pidgin .......................................................................................................................................................212Using the Pidgin Instant Messenger ................................................................................................ 213Pidgin Preferences ............................................................................................................................. 215
Remote Desktop Viewer .........................................................................................................................216Terminal Server Client ...........................................................................................................................218Transmission ........................................................................................................................................... 220gFTP ........................................................................................................................................................ 222Summary ................................................................................................................................................. 224
Chapter 9: Evolution .....................................................................................................................227The Evolution Suite ................................................................................................................................ 228Starting Evolution .................................................................................................................................. 228
Obtain Email Client Info ................................................................................................................... 229Run the Wizard .................................................................................................................................. 229
The Evolution Window .......................................................................................................................... 238The Menu Bar .................................................................................................................................... 238The Toolbar ........................................................................................................................................ 239The Search Tool ................................................................................................................................. 240The Message List ............................................................................................................................... 240The Sidebar ........................................................................................................................................ 242The Switcher ...................................................................................................................................... 242The Preview Pane .............................................................................................................................. 242
95080ftoc.indd 14 3/5/09 12:15:52 AM
Contents xv
Using Evolution ...................................................................................................................................... 242Sending Messages ............................................................................................................................. 242Changing the Configuration ............................................................................................................. 244
Mail Filtering.......................................................................................................................................... 247Filtering Messages ............................................................................................................................ 247Filtering Spam ................................................................................................................................... 249
Backing Up Evolution ............................................................................................................................ 250Using the Address Book ........................................................................................................................ 250Accessing the Calendar and Tasks ...................................................................................................... 252
Calendar ............................................................................................................................................. 252Tasks ................................................................................................................................................... 253
Summary ................................................................................................................................................. 254
Chapter 10: Image Manipulation .............................................................................................255Eye of GNOME Image Viewer .............................................................................................................. 256
Using the Image Viewer ................................................................................................................... 256Supported File Types ........................................................................................................................ 260
The GIMP Image Editor .........................................................................................................................261Starting GIMP .................................................................................................................................... 261GIMP Basic Tools .............................................................................................................................. 261Using GIMP........................................................................................................................................ 263
F-Spot Photo Manager ........................................................................................................................... 268The F-Spot Layout ............................................................................................................................. 268Using the F-Spot Editor ..................................................................................................................... 273
Summary ................................................................................................................................................. 276
Chapter 11: Using Audio .............................................................................................................277Audio File Basics .....................................................................................................................................278Controlling Sound in Ubuntu ............................................................................................................... 279
Sound Preferences ............................................................................................................................. 280The Sound Applet.............................................................................................................................. 282
Rhythmbox ............................................................................................................................................. 284Playing Audio CDs ............................................................................................................................ 284Playing Audio Files ........................................................................................................................... 286Listening to Internet Audio ............................................................................................................... 288Ripping Audio CDs ............................................................................................................................ 289
Brasero .................................................................................................................................................... 290Sound Recorder ...................................................................................................................................... 291Playing Audio Files from Nautilus ....................................................................................................... 292Summary ................................................................................................................................................. 294
Chapter 12: Using Video .............................................................................................................295Video Formats ........................................................................................................................................ 296The Totem Movie Player ........................................................................................................................ 297
The Totem Interface .......................................................................................................................... 298The Totem Preferences Settings....................................................................................................... 301
95080ftoc.indd 15 3/5/09 12:15:52 AM
xvi Contents
Watching Web Clips .............................................................................................................................. 302Checking Your Plug-ins .................................................................................................................... 303Adding Plug-ins ................................................................................................................................. 304More Video Support .......................................................................................................................... 306
Editing Videos ........................................................................................................................................ 307Installing Kino .................................................................................................................................... 308The Kino Interface ............................................................................................................................. 309The Kino Preferences Settings ......................................................................................................... 310
Summary ..................................................................................................................................................311
PART 3: Managing Your Workstation ..........................................................313
Chapter 13: Software Installs and Updates ...........................................................................315Software Management in Ubuntu .........................................................................................................316
Software Packages ............................................................................................................................ 316Software Repositories ........................................................................................................................ 316Configuring Software Repositories .................................................................................................. 317
Installing Updates ...................................................................................................................................319The Update Manager ........................................................................................................................ 319Using the Update Manager Applet .................................................................................................. 321
Installing New Applications ................................................................................................................. 322The Add/Remove Applications Window ......................................................................................... 322Adding a New Application ............................................................................................................... 324Removing an Application .................................................................................................................. 326
Installing New Packages ....................................................................................................................... 327The Synaptic Layout.......................................................................................................................... 328Installing Packages ............................................................................................................................ 331Removing Packages .......................................................................................................................... 333
Command-Line Package Management ............................................................................................... 333Setting Repositories ........................................................................................................................... 333Apt-get Commands ........................................................................................................................... 334
Summary ................................................................................................................................................. 336
Chapter 14: Networking .............................................................................................................337Networking Basics ................................................................................................................................. 338
Internet Connection Types ............................................................................................................... 338Ethernet Connections ........................................................................................................................ 341
Connecting to the Network ................................................................................................................... 343GNOME PPP ...................................................................................................................................... 343Network Manager ............................................................................................................................. 345
Network Tools ......................................................................................................................................... 349Devices ............................................................................................................................................... 350Ping ..................................................................................................................................................... 351Netstat ................................................................................................................................................ 352Traceroute .......................................................................................................................................... 354Port Scan ............................................................................................................................................ 355
95080ftoc.indd 16 3/5/09 12:15:52 AM
Contents xvii
Lookup ................................................................................................................................................ 355Finger ................................................................................................................................................. 357Whois .................................................................................................................................................. 357
Firewalls.................................................................................................................................................. 358Installing Firestarter .......................................................................................................................... 359Starting Firestarter ............................................................................................................................ 360Using Firestarter ................................................................................................................................ 360
Summary ................................................................................................................................................. 364
Chapter 15: External Devices ....................................................................................................367Printers .................................................................................................................................................... 368
The Printer Configuration Tool ........................................................................................................ 368Printer Server Settings ...................................................................................................................... 369Adding a New Printer ....................................................................................................................... 370Modifying Printer Properties ............................................................................................................ 372
Scanners .................................................................................................................................................. 376Detecting the Scanner ....................................................................................................................... 376Scanning a Document ....................................................................................................................... 379The Work Area .................................................................................................................................. 380
Digital Cameras ..................................................................................................................................... 383Portable Music Players .......................................................................................................................... 385Summary ................................................................................................................................................. 386
Chapter 16: The Display ..............................................................................................................387The X Windows System ......................................................................................................................... 388
What Is X Windows?.......................................................................................................................... 388Linux X Windows Software .............................................................................................................. 389The X.Org Configuration .................................................................................................................. 390
Ubuntu Video Configuration ................................................................................................................ 394The Screen Resolution Utility ........................................................................................................... 394Setting Compiz Fusion Features ...................................................................................................... 396Monitor and Video Cards ................................................................................................................. 401
Using 3-D Cards ..................................................................................................................................... 403Ubuntu 3-D Support .......................................................................................................................... 403Viewing Restricted Hardware Drivers ............................................................................................. 404
Summary ................................................................................................................................................. 404
Chapter 17: Users and Groups ................................................................................................. 407The User Administration Tool .............................................................................................................. 408
Adding Users ..................................................................................................................................... 408Modifying Users ................................................................................................................................ 412Deleting Users ................................................................................................................................... 413
Ubuntu Groups ........................................................................................................................................414Adding Groups .................................................................................................................................. 416Modifying Groups ............................................................................................................................. 417Deleting Groups ................................................................................................................................ 418
User and Group Files ..............................................................................................................................418The Users File .................................................................................................................................... 418
95080ftoc.indd 17 3/5/09 12:15:52 AM
xviii Contents
The Groups File ................................................................................................................................. 419Using the Command Line ................................................................................................................. 420
Understanding File Permissions ............................................................................................................421File Properties .................................................................................................................................... 421Changing File Permissions ............................................................................................................... 422
Summary ................................................................................................................................................. 423
Chapter 18: Basic Administration ............................................................................................425Monitoring the System .......................................................................................................................... 426
System ................................................................................................................................................ 426Processes ............................................................................................................................................ 427Resources ........................................................................................................................................... 429File Systems ....................................................................................................................................... 430
Log Files ...................................................................................................................................................431Ubuntu Log Files ............................................................................................................................... 431The System Log Viewer .................................................................................................................... 432
Starting Services .................................................................................................................................... 433Starting and Stopping Services ........................................................................................................ 433Service Properties .............................................................................................................................. 435
Sessions ................................................................................................................................................... 436Startup Programs ............................................................................................................................... 437Options ............................................................................................................................................... 437
Disk Usage Analyzer ............................................................................................................................. 438Summary ................................................................................................................................................. 440
Chapter 19: The Ubuntu Command Line ...............................................................................441The GNOME Terminal Program .......................................................................................................... 442
Session Tabs....................................................................................................................................... 442The Menu Bar .................................................................................................................................... 443The Command-Line Parameters ...................................................................................................... 446
Command-Line Basics ............................................................................................................................447Setting the Command Prompt .......................................................................................................... 447The bash Manual ............................................................................................................................... 449Traversing Directories ....................................................................................................................... 451File and Directory Listing ................................................................................................................. 452File Handling ..................................................................................................................................... 458Directory Handling ............................................................................................................................ 464
Summary ................................................................................................................................................. 466
PART 4: Using the Ubuntu Server ................................................................ 467
Chapter 20: DNS Server ............................................................................................................. 469History of Computer Names ..................................................................................................................470Domain Names ........................................................................................................................................470
DNS Structure .................................................................................................................................... 470Finding Domains ............................................................................................................................... 472
95080ftoc.indd 18 3/5/09 12:15:52 AM
Contents xix
DNS Database Records ..................................................................................................................... 473DNS Protocol ...................................................................................................................................... 478
Ubuntu as a DNS Client .........................................................................................................................478Configuring DNS Client Files ........................................................................................................... 479Ubuntu Client DNS Programs .......................................................................................................... 480
Ubuntu as a DNS Server ....................................................................................................................... 486The named Files ................................................................................................................................ 486Using named as a Local Cache Server ............................................................................................ 488Using named as a Master DNS Server ............................................................................................. 489
Summary ................................................................................................................................................. 492
Chapter 21: Web Server ............................................................................................................. 493Ubuntu Web Servers .............................................................................................................................. 494
Web Scripting Languages ................................................................................................................. 494The LAMP Platform ........................................................................................................................... 498The Tomcat Platform ......................................................................................................................... 498
The Apache Web Server ........................................................................................................................ 499Apache Configuration Files .............................................................................................................. 500Apache Modules ................................................................................................................................ 500Creating Virtual Hosts ...................................................................................................................... 502Testing the Apache Server ............................................................................................................... 503
The MySQL Software ............................................................................................................................ 506Accessing the Server ......................................................................................................................... 506Changing the Root Password ............................................................................................................ 507The phpMyAdmin Tool ..................................................................................................................... 508
The PHP Software ...................................................................................................................................510The PHP Configuration Files ............................................................................................................ 510PHP Extensions .................................................................................................................................. 511Using PHP .......................................................................................................................................... 513
Tomcat ......................................................................................................................................................514Tomcat Configuration ....................................................................................................................... 515Testing Tomcat .................................................................................................................................. 515Managing Tomcat ............................................................................................................................. 518
Summary ................................................................................................................................................. 520
Chapter 22: Samba and Print Server ......................................................................................521What Is Samba? ...................................................................................................................................... 522The Ubuntu Samba Environment ........................................................................................................ 523
Samba Programs ................................................................................................................................ 523Samba Configuration Files ............................................................................................................... 524
Creating a Samba Server .......................................................................................................................531Editing the smb.conf File .................................................................................................................. 531Defining Samba Passwords ............................................................................................................... 532Managing Samba .............................................................................................................................. 533
The Samba Client .................................................................................................................................. 533The smbclient Program ..................................................................................................................... 533Interacting with a Windows Share ................................................................................................... 534
Connecting from Windows ................................................................................................................... 537
95080ftoc.indd 19 3/5/09 12:15:52 AM
xx Contents
The CUPS Print Server .......................................................................................................................... 539Printing in Linux ................................................................................................................................ 539The CUPS Software ........................................................................................................................... 541CUPS Configuration .......................................................................................................................... 541Managing CUPS Printers .................................................................................................................. 542
Summary ................................................................................................................................................. 546
Chapter 23: Email Server ............................................................................................................547How Email Works ................................................................................................................................... 548
Mail Transfer Agent .......................................................................................................................... 549Mail Delivery Agent .......................................................................................................................... 551Mail User Agent ................................................................................................................................ 553
Postfix Setup ........................................................................................................................................... 557Postfix Core Programs ....................................................................................................................... 558Postfix Message Queues ................................................................................................................... 559Postfix Utility Programs ..................................................................................................................... 560Postfix Configuration Files ................................................................................................................ 561Postfix Lookup Tables ....................................................................................................................... 562
Installing Postfix .................................................................................................................................... 563Internet Site........................................................................................................................................ 563Internet with SmartHost .................................................................................................................... 564Satellite System ................................................................................................................................. 565Local Only .......................................................................................................................................... 566
Configuring Postfix ................................................................................................................................ 567Wizard Windows ................................................................................................................................ 566Modifying Configuration Settings .................................................................................................... 573
procmail ...................................................................................................................................................574The .procmailrc File........................................................................................................................... 574Using procmail ................................................................................................................................... 576
Summary ..................................................................................................................................................578
Chapter 24: Database Server ....................................................................................................579The MySQL Server ................................................................................................................................ 580
The MySQL Server Files ................................................................................................................... 580The mysql Command ........................................................................................................................ 585Using mysql ....................................................................................................................................... 588
The PostgreSQL Server ......................................................................................................................... 590The PostgreSQL Files ........................................................................................................................ 591The psql Command ........................................................................................................................... 594Using psql .......................................................................................................................................... 597
Working with Databases ....................................................................................................................... 599Creating a Database .......................................................................................................................... 599Managing Users................................................................................................................................. 600Building Tables .................................................................................................................................. 602Adding and Viewing Data ................................................................................................................ 603
Summary ................................................................................................................................................. 604
95080ftoc.indd 20 3/5/09 12:15:53 AM
Contents xxi
Part 5: Programming in Ubuntu ................................................................... 605
Chapter 25: Shell Scripts .............................................................................................................607Using Multiple Commands ................................................................................................................... 608Creating a Script File ............................................................................................................................. 608Displaying Output ...................................................................................................................................610Using Variables .......................................................................................................................................612
Environment Variables ..................................................................................................................... 612User Variables ................................................................................................................................... 613
The Backtick ............................................................................................................................................615Redirecting Input and Output ...............................................................................................................616
Output Redirection ............................................................................................................................ 616Input Redirection ............................................................................................................................... 617
Pipes .........................................................................................................................................................618Performing Math .................................................................................................................................... 620
The expr Command ........................................................................................................................... 620Using Brackets ................................................................................................................................... 622A Floating-Point Solution .................................................................................................................. 623
Exiting the Script ................................................................................................................................... 626Checking the Exit Status .................................................................................................................. 627The exit Command ............................................................................................................................ 628
Structured Commands .......................................................................................................................... 629The if-then-else Statement ............................................................................................................... 629The test Command ............................................................................................................................ 631
Summary ................................................................................................................................................. 636
Chapter 26: Perl and Python .....................................................................................................637What Is Perl? ........................................................................................................................................... 638Working with Perl .................................................................................................................................. 638
Command-Line Interpreter ............................................................................................................... 639Creating a Perl Program ................................................................................................................... 640
Perl Programming .................................................................................................................................. 640Using Variables in Perl ..................................................................................................................... 641Structured Commands ...................................................................................................................... 644Perl Operators .................................................................................................................................... 646Regular Expressions .......................................................................................................................... 648Perl Command-Line Arguments ...................................................................................................... 650
Perl Modules and CPAN .........................................................................................................................651What Is Python? ...................................................................................................................................... 652Working with Python ............................................................................................................................. 653Programming in Python ........................................................................................................................ 654
Python Variables and Data Structures ............................................................................................. 654Tuples Variables ................................................................................................................................ 655Indentation in Structured Commands .............................................................................................. 656Object-Oriented Programming ......................................................................................................... 657Python Command-Line Arguments ................................................................................................. 657
Python Modules ..................................................................................................................................... 658Summary ................................................................................................................................................. 659
95080ftoc.indd 21 3/5/09 12:15:53 AM
xxii Contents
Chapter 27: C Programming ......................................................................................................661C Programming in Ubuntu ................................................................................................................... 662
The GNU Compiler ........................................................................................................................... 662The GNU Assembler ......................................................................................................................... 665The GNU Linker ................................................................................................................................ 668The GNU Debugger Program ........................................................................................................... 671The GNU objdump Program ............................................................................................................. 674The GNU Profiler Program ............................................................................................................... 676
Writing C Programs ............................................................................................................................... 681C Program Format ............................................................................................................................. 681Sample Program ................................................................................................................................ 684
Summary ................................................................................................................................................. 685
Chapter 28: Java ............................................................................................................................687The Java Development Environment ................................................................................................... 688
Java Programs .................................................................................................................................... 688Platforms............................................................................................................................................. 689
Ubuntu Java Environments................................................................................................................... 690Using OpenJDK ..................................................................................................................................... 691
Installing OpenJDK ........................................................................................................................... 692OpenJDK Components ..................................................................................................................... 692
Java Development Environments ......................................................................................................... 693Command-Line Tools ........................................................................................................................ 694NetBeans ............................................................................................................................................ 703Eclipse ................................................................................................................................................ 707
Summary ..................................................................................................................................................711
Chapter 29: Ruby ..........................................................................................................................713What Is Ruby? ..........................................................................................................................................714
Ruby on the Web ............................................................................................................................... 714Ruby on Rails ..................................................................................................................................... 715
Installing Ruby ........................................................................................................................................715Ruby Components ............................................................................................................................. 715Installing Ruby in Ubuntu ................................................................................................................. 716
Working with Ruby Code .......................................................................................................................719Interactive Ruby................................................................................................................................. 719Scripting with Ruby ........................................................................................................................... 720Embedded Ruby ................................................................................................................................ 721
The Ruby Language ............................................................................................................................... 722Variables ............................................................................................................................................ 722Structured Commands ...................................................................................................................... 725
Object-Oriented Programming ............................................................................................................ 730Creating Classes ................................................................................................................................ 730Using Objects ..................................................................................................................................... 731Adding Methods ................................................................................................................................ 732
95080ftoc.indd 22 3/5/09 12:15:53 AM
Contents xxiii
Ruby on Rails ...........................................................................................................................................732Creating a Project .............................................................................................................................. 733Testing the Project ............................................................................................................................. 736
Summary ................................................................................................................................................. 739
Chapter 30: PHP ............................................................................................................................741What Is PHP? ...........................................................................................................................................742PHP in Ubuntu ........................................................................................................................................743
Core Installation ................................................................................................................................ 743PHP Extensions .................................................................................................................................. 745
Working with PHP ..................................................................................................................................747Defining PHP Code ........................................................................................................................... 747PHP Output ........................................................................................................................................ 749
The PHP Language .................................................................................................................................751PHP Variables .................................................................................................................................... 751Iterating Through Arrays .................................................................................................................. 754Structured Commands ...................................................................................................................... 754Including External Files .................................................................................................................... 756Working with MySQL ....................................................................................................................... 759
Object-Oriented PHP ............................................................................................................................. 760Creating a Class in PHP .................................................................................................................... 761Creating Objects ................................................................................................................................ 761Writing OOP Code in PHP ................................................................................................................ 762Expanding on OOP............................................................................................................................ 763Class Constructors ............................................................................................................................. 765
PECL and PEAR ..................................................................................................................................... 768Summary ................................................................................................................................................. 768
Index .........................................................................................................................................................771
95080ftoc.indd 23 3/5/09 12:15:53 AM
95080flast.indd 24 3/5/09 12:24:43 AM
IntroductionWelcome to Ubuntu Linux Secrets. Like all books in the Secrets series, you can expect to find both hands-on tutorials and real-world practical application information, as well as reference and background information that provides a context for what you are learning. This book is a fairly comprehensive resource on the Ubuntu Linux distribution. By the time you have completed Ubuntu Linux Secrets you will be well-prepared to utilize your Ubuntu workstation or server to its fullest.
Who Should Read This BookIf you’re new to the Linux world, you’ll benefit greatly from this book’s hands-on approach. The book walks through all of the steps required for setting up an Ubuntu Linux system, guiding you through the pitfalls and offering practical advice for getting your Ubuntu workstation up and running. It then walks through all of the applications you’ll find on your new system, showing you how to use the office productivity software; work with images, audio and video clips on your desktop; run CDs and DVDs; and interact with the Internet.
If you’re an advanced Linux enthusiast, you’ll also benefit from Ubuntu Linux Secrets. Nowadays it’s easy to get lost in the graphical world of prebuilt desktop packages. Most desktop Linux distributions try their best to hide the Linux system from the typical user. However, there are times when you have to know what’s going on under the hood. This book shows you how to use the Ubuntu administration features to manage your system, including monitoring programs, users, and disk space. It shows how to access the Linux command-line prompt and what to do once you get there. It also explains how to use your Ubuntu system as a complete program development platform, discussing how to program using shell, Perl, and Python scripts; the C, Java, and Ruby programming languages; and the PHP web-scripting language.
Ubuntu Linux Secrets also walks the seasoned system administrator through how to use the various server software packages included in the Ubuntu server distribution. It dis-cusses how to set up a complete web server using both the LAMP and Tomcat web servers and a database server using the popular MySQL or the feature-rich PostgreSQL database package, how to interact on a Microsoft Windows network using the Samba software, and how to create an email server for your home or organization.
How This Book Is OrganizedThis book is organized to lead you through the basics of the Ubuntu Linux distribution features, from installing your system to using the installed applications. The book is divided into five parts, each one building on the previous parts.
Part 1 starts you out on your Ubuntu Linux journey by helping you get your Ubuntu system running. Chapter 1, “What Is Ubuntu?” walks through the complicated world of Linux distributions, describing why there are so many distributions and what the Ubuntu
95080flast.indd 25 3/5/09 12:24:43 AM
xxvi Introduction
Linux distribution has to offer. After explaining the basics of the Ubuntu system, Part 1 continues with
Downloading and working with the Ubuntu LiveCD (Chapter 2)♦♦
Installing Ubuntu on your PC (Chapter 3)♦♦
Exploring the features of the GNOME desktop (Chapter 4)♦♦
In Part 2, the book takes you through the features you’ll find in the Ubuntu workstation:
Working with files and folders in Ubuntu (Chapter 5)♦♦
Working with text files using the Ubuntu text editors (Chapter 6)♦♦
Using the OpenOffice.org office productivity suite (Chapter 7)♦♦
Becoming familiar with the Ubuntu Network applications (Chapter 8)♦♦
Accessing your email with the Evolution email software (Chapter 9)♦♦
Working with image files (Chapter 10)♦♦
Playing and ripping CDs (Chapter 11)♦♦
Playing DVDs and watching video clips from the Internet (Chapter 12)♦♦
Part 3 shows you how to manage your Ubuntu system:
Installing and updating software packages (Chapter 13)♦♦
Configuring network access (Chapter 14)♦♦
Installing and using external devices such as printers and scanners (Chapter 15)♦♦
Configuring your display and setting up multiple monitors (Chapter 16)♦♦
Adding new users (Chapter 17)♦♦
Controlling running programs and monitoring the system (Chapter 18)♦♦
Using the Ubuntu command line (Chapter 19)♦♦
In Part 4, you’ll see how to install and configure the Ubuntu server packages:
Creating a domain name server (DNS) (Chapter 20)♦♦
Maintaining a web server for dynamic web applications (Chapter 21)♦♦
Using Samba to interact with other devices on a Microsoft Windows network ♦♦
(Chapter 22)Managing a complete email server (Chapter 23)♦♦
Running a full-featured database server using either MySQL or PostgreSQL ♦♦
(Chapter 24)
The last section of the book, Part 5, demonstrates how to use your Ubuntu workstation as a complete programming development environment:
Writing and running shell scripts from the Ubuntu command line (Chapter 25)♦♦
Working with Perl and Python scripts to manipulate data (Chapter 26)♦♦
Using the C programming language to create professional applications ♦♦
(Chapter 27)Installing the Java programming environment to write applications (Chapter 28)♦♦
Installing Ruby to write local and web applications (Chapter 29)♦♦
Using PHP on the Ubuntu LAMP server to write dynamic web applications ♦♦
(Chapter 30)
95080flast.indd 26 3/5/09 12:24:43 AM
Introduction xxvii
Conventions and FeaturesThere are many different organizational and typographical features throughout this book designed to help you get the most of the information.
SecretsWhen the author wants to provide additional information to help you get the most out of your Ubuntu system, the information will appear in a Secrets sidebar, separate from the main chapter material.
Minimum RequirementsTo get the most from the Ubuntu workstation software you must have a PC with at least a 700-MHz processor, 384 MB of system memory (RAM), 8 GB of disk space, and a graph-ics card capable of at least 1024 × 768 resolution. It also helps to have a sound card if you plan on working with audio and video, and a network card if you plan on interacting with a local network or the Internet.
Where to Go from HereOnce you’ve completed Ubuntu Linux Secrets you’ll be well on your way to being an Ubuntu Linux guru. In the ever-changing world of Linux, it’s always a good idea to stay in touch with new developments. The Ubuntu Linux distribution comes out with a new version every 6 months, adding new features and removing some older ones. To keep your knowledge of Ubuntu fresh, it’s important to stay well informed. Find a good Linux forum on the web and monitor what’s going on in the Linux world. There are many popular sites, such as Slashdot and Distrowatch, that provide up-to-the-minute information about advances in Linux. It’s also a good idea to keep an eye on the Ubuntu distribution site itself. Each new release goes through a series of beta releases, which are a great way to be introduced to new features before they’re released in the next version.
The information in the Secrets sidebars is important and is set off in a separate paragraph with a special icon. Secrets provide additional information about things to watch out for, tips on how to better use a feature, or background information that helps in understanding a topic.
95080flast.indd 27 3/5/09 12:24:43 AM
95080flast.indd 28 3/5/09 12:24:43 AM