Ubuntu Unleashed 2010 Edition, 5th Edition

  

  Andrew Hudson

Paul Hudson

Matthew Helmke Ryan Troy

  Ubuntu U N L E A S H E D

  2010 Edition Covering 9.10 and 10.4

  800 East 96th Street, Indianapolis, Indiana 46240 USA Ubuntu Unleashed 2010 Edition: Covering 9.10 and 10.4

  Copyright © 2010 by Sams Publishing All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein.

  ISBN-10: 0-67233-109-8 Library of Congress Cataloging-in-Publication data is on file. Printed in the United States of America First Printing January 2010

  Trademarks

  All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.

  Warning and Disclaimer

  Every effort has been made to make this book as complete and as accurate as possi- ble, but no warranty or fitness is implied. The information provided is on an “as is” basis. The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book or from the use of the CD or programs accompanying it.

  Bulk Sales

  Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. For more information, please contact: U.S. Corporate and Government Sales 1-800-382-3419 corpsales@pearsontechgroup.com For sales outside of the U.S., please contact: International Sales international@pearson.com

  Acquisitions Editor Debra Williams Cauley Development Editor Michael Thurston Managing Editor Patrick Kanouse Project Editor Jennifer Gallant Copy Editor Paula Lowell Indexer Tim Wright Proofreader Leslie Joseph Technical Editor Dallas Releford Publishing Coordinator Kim Boedigheimer Multimedia Developer Dan Scherf Cover and Interior Designer Gary Adair Composition Mark Shirar

