Linux Systems Administrators
*100072* *100072* COIT 13146 Systems Administration (An Introduction to Linux Systems Administration) Study Guide Systems Administration Edition 2003 ã Copyright (Study Guide) Central Queensland University, 2003 Developed by staff of the Faculty of Informatics and Comminication Produced and printed by the Distance and Flexible Learning Centre Central Queensland University Rockhampton, Queensland Copyright material herin is reproduced under the provision of the Copyright Act 1968 Material copied with the permission of thecopyright holder has been duely identified DEVELOPED BY David Jones, Kieren Jamieson, Damien Clark, Nathaniel Fitzgerald-Hood and Anthony Ferguson Chapter 19 The Overview 19 Introduction 19 Other Resources 19 The Course 20 LAMENT OF A LINUX STUDENT 20 THE RATIONALE 21 WHAT YOU WILL LEARN 21 WHY NOT WINDOWS? .23 Course Material 23 STUDY GUIDE 24 THE COURSE WEBSITE 24 Solving Problems 24 Computers in the Real World 24 WHAT YOU THINK COMPUTERS ARE 24 SOME ALTERNATIVES 26 An Overview of Linux 28 BOOTING 28 RUNNING 29 SHUTTING DOWN .30 LAYERS .30 Conclusions 32 Chapter 33 The What, Why and How of Sys Admin 33 Introduction 33 What Systems Administrators 33 WHY WE NEED THEM 34 WHAT THEY DO 34 Home and the real world 37 What Systems Administrators need to know 37 Why UNIX? 39 Unix past, present and future 40 Linux 40 The relationship between Linux and UNIX 41 Some more sys admin theory 41 Daily operations 42 AUTOMATE, AUTOMATE AND AUTOMATE 42 SYSTEM MONITORING .42 Hardware and software 43 EVALUATION 43 PURCHASE .44 INSTALLATION 44 HARDWARE .44 DOCUMENTATION .45 Policy 48 PENALTIES 48 TYPES OF POLICY 48 CREATING POLICY .48 Code of ethics 49 SAGE-AU CODE OF ETHICS 49 SAGE-AU CODE OF ETHICS 49 People skills 50 COMMUNICATING WITH USERS 50 HOW NOT TO COMMUNICATE WITH USERS .53 Conclusions 53 Chapter 54 Information Sources and Problem Solving 54 Introduction 54 Other resources 54 Information sources 54 Professional organisations 55 THE SAGE GROUPS 55 SAGE-AU 55 UNIX USER GROUPS .56 THE ACS, ACM AND IEEE 56 Books and magazines 56 BIBLIOGRAPHIES .57 O'REILLY BOOKS .57 MAGAZINES 57 Internet resources 57 THE COURSE WEBSITE .57 HOW TO USE THE INTERNET 58 SOFTWARE ON THE INTERNET 58 DISCUSSION FORUMS 58 JUST THE FAQS 59 GOOGLE 60 MAILING LISTS 60 OTHER DISCUSSION FORUMS .60 INTERNET BASED LINUX RESOURCES 62 Problem solving 63 GUIDELINES FOR SOLVING PROBLEMS .63 EXAMPLES OF SOLVING PROBLEMS 64 Conclusions 65 Review questions 65 Chapter 66 Using UNIX 66 Introduction 66 Other resources 66 What you need to learn 66 Introductory UNIX 67 WHY DO I NEED TO KNOW THE COMMAND LINE? 68 HOW DO I LEARN ALL THIS STUFF? 68 UNIX COMMANDS ARE PROGRAMS 69 vi 69 AN INTRODUCTION TO VI 70 UNIX commands 72 PHILOSOPHY OF UNIX COMMANDS 72 UNIX COMMAND FORMAT 73 A COMMAND FOR EVERYTHING .74 Online help 74 USING THE MANUAL PAGES .75 IS THERE A MAN PAGE FOR .75 MAN PAGE FORMAT .76 HTML VERSIONS OF MANUAL PAGES 76 Some UNIX commands 76 IDENTIFICATION COMMANDS 77 SIMPLE COMMANDS 78 FILTERS 78 Getting more out of filters 83 Conclusions 84 Chapter 85 The File Hierarchy 85 Introduction 85 WHY? .85 The important sections 86 THE ROOT OF THE PROBLEM 86 Homes for users 87 EVERY USER NEEDS A HOME 87 OTHER HOMES? .87 /usr and /var 88 AND THE DIFFERENCE IS 88 /USR/LOCAL 89 LIB, INCLUDE AND SRC 89 /VAR/SPOOL 90 X-WINDOWS .90 Bins 91 WHICH BIN? 91 /BIN 91 /SBIN 91 /USR/BIN 93 /USR/LOCAL/BIN 93 Configuration files, logs and other bits! 93 ETC ETC ETC 93 LOGS 94 /PROC 94 /DEV 94 Conclusion 94 FUTURE STANDARDS 94 Review questions 95 Chapter 96 Processes and Files 96 Introduction 96 Other resources 96 Multiple users 96 IDENTIFYING USERS 97 USERS AND GROUPS 97 NAMES AND NUMBERS 97 ID 98 Commands and processes 98 WHERE ARE THE COMMANDS? 98 WHICH 98 WHY CAN'T I RUN MY SHELL SCRIPT? .99 WHEN IS A COMMAND NOT A COMMAND? 99 WHY SHELL COMMANDS ARE FASTER THAN OTHER COMMANDS .100 Controlling processes 100 VIEWING EXISTING PROCESSES .101 JOB CONTROL 105 MANIPULATING PROCESSES 106 Process attributes 109 PARENT PROCESSES .109 PROCESS UID AND GID 109 REAL UID AND GID .109 EFFECTIVE UID AND GID .109 Files 110 FILE TYPES 111 TYPES OF NORMAL FILES 111 FILE ATTRIBUTES 112 VIEWING FILE ATTRIBUTES .113 File protection 114 FILE OPERATIONS 114 USERS, GROUPS AND OTHERS 115 THREE SETS OF FILE PERMISSIONS 116 SPECIAL PERMISSIONS .116 Effective UID and GID 117 SETUID AND SETGID 118 Numeric permissions 118 SYMBOLIC TO NUMERIC 119 Changing file permissions 120 CHMOD 120 CHOWN 121 CHGRP 121 CHOWN AND CHGRP 121 DEFAULT PERMISSIONS 122 File permissions and directories 124 FOR EXAMPLE 124 WHAT HAPPENS IF? 124 Links 125 CREATING LINKS .125 HARD AND SOFT LINKS, THE DIFFERENCES 127 Searching the file hierarchy 128 THE FIND COMMAND .128 Performing commands on many files 133 FIND AND -EXEC .134 FIND AND BACK QUOTES 134 FIND AND XARGS .135 Conclusion 135 Review questions 136 Chapter 138 The Shell 138 Introduction 138 Executing commands 138 DIFFERENT SHELLS 139 STARTING A SHELL 139 Parsing the command line 140 The command line 141 ARGUMENTS 141 ONE COMMAND TO A LINE .142 COMMANDS IN THE BACKGROUND 142 Filename substitution 143 Removing special meaning 144 Input/output redirection 146 HOW IT WORKS .146 FILE DESCRIPTORS 146 STANDARD FILE DESCRIPTORS 147 CHANGING DIRECTION 147 USING STANDARD I/O .148 FILTERS 148 I/O REDIRECTION EXAMPLES 149 REDIRECTING STANDARD ERROR 149 EVALUATING FROM LEFT TO RIGHT 150 Everything is a file 151 TTY 151 DEVICE FILES 151 REDIRECTING I/O TO DEVICE FILES 152 Shell variables 153 ENVIRONMENT CONTROL 153 THE SET COMMAND 153 Using shell variables 153 ASSIGNING A VALUE .153 UNINITIALISED VARIABLES .154 RESETTING A VARIABLE 154 THE READONLY COMMAND 154 THE UNSET COMMAND 154 ARITHMETIC 155 THE EXPR COMMAND 155 ALTERNATIVES TO EXPR FOR ARITHMETIC 156 Valid variable names 156 {} 156 Environment control 156 PS1 AND PS2 157 BASH EXTENSIONS .157 Variables and sub-shells 158 FOR EXAMPLE 158 EXPORT 158 LOCAL VARIABLES 158 Advanced variable substitution 159 Brace expansion 159 Evaluation order 161 WHY ORDER IS IMPORTANT .161 THE ORDER .162 The eval command 162 DOING IT TWICE 162 Conclusion 163 Review questions 163 Chapter 165 Text Manipulation 165 Introduction 165 Other resources 165 Regular expressions 165 RES VERSUS FILENAME SUBSTITUTION AND BRACE EXPANSION 166 HOW THEY WORK 168 Repetition, repetition… rep-i-tition… 168 Concatenation and Alternation 170 Different commands, different REs 170 Tagging 170 FOR EXAMPLE 171 ex, ed, sed and vi 171 SO??? 172 WHY USE ED? 172 ED COMMANDS 172 FOR EXAMPLE 174 THE SED COMMAND 175 SED COMMAND FORMAT 175 Understanding complex commands 176 Conclusions 177 Review questions 177 Chapter 178 Shell Programming 178 Introduction 178 SHELL PROGRAMMING - WHY? 178 SHELL PROGRAMMING - WHAT? 178 SHELL PROGRAMMING - HOW? 179 The basics 179 A BASIC PROGRAM 179 AN EXPLANATION OF THE PROGRAM .180 All you ever wanted to know about variables 182 WHY? .182 PREDEFINED VARIABLES 183 PARAMETERS - SPECIAL SHELL VARIABLES .184 ONLY NINE PARAMETERS? 185 THE DIFFERENCE BETWEEN $* AND $@ 186 The basics of Input/Output (I/O) 187 And now for the hard bits 189 SCENARIO .189 IF THEN MAYBE? .190 TESTING TESTING 191 EXPRESSIONS, EXPRESSIONS! 192 ALL ABOUT CASE .194 LOOPS AND REPEATED ACTION COMMANDS 194 WHILE 195 FOR 195 MODIFYING SCANIT 196 PROBLEMS WITH RUNNING SCANIT 196 SO WHAT IS HAPPENING 198 Speed and shell scripts 200 WHAT'S THE MISTAKE .200 SOLUTION IN C 200 SHELL SOLUTION WRITTEN BY C PROGRAMMER .201 SHELL SOLUTION BY SHELL PROGRAMMER .201 COMPARING THE SOLUTIONS 201 THE PROBLEM 202 A SOLUTION FOR SCANIT? .202 NUMBER OF PROCESSES 202 until 203 BREAK AND CONTINUE 203 REDIRECTION 204 Now for the really hard bits 205 FUNCTIONAL FUNCTIONS 205 LOCAL 206 THE RETURN TRIP .206 Difficult and not compulsory 207 RECURSION: (SEE "RECURSION") 207 WAIT'ING AND TRAP'ING 208 Bugs and Debugging 212 METHOD - SET .212 METHOD – ECHO 212 SOME EXAMPLES OF SOME VERY COMMON MISTAKES 212 And now for the really, really hard bits 213 WRITING GOOD SHELL PROGRAMS 213 EVAL THE WONDERFUL! 214 Step-by-step 217 THE PROBLEM 217 SOLVING THE PROBLEM 218 THE FINAL PROGRAM - A LISTING 226 Conclusions 229 Review questions 229 References 230 Chapter 231 Users 231 Introduction 231 Other resources 231 What is a UNIX account? 231 LOGIN NAMES 232 PASSWORDS 233 THE UID 233 HOME DIRECTORIES 234 LOGIN SHELL 234 ... The Linux Installation and Getting Started Guides contain some good overview material The Overview of a Linux System from the Linux Systems Administration Guide is also useful As is the Linux. .. 33 What Systems Administrators 33 WHY WE NEED THEM 34 WHAT THEY DO 34 Home and the real world 37 What Systems Administrators. .. will be to The Linux Documentation Project (The LDP) The LDP is a collaborative project by many people throughout the Linux community to develop high quality documentation about the Linux system