*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
L
AMENT OF A
L
INUX
S
TUDENT
.................................................................................20
T
HE RATIONALE
........................................................................................................21
W
HAT YOU WILL LEARN
............................................................................................21
W
HY NOT
W
INDOWS
?...............................................................................................23
Course Material ............................................................................................................................................................................. 23
S
TUDY
G
UIDE
...........................................................................................................24
T
HE
C
OURSE
W
EBSITE
..............................................................................................24
Solving Problems .......................................................................................................................................................................... 24
Computers in the Real World ........................................................................................................................................................ 24
W
HAT YOU THINK COMPUTERS ARE
..........................................................................24
S
OME ALTERNATIVES
................................................................................................26
An Overview of Linux................................................................................................................................................................... 28
B
OOTING
...................................................................................................................28
R
UNNING
..................................................................................................................29
S
HUTTING DOWN
.......................................................................................................30
L
AYERS
.....................................................................................................................30
Conclusions...................................................................................................................................................................................32
Chapter ............................................................................................................................................................................. 33
The What, Why and How of Sys Admin .......................................................................................................................................33
Introduction...................................................................................................................................................................................33
What Systems Administrators do .................................................................................................................................................. 33
W
HY WE NEED THEM
................................................................................................34
W
HAT 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
A
UTOMATE
,
AUTOMATE AND AUTOMATE
.................................................................42
S
YSTEM MONITORING
...............................................................................................42
Hardware and software.................................................................................................................................................................. 43
E
VALUATION
............................................................................................................43
P
URCHASE
.................................................................................................................44
I
NSTALLATION
..........................................................................................................44
H
ARDWARE
...............................................................................................................44
D
OCUMENTATION
.....................................................................................................45
Policy ............................................................................................................................................................................................48
P
ENALTIES
................................................................................................................48
T
YPES OF
P
OLICY
......................................................................................................48
C
REATING POLICY
.....................................................................................................48
Code of ethics................................................................................................................................................................................ 49
SAGE-AU
CODE OF ETHICS
......................................................................................49
SAGE-AU
CODE OF ETHICS
......................................................................................49
People skills .................................................................................................................................................................................. 50
C
OMMUNICATING WITH
U
SERS
.................................................................................50
H
OW 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
T
HE
SAGE
GROUPS
..................................................................................................55
S
AGE
-
AU
...................................................................................................................55
UNIX U
SER GROUPS
.................................................................................................56
T
HE
ACS, ACM
AND
IEEE......................................................................................56
Books and magazines ....................................................................................................................................................................56
B
IBLIOGRAPHIES
.......................................................................................................57
O'R
EILLY BOOKS
.......................................................................................................57
M
AGAZINES
..............................................................................................................57
Internet resources .......................................................................................................................................................................... 57
T
HE COURSE WEBSITE
...............................................................................................57
H
OW TO USE THE
I
NTERNET
......................................................................................58
S
OFTWARE ON THE
I
NTERNET
...................................................................................58
D
ISCUSSION FORUMS
................................................................................................58
J
UST THE
FAQ
S
........................................................................................................59
G
OOGLE
....................................................................................................................60
M
AILING LISTS
..........................................................................................................60
O
THER DISCUSSION FORUMS
.....................................................................................60
I
NTERNET BASED
L
INUX RESOURCES
........................................................................62
Problem solving............................................................................................................................................................................. 63
G
UIDELINES FOR SOLVING PROBLEMS
.......................................................................63
E
XAMPLES 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
W
HY DO
I
NEED TO KNOW THE COMMAND LINE
? ......................................................68
H
OW DO
I
LEARN ALL THIS STUFF
? ...........................................................................68
UNIX C
OMMANDS ARE PROGRAMS
..........................................................................69
vi.................................................................................................................................................................................................. 69
A
N INTRODUCTION TO
VI
...........................................................................................70
UNIX commands........................................................................................................................................................................... 72
P
HILOSOPHY OF
UNIX
COMMANDS
..........................................................................72
UNIX
COMMAND FORMAT
........................................................................................73
A
COMMAND FOR EVERYTHING
.................................................................................74
Online help .................................................................................................................................................................................... 74
U
SING THE MANUAL PAGES
.......................................................................................75
I
S THERE A MAN PAGE FOR
... .....................................................................................75
MAN PAGE FORMAT
.....................................................................................................76
HTML
VERSIONS OF
M
ANUAL
P
AGES
......................................................................76
Some UNIX commands................................................................................................................................................................. 76
I
DENTIFICATION
C
OMMANDS
....................................................................................77
S
IMPLE COMMANDS
..................................................................................................78
F
ILTERS
.....................................................................................................................78
Getting more out of filters ............................................................................................................................................................. 83
Conclusions...................................................................................................................................................................................84
Chapter ............................................................................................................................................................................. 85
The File Hierarchy.........................................................................................................................................................................85
Introduction...................................................................................................................................................................................85
W
HY
? .......................................................................................................................85
The important sections .................................................................................................................................................................. 86
T
HE ROOT OF THE PROBLEM
......................................................................................86
Homes for users............................................................................................................................................................................. 87
E
VERY USER NEEDS A HOME
... ..................................................................................87
O
THER HOMES
?.........................................................................................................87
/usr
and
/var
........................................................................................................................................................... 88
A
ND THE DIFFERENCE IS
............................................................................................88
/
USR
/
LOCAL
..............................................................................................................89
LIB
,
INCLUDE AND SRC
..............................................................................................89
/
VAR
/
SPOOL
..............................................................................................................90
X-W
INDOWS
.............................................................................................................90
Bins ............................................................................................................................................................................................... 91
W
HICH BIN
? ..............................................................................................................91
/
BIN
...........................................................................................................................91
/
SBIN
.........................................................................................................................91
/
USR
/
BIN
....................................................................................................................93
/
USR
/
LOCAL
/
BIN
..........................................................................................................93
Configuration files, logs and other bits!.........................................................................................................................................93
ETC ETC ETC
. .............................................................................................................93
L
OGS
.........................................................................................................................94
/
PROC
........................................................................................................................94
/
DEV
.........................................................................................................................94
Conclusion..................................................................................................................................................................................... 94
F
UTURE STANDARDS
.................................................................................................94
Review questions........................................................................................................................................................................... 95
Chapter ............................................................................................................................................................................. 96
Processes and Files........................................................................................................................................................................ 96
Introduction...................................................................................................................................................................................96
Other resources.............................................................................................................................................................................. 96
Multiple users................................................................................................................................................................................ 96
I
DENTIFYING USERS
..................................................................................................97
U
SERS AND GROUPS
..................................................................................................97
N
AMES AND NUMBERS
..............................................................................................97
ID
..............................................................................................................................98
Commands and processes.............................................................................................................................................................. 98
W
HERE ARE THE COMMANDS
? ..................................................................................98
WHICH
........................................................................................................................98
W
HY CAN
'
T
I
RUN MY SHELL SCRIPT
? .......................................................................99
W
HEN IS A COMMAND NOT A COMMAND
? .................................................................99
W
HY SHELL COMMANDS ARE FASTER THAN OTHER COMMANDS
.............................100
Controlling processes .................................................................................................................................................................. 100
V
IEWING EXISTING PROCESSES
...............................................................................101
J
OB CONTROL
..........................................................................................................105
M
ANIPULATING PROCESSES
....................................................................................106
Process attributes......................................................................................................................................................................... 109
P
ARENT PROCESSES
.................................................................................................109
P
ROCESS
UID
AND
GID..........................................................................................109
R
EAL
UID
AND
GID ...............................................................................................109
E
FFECTIVE
UID
AND
GID.......................................................................................109
Files............................................................................................................................................................................................. 110
F
ILE TYPES
..............................................................................................................111
T
YPES OF NORMAL FILES
.........................................................................................111
F
ILE ATTRIBUTES
....................................................................................................112
V
IEWING FILE ATTRIBUTES
.....................................................................................113
File protection ............................................................................................................................................................................. 114
F
ILE OPERATIONS
....................................................................................................114
U
SERS
,
GROUPS AND OTHERS
..................................................................................115
T
HREE SETS OF FILE PERMISSIONS
...........................................................................116
S
PECIAL PERMISSIONS
.............................................................................................116
Effective UID and GID ............................................................................................................................................................... 117
SETUID AND SETGID
................................................................................................118
Numeric permissions................................................................................................................................................................... 118
S
YMBOLIC TO NUMERIC
..........................................................................................119
Changing file permissions ........................................................................................................................................................... 120
CHMOD
......................................................................................................................120
CHOWN
......................................................................................................................121
CHGRP
......................................................................................................................121
CHOWN AND CHGRP
....................................................................................................121
D
EFAULT PERMISSIONS
...........................................................................................122
File permissions and directories .................................................................................................................................................. 124
F
OR EXAMPLE
.........................................................................................................124
W
HAT HAPPENS IF
? .................................................................................................124
Links ........................................................................................................................................................................................... 125
C
REATING LINKS
.....................................................................................................125
H
ARD AND SOFT LINKS
,
THE DIFFERENCES
..............................................................127
Searching the file hierarchy......................................................................................................................................................... 128
T
HE FIND COMMAND
...............................................................................................128
Performing commands on many files .......................................................................................................................................... 133
F
IND AND
-
EXEC
.....................................................................................................134
F
IND AND BACK QUOTES
.........................................................................................134
F
IND AND XARGS
.....................................................................................................135
Conclusion................................................................................................................................................................................... 135
Review questions......................................................................................................................................................................... 136
Chapter ........................................................................................................................................................................... 138
The Shell ..................................................................................................................................................................................... 138
Introduction................................................................................................................................................................................. 138
Executing commands................................................................................................................................................................... 138
D
IFFERENT SHELLS
.................................................................................................139
S
TARTING A SHELL
..................................................................................................139
Parsing the command line............................................................................................................................................................140
The command line....................................................................................................................................................................... 141
A
RGUMENTS
...........................................................................................................141
O
NE COMMAND TO A LINE
.......................................................................................142
C
OMMANDS IN THE BACKGROUND
..........................................................................142
Filename substitution................................................................................................................................................................... 143
Removing special meaning.......................................................................................................................................................... 144
Input/output redirection............................................................................................................................................................... 146
H
OW IT WORKS
.......................................................................................................146
F
ILE DESCRIPTORS
..................................................................................................146
S
TANDARD FILE DESCRIPTORS
................................................................................147
C
HANGING DIRECTION
............................................................................................147
U
SING STANDARD
I/O .............................................................................................148
F
ILTERS
...................................................................................................................148
I/O
REDIRECTION EXAMPLES
...................................................................................149
R
EDIRECTING STANDARD ERROR
............................................................................149
E
VALUATING FROM LEFT TO RIGHT
.........................................................................150
Everything is a file ...................................................................................................................................................................... 151
TTY
...........................................................................................................................151
D
EVICE FILES
..........................................................................................................151
R
EDIRECTING
I/O
TO DEVICE FILES
.........................................................................152
Shell variables ............................................................................................................................................................................. 153
E
NVIRONMENT CONTROL
........................................................................................153
T
HE
SET
COMMAND
..................................................................................................153
Using shell variables.................................................................................................................................................................... 153
A
SSIGNING A VALUE
...............................................................................................153
U
NINITIALISED VARIABLES
.....................................................................................154
R
ESETTING A VARIABLE
..........................................................................................154
T
HE
READONLY
COMMAND
..........................................................................................154
T
HE
UNSET
COMMAND
..............................................................................................154
A
RITHMETIC
...........................................................................................................155
T
HE
EXPR
COMMAND
................................................................................................155
A
LTERNATIVES 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
F
OR EXAMPLE
.........................................................................................................158
EXPORT
......................................................................................................................158
L
OCAL VARIABLES
..................................................................................................158
Advanced variable substitution.................................................................................................................................................... 159
Brace expansion .......................................................................................................................................................................... 159
Evaluation order .......................................................................................................................................................................... 161
W
HY ORDER IS IMPORTANT
.....................................................................................161
T
HE ORDER
.............................................................................................................162
The
eval
command ........................................................................................................................................................... 162
D
OING IT TWICE
......................................................................................................162
Conclusion................................................................................................................................................................................... 163
Review questions......................................................................................................................................................................... 163
Chapter ........................................................................................................................................................................... 165
Text Manipulation ....................................................................................................................................................................... 165
Introduction................................................................................................................................................................................. 165
Other resources............................................................................................................................................................................ 165
Regular expressions..................................................................................................................................................................... 165
RE
S VERSUS FILENAME SUBSTITUTION AND BRACE EXPANSION
..............................166
H
OW THEY WORK
....................................................................................................168
Repetition, repetition… rep-i-tition… ......................................................................................................................................... 168
Concatenation and Alternation ....................................................................................................................................................170
Different commands, different REs............................................................................................................................................. 170
Tagging ....................................................................................................................................................................................... 170
F
OR EXAMPLE
.........................................................................................................171
ex
,
ed
,
sed
and
vi
.............................................................................................................................................................. 171
S
O
???......................................................................................................................172
W
HY USE
ED
?...........................................................................................................172
ED COMMANDS
........................................................................................................172
F
OR EXAMPLE
.........................................................................................................174
T
HE
SED
COMMAND
..................................................................................................175
SED
COMMAND FORMAT
...........................................................................................175
Understanding complex commands............................................................................................................................................. 176
Conclusions................................................................................................................................................................................. 177
Review questions......................................................................................................................................................................... 177
Chapter ........................................................................................................................................................................... 178
Shell Programming...................................................................................................................................................................... 178
Introduction................................................................................................................................................................................. 178
S
HELL PROGRAMMING
- WHY?..............................................................................178
S
HELL PROGRAMMING
- WHAT? ...........................................................................178
S
HELL PROGRAMMING
- HOW?..............................................................................179
The basics.................................................................................................................................................................................... 179
A
BASIC PROGRAM
..................................................................................................179
A
N EXPLANATION OF THE PROGRAM
.......................................................................180
All you ever wanted to know about variables.............................................................................................................................. 182
W
HY
? .....................................................................................................................182
P
REDEFINED VARIABLES
.........................................................................................183
P
ARAMETERS
-
SPECIAL SHELL VARIABLES
.............................................................184
O
NLY NINE PARAMETERS
? ......................................................................................185
T
HE DIFFERENCE BETWEEN
$*
AND
$@ ..................................................................186
The basics of Input/Output (I/O) ................................................................................................................................................. 187
And now for the hard bits............................................................................................................................................................ 189
S
CENARIO
...............................................................................................................189
IF
...
THEN
...
MAYBE
? .............................................................................................190
T
ESTING TESTING
....................................................................................................191
E
XPRESSIONS
,
EXPRESSIONS
!..................................................................................192
A
LL ABOUT CASE
.....................................................................................................194
L
OOPS AND REPEATED ACTION COMMANDS
............................................................194
WHILE
......................................................................................................................195
FOR
..........................................................................................................................195
M
ODIFYING SCANIT
................................................................................................196
P
ROBLEMS WITH RUNNING SCANIT
..........................................................................196
S
O WHAT IS HAPPENING
..........................................................................................198
Speed and shell scripts................................................................................................................................................................. 200
W
HAT
'
S THE MISTAKE
.............................................................................................200
S
OLUTION IN
C........................................................................................................200
S
HELL SOLUTION WRITTEN BY
C
PROGRAMMER
.....................................................201
S
HELL SOLUTION BY SHELL PROGRAMMER
.............................................................201
C
OMPARING THE SOLUTIONS
...................................................................................201
T
HE PROBLEM
.........................................................................................................202
A
SOLUTION FOR SCANIT
?.......................................................................................202
N
UMBER OF PROCESSES
..........................................................................................202
until......................................................................................................................................................................................... 203
BREAK AND CONTINUE
..............................................................................................203
R
EDIRECTION
..........................................................................................................204
Now for the really hard bits......................................................................................................................................................... 205
F
UNCTIONAL FUNCTIONS
........................................................................................205
LOCAL
......................................................................................................................206
T
HE RETURN TRIP
.....................................................................................................206
Difficult and not compulsory....................................................................................................................................................... 207
R
ECURSION
: (
SEE
"R
ECURSION
") ............................................................................207
WAIT
'
ING AND TRAP
'
ING
...........................................................................................208
Bugs and Debugging ................................................................................................................................................................... 212
M
ETHOD
1 -
SET
.....................................................................................................212
M
ETHOD
2 –
ECHO
...................................................................................................212
S
OME
E
XAMPLES OF
S
OME
V
ERY
C
OMMON
M
ISTAKES
..........................................212
And now for the really, really hard bits ....................................................................................................................................... 213
W
RITING GOOD SHELL PROGRAMS
..........................................................................213
EVAL THE WONDERFUL
! ...........................................................................................214
Step-by-step................................................................................................................................................................................. 217
T
HE PROBLEM
.........................................................................................................217
S
OLVING THE PROBLEM
..........................................................................................218
T
HE 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
L
OGIN NAMES
.........................................................................................................232
P
ASSWORDS
............................................................................................................233
T
HE
UID.................................................................................................................233
H
OME DIRECTORIES
................................................................................................234
L
OGIN SHELL
...........................................................................................................234
D
OT FILES
...............................................................................................................234
S
KELETON DIRECTORIES
.........................................................................................236
T
HE MAIL FILE
........................................................................................................236
M
AIL ALIASES
.........................................................................................................236
Account configuration files ......................................................................................................................................................... 238
Everyone can read /etc/passwd ............................................................................................................................................ 239
T
HIS IS A PROBLEM
..................................................................................................239
P
ASSWORD MATCHING
............................................................................................239
T
HE SOLUTION
........................................................................................................239
S
HADOW FILE FORMAT
............................................................................................240
Groups......................................................................................................................................................................................... 240
S
HADOW
P
ASSWORDS FOR
G
ROUPS
........................................................................240
L
IMITING USERS ACCESS BY GROUPS
.......................................................................241
T
HE DEFAULT GROUP
..............................................................................................241
O
THER GROUPS
.......................................................................................................241
U
SER PRIVATE GROUPS
...........................................................................................241
Special accounts ..........................................................................................................................................................................242
R
ESTRICTED ACTIONS
.............................................................................................242
B
E CAREFUL
............................................................................................................242
The mechanics............................................................................................................................................................................. 243
O
THER CONSIDERATIONS
........................................................................................243
P
RE
-
REQUISITE
I
NFORMATION
................................................................................243
A
DDING AN
/
ETC
/
PASSWD ENTRY
...........................................................................244
T
HE INITIAL PASSWORD
..........................................................................................244
/
ETC
/
GROUP ENTRY
................................................................................................244
T
HE HOME DIRECTORY
............................................................................................245
T
HE STARTUP FILES
.................................................................................................245
O
NE COMMAND TO RULE THEM ALL
........................................................................245
S
ETTING UP MAIL
....................................................................................................246
T
ESTING AN ACCOUNT
............................................................................................247
I
NFORM THE USER
...................................................................................................248
Removing an account .................................................................................................................................................................. 249
D
ISABLING AN ACCOUNT
........................................................................................249
The Goals of Account Creation ................................................................................................................................................... 250
Making it simple.......................................................................................................................................................................... 250
USERADD
..................................................................................................................250
USERDEL AND USERMOD
............................................................................................250
G
RAPHICAL TOOLS
..................................................................................................250
Automation.................................................................................................................................................................................. 251
G
ATHERING THE INFORMATION
...............................................................................251
P
OLICY
....................................................................................................................251
C
REATING THE ACCOUNTS
......................................................................................251
A
DDITIONAL STEPS
.................................................................................................252
C
HANGING PASSWORDS WITHOUT INTERACTION
.....................................................252
Delegation ................................................................................................................................................................................... 252
Allocating root privilege.............................................................................................................................................................. 252
SUDO ADVANTAGES
................................................................................................254
Conclusions................................................................................................................................................................................. 255
Review questions......................................................................................................................................................................... 255
References................................................................................................................................................................................... 256
Chapter ............................................................................................................................................................... 257
Managing File Systems ............................................................................................................................................................... 257
Introduction................................................................................................................................................................................. 257
W
HAT
? ...................................................................................................................257
W
HY
? .....................................................................................................................257
Other resources............................................................................................................................................................................ 258
A scenario.................................................................................................................................................................................... 258
Devices - Gateways to the kernel ................................................................................................................................................ 258
A
DEVICE IS
... .........................................................................................................258
D
EVICE FILES ARE
... ................................................................................................259
D
EVICE DRIVERS ARE
..............................................................................................259
/
DEV
.......................................................................................................................259
P
HYSICAL CHARACTERISTICS OF DEVICE FILES
.......................................................260
M
AJOR AND MINOR DEVICE NUMBERS ARE
... ..........................................................261
F
INDING THE DEVICES ON YOUR SYSTEM
.................................................................261
W
HY USE DEVICE FILES
? .........................................................................................263
C
REATING DEVICE FILES
.........................................................................................264
T
HE USE AND ABUSE OF DEVICE FILES
.....................................................................265
Devices, Partitions and File systems............................................................................................................................................ 266
D
EVICE FILES AND PARTITIONS
...............................................................................266
P
ARTITIONS AND FILE SYSTEMS
..............................................................................267
P
ARTITIONS AND
B
LOCKS
.......................................................................................268
U
SING THE PARTITIONS
...........................................................................................268
T
HE
V
IRTUAL
F
ILE
S
YSTEM
....................................................................................269
D
IVIDING UP THE FILE HIERARCHY
-
WHY
? .............................................................269
S
CENARIO
U
PDATE
.................................................................................................271
The Linux Native File System - ext3 ........................................................................................................................................ 272
O
VERVIEW
..............................................................................................................272
I-N
ODES
..................................................................................................................273
P
HYSICAL
S
TRUCTURE AND
F
EATURES
...................................................................274
Journaling.................................................................................................................................................................................... 275
A
DVANTAGES OF JOURNALING
................................................................................275
T
YPES OF JOURNALING
............................................................................................276
H
OW DOES JOURNALING WORK
? .............................................................................276
Creating file systems ................................................................................................................................................................... 278
MKFS
........................................................................................................................278
S
CENARIO
U
PDATE
.................................................................................................279
L
OGICAL
V
OLUME
M
ANAGEMENT
..........................................................................280
Mounting & UN-mounting Partitions & Devices ........................................................................................................................ 281
MOUNT
......................................................................................................................281
UMOUNT
....................................................................................................................282
M
OUNTING WITH THE
/
ETC
/
FSTAB FILE
.................................................................283
S
CENARIO
U
PDATE
.................................................................................................284
File Operations ............................................................................................................................................................................ 285
C
REATING A FILE
....................................................................................................285
L
INKING FILES
.........................................................................................................285
LN
............................................................................................................................286
Checking the file system.............................................................................................................................................................. 287
W
HY
M
E
? ...............................................................................................................287
W
HAT TO DO
...........................................................................................................288
FSCK
........................................................................................................................288
U
SING FSCK
.............................................................................................................288
W
HAT CAUSED THE PROBLEM
? ...............................................................................289
Conclusions................................................................................................................................................................................. 289
Review questions......................................................................................................................................................................... 289
References................................................................................................................................................................................... 291
Chapter ............................................................................................................................................................... 292
Backups....................................................................................................................................................................................... 292
Introduction................................................................................................................................................................................. 292
Other resources............................................................................................................................................................................ 292
Backups aren't enough................................................................................................................................................................. 293
Characteristics of a good backup strategy.................................................................................................................................... 293
E
ASE OF USE
...........................................................................................................293
T
IME EFFICIENCY
....................................................................................................293
E
ASE OF RESTORING FILES
......................................................................................294
A
BILITY TO VERIFY BACKUPS
..................................................................................294
T
OLERANCE OF FAULTY MEDIA
...............................................................................294
P
ORTABILITY TO A RANGE OF PLATFORMS
..............................................................295
Considerations for a backup strategy........................................................................................................................................... 295
The components of backups ........................................................................................................................................................ 295
S
CHEDULER
............................................................................................................296
T
RANSPORT
.............................................................................................................296
M
EDIA
....................................................................................................................298
Commands................................................................................................................................................................................... 298
DUMP AND RESTORE
..................................................................................................299
DUMP ON
L
INUX
.......................................................................................................299
T
HE RESTORE COMMAND
.........................................................................................300
Using dump and restore without a tape ................................................................................................................................. 301
O
UR PRACTICE FILE SYSTEM
...................................................................................301
D
OING A LEVEL
0
DUMP
..........................................................................................301
R
ESTORING THE BACKUP
.........................................................................................302
A
LTERNATIVE
.........................................................................................................302
T
HE TAR COMMAND
.................................................................................................303
T
HE DD COMMAND
...................................................................................................304
T
HE MT COMMAND
...................................................................................................305
Compression programs................................................................................................................................................................ 306
COMPRESS
................................................................................................................307
GZIP
........................................................................................................................307
Conclusions................................................................................................................................................................................. 307
Review questions......................................................................................................................................................................... 308
Chapter ............................................................................................................................................................... 309
Startup and Shutdown.................................................................................................................................................................. 309
Introduction................................................................................................................................................................................. 309
Other resources............................................................................................................................................................................ 309
A booting overview ..................................................................................................................................................................... 309
Finding the kernel........................................................................................................................................................................ 310
ROM ......................................................................................................................310
T
HE BOOTSTRAP PROGRAM
.....................................................................................310
Booting on a PC .......................................................................................................................................................................... 311
O
N THE FLOPPY
.......................................................................................................311
M
AKING A BOOT DISK
.............................................................................................311
U
SING A BOOT LOADER
...........................................................................................312
Starting the kernel ....................................................................................................................................................................... 313
K
ERNEL BOOT MESSAGES
........................................................................................313
Starting the processes ..................................................................................................................................................................315
R
UN LEVELS
............................................................................................................316
/
ETC
/
INITTAB
........................................................................................................316
System configuration................................................................................................................................................................... 319
Terminal logins ........................................................................................................................................................................... 320
Startup scripts.............................................................................................................................................................................. 320
T
HE
L
INUX PROCESS
...............................................................................................321
/etc/rc.d/init.d .....................................................................................322
Why won't it boot? ...................................................................................................................................................................... 322
S
OLUTIONS
.............................................................................................................323
M
AKING A BOOT DISK
.............................................................................................323
U
SING RESCUE MODE ON THE
CD-ROM .................................................................324
U
SING THE ALTERNATIVE BOOT
..............................................................................325
D
ISASTER RECOVERY SOLUTIONS
............................................................................326
Solutions to hardware problems .................................................................................................................................................. 327
D
AMAGED FILE SYSTEMS
........................................................................................327
I
MPROPERLY CONFIGURED KERNELS
.......................................................................327
Shutting down ............................................................................................................................................................................. 328
R
EASONS FOR SHUTTING DOWN
..............................................................................328
B
EING NICE TO THE USERS
.......................................................................................329
Commands to shutdown........................................................................................................................................................... 329
S
HUTDOWN
..................................................................................................................330
W
HAT HAPPENS
......................................................................................................330
T
HE OTHER COMMANDS
..........................................................................................331
Conclusions................................................................................................................................................................................. 331
Review questions......................................................................................................................................................................... 331
References................................................................................................................................................................................... 332
Chapter ............................................................................................................................................................... 333
Kernel.......................................................................................................................................................................................... 333
The heart that keeps the system pumping .................................................................................................................................... 333
Other resources............................................................................................................................................................................ 333
Why the kernel? .......................................................................................................................................................................... 334
How?........................................................................................................................................................................................... 335
The lifeless image........................................................................................................................................................................ 335
Inside the great unknown, the kernel ........................................................................................................................................... 336
Documentation ............................................................................................................................................................................ 339
The first incision.......................................................................................................................................................................... 339
M
AKING THE HEART BEAT
... ...................................................................................339
The proc file system.................................................................................................................................................................. 340
Really, why bother?..................................................................................................................................................................... 342
C
OMPILING THE SOURCE
.........................................................................................343
S
TANDARD
UNIX
COMPILATION
.....................................................................................343
D
EPENDENCIES
.......................................................................................................348
C
OMPILATION
.........................................................................................................348
C
ONFIGURING THE BOOT LOADER
...........................................................................349
Kernel Modules ........................................................................................................................................................................... 350
K
ERNEL
M
ODULE
U
TILITIES
...................................................................................351
KMOD
: T
HE KERNEL MODULE LOADER
......................................................................353
Installing pre-compiled kernels using RPM................................................................................................................................. 353
A
PPLYING PATCHES
................................................................................................354
T
HAT
’
S ALL GREAT
,
BUT HOW LONG IS IT GOING TO TAKE
? ....................................355
C
OMMON PROBLEMS
...............................................................................................356
Conclusions................................................................................................................................................................................. 357
Review questions......................................................................................................................................................................... 357
References................................................................................................................................................................................... 358
Chapter ............................................................................................................................................................... 359
Automation and Observation....................................................................................................................................................... 359
Introduction................................................................................................................................................................................. 359
Other resources............................................................................................................................................................................ 359
Automation and cron................................................................................................................................................................. 359
C
OMPONENTS OF
CRON
.............................................................................................360
CRONTAB
FORMAT
......................................................................................................360
C
REATING
CRONTAB
FILES
..........................................................................................361
Current Observation .................................................................................................................................................................... 362
DF
............................................................................................................................362
DU
............................................................................................................................362
S
YSTEM
S
TATUS
.....................................................................................................363
T
HE NICE VALUE
.....................................................................................................365
S
IGNALS
..................................................................................................................365
Historical observation.................................................................................................................................................................. 366
M
ANAGING LOG AND ACCOUNTING FILES
...............................................................366
C
ENTRALISE
............................................................................................................366
S
ECURITY
................................................................................................................367
L
OOK AT THEM
.......................................................................................................367
Logging .......................................................................................................................................................................................367
SYSLOG
......................................................................................................................367
Accounting .................................................................................................................................................................................. 371
L
OGIN ACCOUNTING
...............................................................................................371
LAST
.........................................................................................................................371
AC
............................................................................................................................371
P
ROCESS ACCOUNTING
............................................................................................372
LASTCOMM
................................................................................................................372
T
HE SA COMMAND
...................................................................................................372
S
O WHAT
?...............................................................................................................373
Conclusions................................................................................................................................................................................. 373
Review questions......................................................................................................................................................................... 374
Chapter ............................................................................................................................................................... 375
Networks: The Connection.......................................................................................................................................................... 375
Introduction................................................................................................................................................................................. 375
Other Resources .......................................................................................................................................................................... 375
The Overview.............................................................................................................................................................................. 376
W
HAT YOU NEED
....................................................................................................376
W
HAT YOU DO
........................................................................................................377
TCP/IP Basics ............................................................................................................................................................................. 377
H
OSTNAMES
............................................................................................................377
HOSTNAME
................................................................................................................378
Q
UALIFIED NAMES
..................................................................................................379
Not qualified.......................................................................................................379
IP/I
NTERNET ADDRESSES
........................................................................................379
Dotted quad to binary ........................................................................................379
Networks and hosts ............................................................................................380
For example .......................................................................................................380
The Internet is a network of networks ......................................................................................................................................... 381
N
AME RESOLUTION
.................................................................................................384
R
OUTING
.................................................................................................................387
TCP/IP
BASICS CONCLUSION
..................................................................................388
Network Hardware ...................................................................................................................................................................... 388
N
ETWORK DEVICES
.................................................................................................389
E
THERNET
...............................................................................................................390
C
ONVERTING HARDWARE ADDRESSES TO
I
NTERNET ADDRESSES
............................390
SLIP, PPP
AND POINT
-
TO
-
POINT
............................................................................392
Kernel support for networking..................................................................................................................................................... 392
Configuring the connection ......................................................................................................................................................... 394
T
HE CONFIGURATION PROCESS
................................................................................394
C
ONFIGURATION RELATED TOOLS AND FILES
..........................................................394
C
ONFIGURING THE DEVICE
/
INTERFACE
...................................................................395
C
ONFIGURING THE NAME RESOLVER
.......................................................................396
C
ONFIGURING ROUTING
..........................................................................................398
Network “management” tools...................................................................................................................................................... 400
R
ED
H
AT
GUI
NETWORKING TOOLS
.......................................................................400
NSLOOKUP
................................................................................................................401
NETSTAT
..................................................................................................................401
TRACEROUTE
.............................................................................................................402
Conclusions................................................................................................................................................................................. 403
Review questions......................................................................................................................................................................... 403
References................................................................................................................................................................................... 405
Chapter ............................................................................................................................................................... 406
Network Applications.................................................................................................................................................................. 406
Introduction................................................................................................................................................................................. 406
Other resources............................................................................................................................................................................ 406
How it all works .......................................................................................................................................................................... 407
Ports ............................................................................................................................................................................................ 407
R
ESERVED PORTS
....................................................................................................408
L
OOK AT PORTS
,
NETSTAT
.......................................................................................409
Network daemons........................................................................................................................................................................ 410
H
OW NETWORK DAEMONS START
...........................................................................410
XINETD AND INETD
..................................................................................................411
H
OW IT WORKS
.......................................................................................................412
Network clients ........................................................................................................................................................................... 413
T
HE TELNET CLIENT
.................................................................................................413
Network protocols ....................................................................................................................................................................... 413
R
EQUEST FOR COMMENT
(RFC
S
) ............................................................................413
T
EXT BASED PROTOCOLS
........................................................................................414
H
OW IT WORKS
.......................................................................................................415
Security ....................................................................................................................................................................................... 416
XINETD
,
INETD AND
TCPW
RAPPERS
/
TCPD
.................................................................416
What's an Intranet? ...................................................................................................................................................................... 418
S
ERVICES ON AN
I
NTRANET
....................................................................................418
File and print sharing................................................................................................................................................................... 418
S
AMBA
....................................................................................................................419
Email........................................................................................................................................................................................... 421
E
MAIL COMPONENTS
...............................................................................................421
E
MAIL
P
ROTOCOLS
.................................................................................................423
World-wide web.......................................................................................................................................................................... 424
Conclusions................................................................................................................................................................................. 424
Review questions......................................................................................................................................................................... 425
References................................................................................................................................................................................... 425
Chapter ............................................................................................................................................................... 426
Security ....................................................................................................................................................................................... 426
Local Introduction ....................................................................................................................................................................... 426
Linux Security HOWTO ............................................................................................................................................................. 426
I
NTRODUCTION
.......................................................................................................426
O
VERVIEW
..............................................................................................................428
P
HYSICAL
S
ECURITY
...............................................................................................432
L
OCAL
S
ECURITY
....................................................................................................435
F
ILES AND
F
ILE SYSTEM
S
ECURITY
.........................................................................437
P
ASSWORD
S
ECURITY AND
E
NCRYPTION
................................................................442
K
ERNEL
S
ECURITY
..................................................................................................449
N
ETWORK
S
ECURITY
..............................................................................................452
S
ECURITY
P
REPARATION
(
BEFORE YOU GO ON
-
LINE
) ..............................................461
W
HAT
T
O
D
O
D
URING AND
A
FTER A
B
REAKIN
......................................................463
C
LOSING THE
H
OLE
................................................................................................464
A
SSESSING THE
D
AMAGE
........................................................................................464
B
ACKUPS
,
B
ACKUPS
, B
ACKUPS
!.............................................................................465
T
RACKING
D
OWN THE
I
NTRUDER
. ..........................................................................465
S
ECURITY
S
OURCES
................................................................................................465
G
LOSSARY
..............................................................................................................468
F
REQUENTLY
A
SKED
Q
UESTIONS
...........................................................................469
C
ONCLUSION
...........................................................................................................471
A
CKNOWLEDGMENTS
.............................................................................................471
Systems Administration Chapter 1: The Overview
Page 19
Chapter
The Overview
Introduction
This overview chapter has been included in this text as a result of feedback from
previous students in the course Systems Administration. It is an attempt to give you
an overview of the course and more importantly of computing, Linux and Systems
Administration.
Many students commented that they felt lost in the detail of Linux without having an
overall picture of how it fits together. Hopefully this chapter will go some way
towards solving this problem, and will provide some sort of small map and compass
so you have an idea of where you are and where you are going.
We are always keen and willing to hear feedback about this text. If you have useful
suggestions please feel free to make them via the various mechanisms which are
available on the course website.
This chapter will discuss the following:
· The course
A brief overview of the course and why it is the way it is. This will also include
an introduction to the material we will cover this term.
· Course material
A really quick explanation of how the course CD-ROM, website, textbook and
other material all fit together (or at least how we hope it will).
· Solving problems
There is one thing both you and I can be sure of this term… At some stage, you
will have problems with Linux or this course. This section provides some hints
and tips on how you should go about solving these problems.
· Computers in the real world
Those of you who have not read widely, or perhaps don’t have experience in the
computing industry, will think that computing starts and stops with single, stand-
alone Windows computers. This couldn't be further from the truth. This section
attempts to give you some idea of at least one other version of what is out there.
· An overview of Linux
Last but not least this section provides a quick overview of Linux, how it works
and some of the more important concepts you will learn about during this course.
Other Resources
All the chapters in this text will have a section called “Other Resources” near the start
of the chapter. The idea of this section is, obviously, to point you to other resources
Systems Administration Chapter 1: The Overview
Page 20
that discuss related material. The course’s website will maintain a more up-to-date
list of resources which will include comments from people about those resources and
a space where you can contribute comments and provide pointers to resources you
found useful.
One of the most common references 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. A mirror
of the LDP website is included on the course website/CD-ROM.
Other resources that discuss similar material to this chapter include:
· Online lectures 1, 2 and 3 on the course website discuss some of the same
information covered here, though some of the information may be a touch old.
· HOWTO’s
These are “smallish” documents that provide guidance on a particular topic. One
HOWTO which covers similar material to this chapter is the UNIX and Internet
Fundamentals HOW-TO.
· Guides
The LDP also includes a number of guides that are essentially full-blown books.
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 Overview section from the
Linux Administration Made Easy Guide (LAME).
The Course
You can get some idea of what to expect from the course, Systems Administration,
and to some extent a career as a Systems Administrator, from the following poem
written by a past student.
Lament of a Linux Student
Here I sit broken hearted
Loaded X-Windows and
Can't get it started
Off I go in a Tizzy
Looks as though tomorrow I'm busy
I can guarantee that most students will at some stage be frustrated, annoyed,
depressed and entirely sick of this course, Linux and anyone responsible for it. This
can also be said for a career in Systems Administration.
Many of you may have heard of this course from other students. Hopefully they
haven’t put you off trying to learn something different. The experience of past
students in for this course can be summarised as follows:
· enjoyable
· very practical
· a lot of work
Systems Administration Chapter 1: The Overview
Page 21
Hopefully this year you will find the emphasis more on the first two rather than the
last one. But don’t expect to simply read this study guide and instantly become a
systems administrator, it is just not going to happen. This course will require a lot of
extra work, but I can guarantee if you put in the time now it will make your job that
much easier once you have entered the work force.
The rationale
Why is the course the way it is? There are lots of contributing reasons, but the main
ones are:
· You need to learn about Systems Administration
Systems Administration is an essential task, especially given the increasing
importance of computers. Systems Administration is difficult. Software and
untrained people can't be Systems Administrators. Knowing about Systems
Administration will make you a better programmer and computing professional,
even if you don't find employment as a Systems Administrator.
· People only learn by doing
Sure you might be able to recite back to me a whole bunch of facts, commands
and concepts and probably even pass an exam. But you won't know how to be a
Systems Administrator. To do this you have to experience it.
The last point cannot be emphasised enough. You will learn nothing from this book
and course by simply reading about it. You have to get in and get your hands dirty
playing around.
What you will learn
The aim of the course is to introduce you to the task of Systems Administration -
looking after and maintaining complex computer systems. In particular, the course
aims to produce students who meet the requirements of a Junior Systems
Administrator as outlined in the SAGE Job Description booklet (without the 1 or 2
years experience). You can find an excerpt from the Job Description booklet on the
course website.
Figure 1.1 provides a graphical representation of the topics introduced in this course.
Systems Administration Chapter 1: The Overview
Page 22
Figure 1.1
An Overview of the Content of this Book.
For the first nine chapters of this book we concentrate on the foundations - basic
UNIX. You need to become familiar with basic concepts such as UNIX commands,
shells, and regular expressions before you can progress to the “real” Systems
Administration topics. You will apply your knowledge of these foundation concepts
in the later chapters of the book.
Chapters 10 through 18 cover the following concepts:
· Users and account management
People have to be able to use the systems you manage. Chapter 10 examines the
issues involved with this on a Linux system.
· File systems and Backups
People use a computer in order to store and manipulate data. That data has to be
stored somewhere. Chapters 11 and 12 examine how Linux stores data on hard-
drives and how you can perform backups to tape.
· Start up and Shutdown
Operating systems such as Linux and Windows NT are not simple systems. The
process to start them up and shut them down is quite complex and problems can
arise. Chapter 13 examines the Linux start up and shutdown process.
· The kernel
Many of the services provided by a computer are implemented in the kernel of
the operating system. Chapter 14 examines how to configure, compile and install
the Linux kernel.
· Automation and Observation
Once your computer is up and running you need to be able to automate tasks and
observe what is going on. Chapter 15 examines how to achieve these two tasks
on a Linux computer.
Systems Administration Chapter 1: The Overview
Page 23
· Networks
Without a network connection and network services, most modern computers are
considered useless. Chapters 16 and 17 examine how to connect, configure and
use a Linux computer on a network.
· Security
Ensuring that your computer and its contents is safe from prying eyes is an
essential part of any Systems Administrator’s job. Chapter 18 provides an
overview of security on a Linux system.
All these concepts are essential to Systems Administrators regardless of the type of
operating system they are using. Someone managing a Windows NT, Windows 2000
or Windows .NET system still needs to ensure the security of the system, connect it to
a network, configure it for new drivers and keep an eye on what is happening.
Why not Windows?
A very common question from students doing the course is, why are we using Linux?
Why aren't we using NT, 2000 or .NET? Here are some of my answers to those
questions.
· Windows is not cheap
It costs money to distribute a copy of Windows server to a couple of hundred
students doing the course in three or four countries. A lot more money than it
does to distribute Linux.
· It is not complete
Adding to the cost is that when you get a copy of Windows server you don't get a
real web server, a database and a bunch of other important software.
· It hides its complexity
Windows NT server, 2000 server and .NET are supposed to be easy to
administer. After all, they are all GUI based. That isn't an argument, as there are
similar GUI based tools for managing UNIX boxes. The problem with GUIs,
especially when you are learning about systems, is that GUIs hide how things
work. As a Systems Administrator you need to know how things work. You
don't need to know that to get it to work you press that button on that dialog box.
A trained monkey can work that out.
· It is closed
Windows is Microsoft's. They own it. They make the rules. If they are unhappy,
they change it. Linux is owned by a community of people who work together to
make it better.
· If you learn Linux you can learn Windows
Lastly, if you can learn the material in this textbook, learning how to administer a
server of another operating system is no great difficulty.
Course Material
For this course you will need to have access to this study guide and the course
website. This section gives a brief overview of the relationships between these
materials.
Systems Administration Chapter 1: The Overview
Page 24
Study Guide
This book provides most of the reading and exercises you will need for the course.
You should end up reading most of it if not all of it. Electronic copies of the text are
available on the course website, or you can purchase a hardcopy of it from the CQU
bookshop.
There are a couple of older chapters from this text that are not included with the print
version.
The Course Website
It is intended that the course website will be the primary site for interaction and
information exchange. The website should always have the most up-to-date
information.
The website will also have a number of features which will enable you to make
contributions to improving the site and the course. Please take the time to visit and
become familiar with the website and its features. The URL for the course website
can be found in the Course Profile.
Solving Problems
Students enrolled in this course will be nearing the end their degree. It won't be long
before you are computing professionals employed to do work with computers. When
you are a computing professional you will not be able to ask the lecturer how to do
something. You will need to know how to solve the problem yourself, to work it out.
If there is one thing I hope you learn from this course it is the ability to solve your
own problems.
Chapter 3 of this textbook offers more details about how you should go about solving
problems. Please refer to it.
Computers in the Real World
Chances are most of your experience with computers are with Wintel PCs (computers
with Intel CPUs running various versions of the Windows operating system). As with
most people, your past experience colours your beliefs. Out in the "real world" (a
term I will use throughout the book to refer to largish organisations) there is a lot
more to computers than Wintel computers with a single monitor, CPU and keyboard.
It is hoped that this section will introduce you to some of the differences you can
expect to experience when you enter the "real world".
What you think computers are
Chances are you think computers have one monitor, one CPU, some RAM, a
keyboard, a printer, a couple of other peripherals and maybe a network connection.
To use the computer you sit down in front of it,
· Turn it on
As a result, the computer finds some boot information on one of the drives, loads
Systems Administration Chapter 1: The Overview
Page 25
the kernel of the operating system you use, configures the machine and starts up
some other software services.
· Get presented with a GUI interface, i.e. Windows, on the monitor
· Do stuff by double clicking on icons and the like
As a result the computer loads programs from file and executes them using your
computer's CPU and displays the results on the monitor.
· You might be able to connect to a network drive
The network drive might contain data or maybe some programs, which you can
run using the CPU of your computer.
· When you are finished you turn the computer off.