ISBN-13: 978-0-67233-109-1

  Contents at a Glance

  Introduction

  1 Part I Installation and Configuration

  1 Installing Ubuntu..........................................................................................11

  2 Post-Installation Configuration ....................................................................25

  3 Working with Gnome ...................................................................................51

  4 Command Line Quickstart ...........................................................................79

  Part II Desktop Ubuntu

  5 On the Internet ...........................................................................................113

  6 Productivity Applications ...........................................................................133

  7 Multimedia Applications ............................................................................153

  8 Printing with Ubuntu .................................................................................185

  9 Games..........................................................................................................197

  Part III System Administration

  10 Managing Users...........................................................................................209

  11 Automating Tasks........................................................................................233

  12 System-Monitoring Tools............................................................................289

  13 Backing Up ..................................................................................................301

  14 Networking..................................................................................................325

  15 Remote Access with SSH and Telnet...........................................................371

  Part IV Ubuntu as a Server

  16 File and Print...............................................................................................381

  17 Apache Web Server Management ...............................................................407

  18 Remote File Serving with FTP .....................................................................439

  19 Handling Electronic Mail............................................................................471

  20 Proxying and Reverse Proxying ..................................................................489

  21 Administering Database Services ................................................................499

  22 LDAP............................................................................................................525

  Part V Programming Linux

  23 Using Perl ....................................................................................................537

  24 Working with Python .................................................................................561

  25 Writing PHP Scripts.....................................................................................579

  26 C/C++ Programming Tools for Ubuntu......................................................613

  27 Mono ...........................................................................................................625

  Part VI Ubuntu Housekeeping

  28 Securing Your Machines .............................................................................639

  29 Performance Tuning....................................................................................651

  30 Command Line Masterclass........................................................................663

  31 Managing Software .....................................................................................689

  32 Kernel and Module Management...............................................................701

  Part VII Appendixes A Ubuntu Under the Hood ............................................................................727 B Installation Resources .................................................................................737 C Ubuntu and Linux Internet Resources .......................................................759 Index ...........................................................................................................769

  Table of Contents

  

  

  

   Researching Your Hardware Specifications .........................................12 Installation Options.............................................................................12 Planning Partition Strategies ...............................................................12 The Boot Loader ..................................................................................13 Installing from CD or DVD .................................................................13

   Starting the Install ...............................................................................14 First Update..........................................................................................20 Wubi—The Easy Installer for Windows ..............................................22 Shutting Down ....................................................................................24

  

  

  

  Changing the Desktop Background ....................................................34 Changing Colors..................................................................................35 Modifying System Fonts ......................................................................36 Changing How Menus Look ...............................................................36 Visual Effects........................................................................................37

   Preferred Applications .........................................................................37 Removable Drives and Media..............................................................39

   Keyboard Shortcuts..............................................................................40 Keyboard Layout..................................................................................40 Mouse...................................................................................................41

   Configuring a Serial-Port Modem .......................................................42 Configuring WinModems for Laptops ................................................42

  

  Using the date Command ...................................................................45 Using the hwclock Command ............................................................45 Changing the Time and Date..............................................................46

   Checking Drive Assignment................................................................47

  

  

   Gnome: The GNU Network Object Model Environment...................52

  

  Elements of the xorg.conf File ............................................................57 Configuring X......................................................................................62

   Using a Display Manager.....................................................................65 Changing Window Managers..............................................................73

  

  

  

   Navigating Through the File System...................................................83 Managing Files with the Shell .............................................................85 Working with Compressed Files..........................................................86 Use Essential Commands from the /bin and /sbin Directories ..........87 Use and Edit Files in the /etc Directory ..............................................87 Protect the Contents of User Directories—/home ..............................87 Use the Contents of the /proc Directory to Interact with the Kernel..................................................................................87 Work with Shared Data in the /usr Directory.....................................89 Temporary File Storage in the /tmp Directory....................................89 Access Variable Data Files in the /var Directory .................................89

   Text-based Console Login....................................................................90 Logging Out .........................................................................................90

  Ubuntu Unleashed 2008 Edition

  Logging In and Out from a Remote Computer ..................................91 Using Environment Variables..............................................................92

   Working with vi...................................................................................96 Working with emacs............................................................................97

   Assigning Permissions .......................................................................100 Directory Permissions ........................................................................101 Understanding Set User ID and Set Group ID Permissions ..............103

   Creating Users....................................................................................105 Deleting Users....................................................................................106 Shutting Down the System ...............................................................106 Rebooting the System........................................................................107

   Using Man Pages................................................................................108

  

  

  

  

  Evolution ...........................................................................................116 Mozilla Thunderbird..........................................................................118 KMail..................................................................................................120 Other Mail Clients .............................................................................120

   Firefox ................................................................................................122 Liferea.................................................................................................122

  

  

  Configuring OpenOffice.org .............................................................136 Working with OpenOffice.org Writer ...............................................137 Working with OpenOffice.org Calc...................................................140

  Contents

  Ubuntu Unleashed 2008 Edition

  Working with Gnome Office.............................................................146 Working with KOffice........................................................................149

  

  

   Sound Cards.......................................................................................154 Adjusting Volume ..............................................................................155 Sound Formats ...................................................................................156 Listening to Music .............................................................................157

   The GNU Image Manipulation Program...........................................163 Using Scanners in Ubuntu ................................................................164 Working with Graphics Formats .......................................................166 Capturing Screen Images ...................................................................168

   Handheld Digital Cameras ................................................................168 Using F-Spot.......................................................................................169

   Creating CDs and DVDs with Ubuntu’s Graphical Clients..............172 Creating CDs from the Command Line ...........................................174 Creating DVDs from the Command Line.........................................176

   TV and Video Hardware ....................................................................178 Video Formats ....................................................................................180 Viewing Video in Linux.....................................................................181 Personal Video Recorders ..................................................................181 DVD and Video Players .....................................................................182

  

  

  

  GUI-Based Printer Configuration Quickstart ....................................187 Managing Printing Services ...............................................................188

   Creating the Print Queue ..................................................................190 Editing Printer Settings......................................................................192

  

  Contents

  

   Installing Proprietary Video Drivers..................................................198

   DOOM 3 ............................................................................................200 Unreal Tournament 2004 ..................................................................201 Quake 4 ..............................................................................................202 Wolfenstein: Enemy Territory ...........................................................203 Battle for Wesnoth.............................................................................204

  

  

  

   The Super User/Root User .................................................................210 User IDs and Group IDs ....................................................................212 File Permissions .................................................................................212

   Group Management Tools.................................................................214

   User Management Tools ....................................................................216 Adding New Users .............................................................................218 Monitoring User Activity on the System ..........................................219

   System Password Policy .....................................................................220 The Password File ..............................................................................220 Shadow Passwords .............................................................................221 Managing Password Security for Users..............................................223 Changing Passwords in a Batch ........................................................224

   Temporarily Changing User Identity with the su Command ..........225 Granting Root Privileges on Occasion—The sudo Command .........227

   Implementing Quotas .......................................................................230 Manually Configuring Quotas ..........................................................230

  

  Ubuntu Unleashed 2008 Edition

  

  

  Loading the Linux Kernel..................................................................235 System Services and Runlevels ..........................................................236 Runlevel Definitions..........................................................................236 Booting into the Default Runlevel ....................................................237 Booting to a Non-Default Runlevel with GRUB ...............................237 Understanding init Scripts and the Final Stage of Initialization......238 Controlling Services at Boot with Administrative Tools ..................239 Changing Runlevels...........................................................................240 Troubleshooting Runlevel Problems .................................................240

  

  Using at and batch to Schedule Tasks for Later ................................242 Using cron to Run Jobs Repeatedly...................................................245

   The Shell Command Line .................................................................248 Shell Pattern-Matching Support ........................................................250 Redirecting Input and Output...........................................................251 Piping Data ........................................................................................252 Background Processing ......................................................................252

   Running the New Shell Program.......................................................254 Storing Shell Scripts for Systemwide Access......................................255 Interpreting Shell Scripts Through Specific Shells ............................256 Using Variables in Shell Scripts .........................................................258 Assigning a Value to a Variable .........................................................258 Accessing Variable Values ..................................................................259 Positional Parameters ........................................................................259 A Simple Example of a Positional Parameter ....................................259 Using Positional Parameters to Access and Retrieve

  Variables from the Command Line ................................................260 Using a Simple Script to Automate Tasks..........................................261 Built-In Variables ...............................................................................263 Special Characters..............................................................................263 Use Double Quotes to Resolve Variables in Strings with

  Embedded Spaces ............................................................................264 Using Single Quotes to Maintain Unexpanded Variables ................265 Using the Backslash as an Escape Character.....................................266 Using the Backtick to Replace a String with Output ........................266 Comparison of Expressions in pdksh and bash................................267

  Contents Comparing Expressions with tcsh.....................................................272 The for Statement ..............................................................................276 The while Statement..........................................................................277 The until Statement...........................................................................279 The repeat Statement (tcsh) ..............................................................280 The select Statement (pdksh) ............................................................280 The shift Statement ...........................................................................281 The if Statement ................................................................................281 The case Statement ............................................................................283 The break and exit Statements ..........................................................285 Using Functions in Shell Scripts........................................................285

  

  

   Using the kill Command to Control Processes.................................291 Using Priority Scheduling and Control.............................................292 Displaying Free and Used Memory with free ...................................294 Disk Space ..........................................................................................295 Disk Quotas........................................................................................296

  

  

   Why Data Loss Occurs.......................................................................302 Assessing Your Backup Needs and Resources ....................................303 Evaluating Backup Strategies .............................................................304 Making the Choice ............................................................................307

   Removable Storage Media .................................................................308 Network Storage.................................................................................309 Tape Drive Backup .............................................................................309

   tar: The Most Basic Backup Tool .......................................................310 The GNOME File Roller .....................................................................312 Using the Amanda Backup Application ............................................315 Alternative Backup Software..............................................................316

   Copying Files Using tar .....................................................................317 Compressing, Encrypting, and Sending tar Streams ........................317

  Ubuntu Unleashed 2008 Edition Copying Files Using cp......................................................................318 Copying Files Using mc.....................................................................318

   The Ubuntu Rescue Disc....................................................................320 Backing Up and Restoring the Master Boot Record..........................320 Booting the System from a Generic Boot Floppy .............................320 Using a GRUB Boot Floppy ...............................................................321 Using the Recovery Facility ...............................................................322

  

  

   Checking for the Availability of the Loopback Interface .................326 Configuring the Loopback Interface Manually ................................326

   TCP/IP Addressing .............................................................................329 Using IP Masquerading in Ubuntu ...................................................331 Ports ...................................................................................................332

   Subnetting..........................................................................................333 Subnet Masks .....................................................................................334 Broadcast, Unicast, and Multicast Addressing ..................................334

   Network Interface Cards....................................................................335 Network Cable ...................................................................................337 Hubs and Switches.............................................................................338 Routers and Bridges ...........................................................................339 Initializing New Network Hardware..................................................339

   Command-Line Network Interface Configuration ...........................342 Network Configuration Files .............................................................347 Using Graphical Configuration Tools ...............................................349

   How DHCP Works .............................................................................351 Activating DHCP at Installation and Boot Time ..............................352 DHCP Software Installation and Configuration ...............................353 Using DHCP to Configure Network Hosts ........................................354 Other Uses for DHCP.........................................................................357

   Support for Wireless Networking in Ubuntu ....................................357 Advantages of Wireless Networking..................................................358 Choosing from Among Available Wireless Protocols .......................359

  

  

   Creating a CUPS Printer Entry ..........................................................400

  Enabling Network Printing on a LAN ...............................................397 Session Message Block Printing .........................................................398

  

   Manually Configuring Samba with /etc/samba/smb.conf................387 Testing Samba with the testparm Command ...................................390 Starting the smbd Daemon ...............................................................390 Mounting Samba Shares ....................................................................391 Configuring Samba Using SWAT.......................................................392

   Installing and Starting or Stopping NFS ...........................................382 NFS Server Configuration ..................................................................383 NFS Client Configuration..................................................................384

  

  VNC....................................................................................................378

  Understanding Point-to-Point Protocol over Ethernet .....................363 Configuring a PPPoE Connection Manually.....................................363

  XDMCP ..............................................................................................377

  

  Using scp to Copy Individual Files Between Machines....................374 Using sftp to Copy Many Files Between Machines ..........................374 Using ssh-keygen to Enable Key-based Logins..................................375

  

  

   Configuring a Dial-Up Connection Manually ..................................365

  Contents

  Ubuntu Unleashed 2008 Edition

  All-in-One (Print/Fax/Scan) Devices .................................................403 Using USB and Legacy Printers .........................................................403

  

  

  Installing with APT............................................................................409 Building the Source Yourself .............................................................410

   Starting the Apache Server Manually................................................413 Using /etc/init.d/apache2 ..................................................................414

   Runtime Configuration Directives ....................................................416 Editing apache2.conf .........................................................................417 Apache Multiprocessing Modules .....................................................419 Using .htaccess Configuration Files ..................................................420

   Restricting Access with allow and deny............................................422 Authentication...................................................................................423 Final Words on Access Control .........................................................425

   mod_access ........................................................................................427 mod_alias ...........................................................................................427 mod_asis ............................................................................................427 mod_auth...........................................................................................428 mod_auth_anon.................................................................................428 mod_auth_dbm .................................................................................428 mod_auth_digest ...............................................................................428 mod_autoindex..................................................................................429 mod_cgi..............................................................................................429 mod_dir and mod_env ......................................................................429 mod_expires.......................................................................................429 mod_headers......................................................................................429 mod_include ......................................................................................429 mod_info and mod_log_config .........................................................430 mod_mime and mod_mime_magic ..................................................430 mod_negotiation ...............................................................................430 mod_proxy.........................................................................................430 mod_rewrite .......................................................................................430 mod_setenvif .....................................................................................430

  Contents mod_speling.......................................................................................431 mod_status.........................................................................................431 mod_ssl ..............................................................................................431 mod_unique_id..................................................................................431 mod_userdir .......................................................................................431 mod_usertrack....................................................................................431 mod_vhost_alias ................................................................................431

   Address-Based Virtual Hosts ..............................................................432 Name-Based Virtual Hosts .................................................................432

  

  Sun ONE Web Server .........................................................................436 Zope ...................................................................................................436 Zeus Web Server.................................................................................436

  

  

  Choosing an Authenticated or Anonymous Server ..........................440 Ubuntu FTP Server Packages .............................................................440 Other FTP Servers ..............................................................................440

  

  Starting the Very Secure FTP Server (vsftpd) Package .......................445

  Controlling Anonymous Access ........................................................445 Other vsftpd Server Configuration Files ...........................................446

  

  Configure Access Control..................................................................449 Configure User Information..............................................................452 Configure System Logging ................................................................456 Configure Permission Control ..........................................................457 Configure Commands Directed Toward the cdpath.........................459 Structure of the shutdown File..........................................................460

   Strip Prefix .........................................................................................461 Strip Postfix........................................................................................461 Add-On Prefix ....................................................................................461 Add-On Postfix ..................................................................................461

  Ubuntu Unleashed 2008 Edition External Command ...........................................................................461 An Example of Conversions in Action..............................................462

  

  Display Information About Connected Users...................................464 Count the Number of Connections ..................................................465 Use /usr/sbin/ftpshut to Schedule FTP Server Downtime ................466 Use /var/log/xferlog to View a Log of Server Transactions...............467

  

  

   The Mail Transport Agent..................................................................472 Choosing an MTA..............................................................................474 The Mail Delivery Agent ...................................................................474 The Mail User Agent ..........................................................................475

   Configuring Masquerading ...............................................................477 Using Smart Hosts .............................................................................477 Setting Message Delivery Intervals....................................................477 Mail Relaying .....................................................................................478 Forwarding Email with Aliases ..........................................................478

   Installing Fetchmail...........................................................................479 Configuring Fetchmail ......................................................................480

   Procmail .............................................................................................483 Spamassassin......................................................................................484 Squirrelmail........................................................................................484 Virus Scanners....................................................................................484

  

  Microsoft Exchange Server/Outlook Client ......................................486 CommuniGate Pro.............................................................................486 Oracle Collaboration Suite ................................................................486 Bynari.................................................................................................486 Open-Xchange ...................................................................................486 phpgroupware....................................................................................487 PHProjekt ...........................................................................................487 Horde .................................................................................................487

  

  Contents

  

  

  How Relational Databases Work .......................................................501 Understanding SQL Basics.................................................................503 Creating Tables ..................................................................................503 Inserting Data into Tables .................................................................504 Retrieving Data from a Database.......................................................505

   Speed ..................................................................................................507 Data Locking......................................................................................508 ACID Compliance in Transaction Processing to Protect Data Integrity .................................................................509 SQL Subqueries ..................................................................................509 Procedural Languages and Triggers ...................................................510

   Setting a Password for the MySQL Root User ...................................511 Creating a Database in MySQL .........................................................511 Granting and Revoking Privileges in MySQL ...................................512

   Initializing the Data Directory in PostgreSQL ..................................514 Creating a Database in PostgreSQL ...................................................515 Creating Database Users in PostgreSQL ............................................516 Deleting Database Users in PostgreSQL ............................................517 Granting and Revoking Privileges in PostgreSQL .............................517

   SSH Access to a Database...................................................................518 Local GUI Client Access to a Database .............................................520 Web Access to a Database..................................................................520 The MySQL Command-Line Client ..................................................521 The PostgreSQL Command-Line Client ............................................523 Graphical Clients ...............................................................................523

  

  Ubuntu Unleashed 2008 Edition

  

   Populating Your Directory.................................................................528

   Evolution ...........................................................................................531 Thunderbird.......................................................................................532

  

  

  

   Perl Versions ......................................................................................538 A Simple Perl Program.......................................................................538

   Perl Variable Types.............................................................................540 Special Variables.................................................................................541

   Comparison Operators ......................................................................542 Compound Operators........................................................................543 Arithmetic Operators .........................................................................544 Other Operators .................................................................................544 Special String Constants ....................................................................545

   if .........................................................................................................546 unless .................................................................................................546

   for.......................................................................................................547 foreach ...............................................................................................547 while ..................................................................................................548 until ...................................................................................................548 last and next ......................................................................................548 do ... while and do ... until ...............................................................549

  

  Sending Mail ......................................................................................552 Purging Logs ......................................................................................554 Posting to Usenet...............................................................................555

  Contents One-Liners .........................................................................................556 Command-Line Processing................................................................556

  

  

   Getting Interactive.............................................................................562

   Numbers.............................................................................................563 More on Strings .................................................................................564 Lists ....................................................................................................567 Dictionaries........................................................................................569 Conditionals and Looping ................................................................570

  

  Class and Object Variables ................................................................574 Constructors and Destructors............................................................575 Class Inheritance ...............................................................................575

  

  

   Entering and Exiting PHP Mode .......................................................580 Variables.............................................................................................580 Arrays .................................................................................................582 Constants ...........................................................................................584 References ..........................................................................................584 Comments .........................................................................................585 Escape Sequences ...............................................................................585 Variable Substitution .........................................................................587 Operators ...........................................................................................587 Conditional Statements.....................................................................589 Special Operators ...............................................................................591 Switching ...........................................................................................592 Loops..................................................................................................593 Including Other Files.........................................................................596

   Strings ................................................................................................596 Arrays .................................................................................................600 Files ....................................................................................................602 Miscellaneous.....................................................................................604

  

  The Structure of a C# Program..........................................................628 Printing Out the Parameters..............................................................629 Creating Your Own Variables ............................................................629 Adding Some Error Checking ............................................................630

  Securing a Wireless Network .............................................................642 Passwords and Physical Security .......................................................643 Configuring and Using Tripwire .......................................................644 Devices ...............................................................................................645

  

  

  

  

   Searching with Beagle........................................................................631 Creating a GUI with Gtk# .................................................................634

  

  Introduction to PEAR::DB .................................................................608

  

  

  Using the KDevelop Client................................................................620 The Glade Client for Developing in GNOME...................................621

  

   Building Programs with make ...........................................................615 Using Makefiles..................................................................................615 Using the autoconf Utility to Configure Code .................................617 Managing Software Projects with Subversion ...................................617 Debugging Tools ................................................................................618