Linux Bible (Christopher Negus) (Z-Library)
Author: Christopher Negus
科学
Reference and reference book on various topics of the use of a desktop or the configuration of servers. Everything that covers many topics certainly fails at the tangent of detail, quality, and top-notch insights.
📄 File Format:
PDF
💾 File Size:
24.8 MB
5
Views
0
Downloads
0.00
Total Donations
📄 Text Preview (First 20 pages)
ℹ️
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
📄 Page
1
(This page has no text content)
📄 Page
2
(This page has no text content)
📄 Page
3
ffi rs.indd 04/02/2015 Page i Linux® Bible Ninth Edition
📄 Page
4
(This page has no text content)
📄 Page
5
ffi rs.indd 04/02/2015 Page iii Linux® BIBLE Ninth Edition Christopher Negus
📄 Page
6
ffi rs.indd 04/02/2015 Page iv Linux® Bible, Ninth Edition Published by John Wiley & Sons, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2015 by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-1-118-99987-5 ISBN: 978-1-118-99989-9 (ebk) ISBN: 978-1-118-99988-2 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/ permissions. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEB SITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com. Library of Congress Control Number: 2015937667 Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Linux is a registered trademark of Linus Torvalds. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.
📄 Page
7
ffi rs.indd 04/02/2015 Page v As always, I dedicate this book to my wife, Sheree.
📄 Page
8
ffi rs.indd 04/02/2015 Page vi
📄 Page
9
ffi rs.indd 04/02/2015 Page vii About the Author Chris Negus is a Red Hat Certifi ed Instructor (RHCI), Red Hat Certifi ed Examiner (RHCX), Red Hat Certifi ed Architect (RHCA), and Principal Technical Writer for Red Hat Inc. In more than six years with Red Hat, Chris has taught hundreds of IT professionals aspiring to become Red Hat Certifi ed Engineers (RHCE). In his current position at Red Hat, Chris produces articles for the Red Hat Customer Portal. The projects he works on include Red Hat Enterprise Linux 7, Red Hat Enterprise OpenStack Platform, Red Hat Enterprise Virtualization and Linux containers in Docker format. Besides his RHCA certifi cation, Chris is a Red Hat Certifi ed Virtualization Administrator (RHCVA) and Red Hat Certifi ed Datacenter Specialist (RHCDS). He also has certifi cates of expertise in Deployment and Systems Management, Clustering and Storage Management, Cloud Storage, and Server Hardening. Before joining Red Hat, Chris wrote or co-wrote dozens of books on Linux and UNIX, includ- ing Red Hat Linux Bible (all editions), CentOS Bible, Fedora Bible, Linux Troubleshooting Bible, Linux Toys and Linux Toys II. Chris also co-authored several books for the Linux Toolbox series for power users: Fedora Linux Toolbox, SUSE Linux Toolbox, Ubuntu Linux Toolbox, Mac OS X Toolbox, and BSD UNIX Toolbox. For eight years Chris worked with the organization at AT&T that developed UNIX before moving to Utah to help contribute to Novell’s UnixWare project in the early 1990s. When not writing about Linux, Chris enjoys playing soccer and just hanging out with his wife, Sheree, and son, Seth. About the Technical Editor Richard Blum, LPIC-1, has worked in the IT industry for more than 20 years as both a systems and network administrator and has published numerous Linux and open source books. He has administered UNIX, Linux, Novell, and Microsoft servers, as well as helped design and maintain a 3,500-user network utilizing Cisco switches and routers. He has used Linux servers and shell scripts to perform automated network monitoring and has written shell scripts in most of the common Linux shell environments. Rich is an online instruc- tor for an Introduction to Linux course that is used by colleges and universities across the United States. When he isn’t being a computer nerd, Rich plays electric bass in a couple of different church worship bands, and enjoys spending time with his wife, Barbara, and two daughters, Katie Jane and Jessica.
📄 Page
10
(This page has no text content)
📄 Page
11
ffi rs.indd 04/02/2015 Page ix Credits Project Editor Martin V. Minner Technical Editor Richard Blum Production Manager Kathleen Wisor Copy Editor Gwenette Gaddis Manager of Content Development & Assembly Mary Beth Wakefield Marketing Director David Mayhew Marketing Manager Carrie Sherrill Professional Technology & Strategy Director Barry Pruett Business Manager Amy Knies Associate Publisher Jim Minatel Project Coordinator, Cover Brent Savage Proofreader Amy Schneider Indexer John Sleeva Cover Designer Wiley
📄 Page
12
(This page has no text content)
📄 Page
13
xi ffi rs.indd 04/02/2015 Page xi S ince I was hired by Red Hat Inc. more than six years ago, I have been exposed to many of the best Linux developers, testers, support professionals and instructors in the world. Since I can’t thank everyone individually, I instead salute the culture of cooperation and excellence that serves to improve my own Linux skills every day. I don’t speak well of Red Hat because I work there; I work at Red Hat because it lives up to the ideals of open source software in ways that match my own beliefs. There are a few people at Red Hat I would like to acknowledge particularly. Discussions with Victor Costea, Andrew Blum, and other Red Hat instructors have helped me adapt my ways of thinking about how people learn Linux. I’m able to work across a wide range of technologies because of the great support I get from my supervisor, Adam Strong, and my senior manager, Sam Knuth, who both point me toward cool projects but never hold me back. In this edition, particular help came from Ryan Sawhill Aroha, who helped me simplify my writing on encryption technology. For the new content I wrote in this book on Linux cloud technologies, I’d like to thank members of OpenStack, Docker, and RHEV teams, who help me learn cutting-edge cloud technology every day. As for the people at Wiley, thanks for letting me continue to develop and improve this book over the years. Marty Minner has helped keep me on task through a demanding schedule. Mary Beth Wakefi eld and Ken Brown have been there to remind me at the times I forgot it was a demanding schedule. Thanks to Richard Blum for his reliably thorough job of tech editing. Thanks to Margot Maley Hutchison from Waterside Productions for contracting the book for me with Wiley and always looking out for my best interests. Finally, thanks to my wife, Sheree, for sharing her life with me and doing such a great job raising Seth and Caleb. Acknowledgments
📄 Page
14
(This page has no text content)
📄 Page
15
xiii ffi rs.indd 04/02/2015 Page xiii Acknowledgments ........................................................................................................ xi Introduction .......................................................................................................... xxxiii Part I: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 1: Starting with Linux ....................................................................................... 3 Chapter 2: Creating the Perfect Linux Desktop ............................................................... 29 Part II: Becoming a Linux Power User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Chapter 3: Using the Shell ............................................................................................ 65 Chapter 4: Moving around the Filesystem ...................................................................... 97 Chapter 5: Working with Text Files ............................................................................... 117 Chapter 6: Managing Running Processes .......................................................................137 Chapter 7: Writing Simple Shell Scripts .........................................................................153 Part III: Becoming a Linux System Administrator . . . . . . . . . . . . . . . . . . . . 171 Chapter 8: Learning System Administration .................................................................173 Chapter 9: Installing Linux .........................................................................................201 Chapter 10: Getting and Managing Software ................................................................233 Chapter 11: Managing User Accounts ...........................................................................259 Chapter 12: Managing Disks and Filesystems ................................................................283 Part IV: Becoming a Linux Server Administrator . . . . . . . . . . . . . . . . . . . . 313 Chapter 13: Understanding Server Administration ........................................................315 Chapter 14: Administering Networking ........................................................................347 Chapter 15: Starting and Stopping Services ..................................................................377 Chapter 16: Confi guring a Print Server .........................................................................423 Chapter 17: Confi guring a Web Server ..........................................................................449 Chapter 18: Confi guring an FTP Server .........................................................................477 Chapter 19: Confi guring a Windows File Sharing (Samba) Server ....................................499 Chapter 20: Confi guring an NFS File Server ..................................................................527 Chapter 21: Troubleshooting Linux ..............................................................................551 Part V: Learning Linux Security Techniques . . . . . . . . . . . . . . . . . . . . . . . . 589 Chapter 22: Understanding Basic Linux Security ..........................................................591 Chapter 23: Understanding Advanced Linux Security ....................................................627 Chapter 24: Enhancing Linux Security with SELinux ....................................................669 Chapter 25: Securing Linux on a Network.....................................................................699 Contents at a Glance
📄 Page
16
xiv ffi rs.indd 04/02/2015 Page xiv Part VI: Extending Linux into the Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . 727 Chapter 26: Using Linux for Cloud Computing ...............................................................729 Chapter 27: Deploying Linux to the Cloud .................................................................... 749 Part VII: Appendixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769 Appendix A: Media .....................................................................................................771 Appendix B: Exercise Answers.....................................................................................781 Index ........................................................................................................................839
📄 Page
17
xv ftoc.indd 04/02/2015 Page xv Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxiii Part I: Getting Started 1 Chapter 1: Starting with Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Understanding What Linux Is ................................................................................ 4 Understanding How Linux Differs from Other Operating Systems .............................. 6 Exploring Linux History ........................................................................................ 6 Free-fl owing UNIX culture at Bell Labs ........................................................... 7 Commercialized UNIX ................................................................................... 9 Berkeley Software Distribution arrives .................................................. 9 UNIX Laboratory and commercialization .............................................. 10 GNU transitions UNIX to freedom .................................................................11 BSD loses some steam ................................................................................. 13 Linus builds the missing piece .................................................................... 13 OSI open source defi nition .......................................................................... 14 Understanding How Linux Distributions Emerged .................................................. 16 Choosing a Red Hat distribution .................................................................. 17 Using Red Hat Enterprise Linux .......................................................... 17 Using Fedora...................................................................................... 18 Choosing Ubuntu or another Debian distribution .......................................... 19 Finding Professional Opportunities with Linux Today ............................................ 20 Understanding how companies make money with Linux ................................ 21 Becoming Red Hat certifi ed ......................................................................... 22 RHCSA topics ..................................................................................... 23 RHCE topics ....................................................................................... 24 Summary ............................................................................................................ 26 Chapter 2: Creating the Perfect Linux Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Understanding Linux Desktop Technology ............................................................ 30 Starting with the Fedora GNOME Desktop Live image ..................................................................................................... 32 Using the GNOME 3 Desktop ................................................................................. 33 After the computer boots up ....................................................................... 33 Navigating with the mouse ................................................................. 34 Contents
📄 Page
18
xvi Contents ftoc.indd 04/02/2015 Page xvi Navigating with the keyboard ............................................................. 38 Setting up the GNOME 3 desktop ...................................................................41 Extending the GNOME 3 desktop .................................................................. 42 Using GNOME shell extensions ............................................................. 42 Using the GNOME Tweak Tool ............................................................... 44 Starting with desktop applications .............................................................. 45 Managing fi les and folders with Nautilus ............................................. 45 Installing and managing additional software ....................................... 46 Playing music with Rhythmbox .......................................................... 48 Stopping the GNOME 3 desktop .................................................................... 49 Using the GNOME 2 Desktop ................................................................................. 49 Using the Metacity window manager ............................................................ 50 Changing GNOME’s appearance ..................................................................... 52 Using the GNOME panels .............................................................................. 53 Using the Applications and System menus ........................................... 54 Adding an applet ............................................................................... 54 Adding another panel ........................................................................ 55 Adding an application launcher .......................................................... 55 Adding a drawer ................................................................................ 56 Changing panel properties .................................................................. 57 Adding 3D effects with AIGLX ..................................................................... 58 Summary ............................................................................................................ 60 Exercises .............................................................................................................61 Part II: Becoming a Linux Power User 63 Chapter 3: Using the Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 About Shells and Terminal Windows ..................................................................... 66 Using the shell prompt ................................................................................ 67 Using a terminal window ............................................................................ 68 Using virtual consoles ................................................................................ 69 Choosing Your Shell ............................................................................................. 69 Running Commands ............................................................................................ 70 Understanding command syntax .................................................................. 71 Locating commands .....................................................................................74 Recalling Commands Using Command History.........................................................76 Command-line editing ................................................................................ 77 Command-line completion ........................................................................... 79 Command-line recall ................................................................................... 80 Connecting and Expanding Commands .................................................................. 82 Piping between commands .......................................................................... 82 Sequential commands ................................................................................. 83 Background commands ............................................................................... 83 Expanding commands ................................................................................. 84
📄 Page
19
xvii Contents ftoc.indd 04/02/2015 Page xvii Expanding arithmetic expressions ............................................................... 84 Expanding variables ................................................................................... 85 Using Shell Variables ........................................................................................... 85 Creating and using aliases ........................................................................... 87 Exiting the shell ......................................................................................... 88 Creating Your Shell Environment .......................................................................... 88 Confi guring your shell ................................................................................ 88 Setting your prompt ................................................................................... 89 Adding environment variables ..................................................................... 91 Getting Information about Commands .................................................................. 92 Summary ............................................................................................................ 94 Exercises ............................................................................................................ 95 Chapter 4: Moving around the Filesystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Using Basic Filesystem Commands .......................................................................100 Using Metacharacters and Operators ....................................................................102 Using fi le-matching metacharacters ............................................................102 Using fi le-redirection metacharacters .........................................................103 Using brace expansion characters ...............................................................105 Listing Files and Directories ...............................................................................105 Understanding File Permissions and Ownership ....................................................109 Changing permissions with chmod (numbers) .............................................. 111 Changing permissions with chmod (letters) ................................................. 111 Setting default fi le permission with umask .................................................112 Changing fi le ownership.............................................................................113 Moving, Copying, and Removing Files ..................................................................114 Summary ...........................................................................................................115 Exercises ...........................................................................................................115 Chapter 5: Working with Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Editing Files with vim and vi .............................................................................. 117 Starting with vi ........................................................................................119 Adding text ......................................................................................119 Moving around in the text .................................................................120 Deleting, copying, and changing text .................................................121 Pasting (putting) text .......................................................................122 Repeating commands ........................................................................122 Exiting vi .........................................................................................122 Skipping around in the fi le ........................................................................123 Searching for text .....................................................................................124 Using ex mode ...........................................................................................124 Learning more about vi and vim .................................................................124 Finding Files......................................................................................................125 Using locate to fi nd fi les by name ...............................................................125
📄 Page
20
xviii Contents ftoc.indd 04/02/2015 Page xviii Searching for fi les with fi nd .......................................................................127 Finding fi les by name ........................................................................127 Finding fi les by size ..........................................................................128 Finding fi les by user..........................................................................128 Finding fi les by permission ................................................................129 Finding fi les by date and time ...........................................................130 Using ‘not’ and ‘or’ when fi nding fi les .................................................131 Finding fi les and executing commands ...............................................131 Searching in fi les with grep........................................................................132 Summary ...........................................................................................................134 Exercises ...........................................................................................................134 Chapter 6: Managing Running Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Understanding Processes ....................................................................................137 Listing Processes ...............................................................................................138 Listing processes with ps ...........................................................................138 Listing and changing processes with top .....................................................140 Listing processes with System Monitor ........................................................142 Managing Background and Foreground Processes ..................................................144 Starting background processes ...................................................................144 Using foreground and background commands ..............................................145 Killing and Renicing Processes ............................................................................146 Killing processes with kill and killall ..........................................................146 Using kill to signal processes by PID ...................................................147 Using killall to signal processes by name ............................................148 Setting processor priority with nice and renice ...........................................148 Limiting Processes with cgroups..........................................................................149 Summary ...........................................................................................................151 Exercises ...........................................................................................................151 Chapter 7: Writing Simple Shell Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Understanding Shell Scripts ................................................................................153 Executing and debugging shell scripts ........................................................154 Understanding shell variables ....................................................................154 Special shell positional parameters .....................................................156 Reading in parameters ......................................................................157 Parameter expansion in bash .............................................................157 Performing arithmetic in shell scripts .........................................................158 Using programming constructs in shell scripts.............................................159 The “if…then” statements .................................................................159 The case command ............................................................................162 The “for…do” loop ............................................................................163 The “while…do” and “until…do” loops ...............................................164 Trying some useful text manipulation programs ..........................................164 The general regular expression parser .................................................165
The above is a preview of the first 20 pages. Register to read the complete e-book.