عن كتاب Linux Fundamentals Paul Cobbaut: Linux Fundamentals
Paul Cobbaut
Publication date 2015-05-24 CEST
Abstract
This book is meant to be used in an instructor-led training. For self-study, the intent is to read
this book next to a working Linux computer so you can immediately do every subject, practicing
each command.
This book is aimed at novice Linux system administrators (and might be interesting and useful
for home users that want to know a bit more about their Linux system). However, this book
is not meant as an introduction to Linux desktop applications like text editors, browsers, mail
clients, multimedia or office applications.
More information and free .pdf available at
http://linux-training.be
.
Feel free to contact the author:
• Paul Cobbaut: paul.cobbaut@gmail.com, http://www.linkedin.com/in/cobbaut
Contributors to the Linux Training project are:
• Serge van Ginderachter: serge@ginsys.eu, build scripts and infrastructure setup
• Ywein Van den Brande: ywein@crealaw.eu, license and legal sections
• Hendrik De Vloed: hendrik.devloed@ugent.be, buildheader.pl script
We'd also like to thank our reviewers:
• Wouter Verhelst: wo@uter.be, http://grep.be
• Geert
Goossens:
mail.goossens.geert@gmail.com,
http://www.linkedin.com/in/
geertgoossens
• Elie De Brauwer: elie@de-brauwer.be, http://www.de-brauwer.be
• Christophe Vandeplas: christophe@vandeplas.com, http://christophe.vandeplas.com
• Bert Desmet: bert@devnox.be, http://blog.bdesmet.be
• Rich Yonts: richyonts@gmail.com,
Copyright 2007-2015 Netsec BVBA, Paul Cobbaut
Permission is granted to copy, distribute and/or modify this document under the terms of the
GNU Free Documentation License
, Version 1.3 or any later version published by the Free
Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. A copy of the license is included in the section entitled 'GNU Free Documentation
License'.
iii
.................................................................................................................................. 199
20.7. gzip - gunzip
.................................................................................................................... 200
20.8. zcat - zmore
..................................................................................................................... 200
20.9. bzip2 - bunzip2
................................................................................................................ 201
20.10. bzcat - bzmore
............................................................................................................... 201
20.11. practice: basic Unix tools
.............................................................................................. 202
20.12. solution: basic Unix tools
.............................................................................................. 203
.................................................................................................................... 205
21.1. regex versions
.................................................................................................................. 206
21.2. grep
.................................................................................................................................. 207
21.3. rename
.............................................................................................................................. 212
21.4. sed
.................................................................................................................................... 215
21.5. bash history
...................................................................................................................... 219
VI. vi
............................................................................................................................................................ 220
....................................................................................................................... 222
22.1. command mode and insert mode
.................................................................................... 223
22.2. start typing
(a A i I o O)................................................................................................ 223
22.3. replace and delete a character
(r x X)............................................................................. 224
22.4. undo and repeat
(u .)....................................................................................................... 224
22.5. cut, copy and paste a line
(dd yy p P)............................................................................ 224
22.6. cut, copy and paste lines
(3dd 2yy)................................................................................ 225
22.7. start and end of a line
(0 or ^ and $).............................................................................. 225
22.8. join two lines
(J) and more
............................................................................................. 225
22.9. words
(w b)..................................................................................................................... 226
22.10. save
(or not) and exit
(:w :q :q! ).................................................................................. 226
22.11. Searching
(/ ?)................................................................................................................ 226
22.12. replace all
( :1,$ s/foo/bar/g )........................................................................................ 227
22.13. reading files
(:r :r !cmd)................................................................................................ 227
22.14. text buffers
..................................................................................................................... 227
22.15. multiple files
.................................................................................................................. 227
Linux Fundamentals
vii
22.16. abbreviations
.................................................................................................................. 228
22.17. key mappings
................................................................................................................. 229
22.18. setting options
................................................................................................................ 229
22.19. practice: vi
(m)............................................................................................................... 230
22.20. solution: vi
(m)............................................................................................................... 231
VII. scripting
................................................................................................................................................ 232
23. scripting introduction
................................................................................................................ 234
23.1. prerequisites
..................................................................................................................... 235
23.2. hello world
....................................................................................................................... 235
23.3. she-bang
........................................................................................................................... 235
23.4. comment
........................................................................................................................... 236
23.5. variables
........................................................................................................................... 236
23.6. sourcing a script
.............................................................................................................. 236
23.7. troubleshooting a script
................................................................................................... 237
23.8. prevent setuid root spoofing
............................................................................................ 237
23.9. practice: introduction to scripting
................................................................................... 238
23.10. solution: introduction to scripting
................................................................................. 239
............................................................................................................................. 240
24.1. test
[ ]............................................................................................................................... 241
24.2. if then else
....................................................................................................................... 242
24.3. if then elif
........................................................................................................................ 242
24.4. for loop
............................................................................................................................ 242
24.5. while loop
........................................................................................................................ 243
24.6. until loop
.......................................................................................................................... 243
24.7. practice: scripting tests and loops
................................................................................... 244
24.8. solution: scripting tests and loops
................................................................................... 245
.................................................................................................................. 247
25.1. script parameters
.............................................................................................................. 248
25.2. shift through parameters
.................................................................................................. 249
25.3. runtime input
................................................................................................................... 249
25.4. sourcing a config file
...................................................................................................... 250
25.5. get script options with getopts
........................................................................................ 251
25.6. get shell options with shopt
............................................................................................ 252
25.7. practice: parameters and options
..................................................................................... 253
25.8. solution: parameters and options
..................................................................................... 254
............................................................................................................................. 255
26.1. eval
................................................................................................................................... 256
26.2.
(( ))
................................................................................................................................... 256
26.3. let
..................................................................................................................................... 257
26.4. case
.................................................................................................................................. 258
26.5. shell functions
.................................................................................................................. 259
26.6. practice : more scripting
.................................................................................................. 260
26.7. solution : more scripting
.................................................................................................. 261
VIII. local user management
....................................................................................................................... 263
27. introduction to users
.................................................................................................................. 266
27.1. whoami
............................................................................................................................ 267
27.2. who
.................................................................................................................................. 267
27.3. who am i
.......................................................................................................................... 267
27.4. w
...................................................................................................................................... 267
27.5. id
...................................................................................................................................... 267
27.6. su to another user
............................................................................................................ 268
27.7. su to root
......................................................................................................................... 268
27.8. su as root
......................................................................................................................... 268
27.9. su - $username
................................................................................................................ 268
27.10. su -
................................................................................................................................. 268
27.11. run a program as another user
...................................................................................... 269
27.12. visudo
............................................................................................................................. 269
27.13. sudo su -
........................................................................................................................ 270
Linux Fundamentals
viii
27.14. sudo logging
.................................................................................................................. 270
27.15. practice: introduction to users
....................................................................................... 271
27.16. solution: introduction to users
....................................................................................... 272
....................................................................................................................... 274
28.1. user management
............................................................................................................. 275
28.2. /etc/passwd
....................................................................................................................... 275
28.3. root
................................................................................................................................... 275
28.4. useradd
............................................................................................................................. 276
28.5. /etc/default/useradd
.......................................................................................................... 276
28.6. userdel
.............................................................................................................................. 276
28.7. usermod
............................................................................................................................ 276
28.8. creating home directories
................................................................................................ 277
28.9. /etc/skel/
........................................................................................................................... 277
28.10. deleting home directories
.............................................................................................. 277
28.11. login shell
...................................................................................................................... 278
28.12. chsh
................................................................................................................................ 278
28.13. practice: user management
............................................................................................ 279
28.14. solution: user management
............................................................................................ 280
............................................................................................................................ 282
29.1. passwd
.............................................................................................................................. 283
29.2. shadow file
...................................................................................................................... 283
29.3. encryption with passwd
................................................................................................... 284
29.4. encryption with openssl
................................................................................................... 284
29.5. encryption with crypt
...................................................................................................... 285
29.6. /etc/login.defs
................................................................................................................... 286
29.7. chage
................................................................................................................................ 286
29.8. disabling a password
....................................................................................................... 287
29.9. editing local files
............................................................................................................. 287
29.10. practice: user passwords
................................................................................................ 288
29.11. solution: user passwords
................................................................................................ 289
................................................................................................................................ 291
30.1. system profile
.................................................................................................................. 292
30.2. ~/.bash_profile
................................................................................................................. 292
30.3. ~/.bash_login
.................................................................................................................... 293
30.4. ~/.profile
.......................................................................................................................... 293
30.5. ~/.bashrc
........................................................................................................................... 293
30.6. ~/.bash_logout
.................................................................................................................. 294
30.7. Debian overview
.............................................................................................................. 295
30.8. RHEL5 overview
............................................................................................................. 295
30.9. practice: user profiles
...................................................................................................... 296
30.10. solution: user profiles
.................................................................................................... 297
.......................................................................................................................................... 298
31.1. groupadd
.......................................................................................................................... 299
31.2. group file
......................................................................................................................... 299
31.3. groups
.............................................................................................................................. 299
31.4. usermod
............................................................................................................................ 300
31.5. groupmod
......................................................................................................................... 300
31.6. groupdel
........................................................................................................................... 300
31.7. gpasswd
............................................................................................................................ 301
31.8. newgrp
............................................................................................................................. 302
31.9. vigr
................................................................................................................................... 302
31.10. practice: groups
............................................................................................................. 303
31.11. solution: groups
............................................................................................................. 304
IX. file security
............................................................................................................................................ 305
32. standard file permissions
.......................................................................................................... 307
32.1. file ownership
.................................................................................................................. 308
32.2. list of special files
........................................................................................................... 310
32.3. permissions
...................................................................................................................... 311
Linux Fundamentals
ix
32.4. practice: standard file permissions
.................................................................................. 316
32.5. solution: standard file permissions
.................................................................................. 317
33. advanced file permissions
.......................................................................................................... 319
33.1. sticky bit on directory
..................................................................................................... 320
33.2. setgid bit on directory
..................................................................................................... 320
33.3. setgid and setuid on regular files
.................................................................................... 321
33.4. setuid on sudo
.................................................................................................................. 321
33.5. practice: sticky, setuid and setgid bits
............................................................................ 322
33.6. solution: sticky, setuid and setgid bits
............................................................................ 323
...................................................................................................................... 325
34.1. acl in /etc/fstab
................................................................................................................. 326
34.2. getfacl
.............................................................................................................................. 326
34.3. setfacl
............................................................................................................................... 326
34.4. remove an acl entry
......................................................................................................... 327
34.5. remove the complete acl
................................................................................................. 327
34.6. the acl mask
..................................................................................................................... 327
34.7. eiciel
................................................................................................................................. 328
....................................................................................................................................... 329
35.1. inodes
............................................................................................................................... 330
35.2. about directories
.............................................................................................................. 331
35.3. hard links
......................................................................................................................... 332
35.4. symbolic links
.................................................................................................................. 333
35.5. removing links
................................................................................................................. 333
35.6. practice : links
................................................................................................................. 334
35.7. solution : links
................................................................................................................. 335
X. Appendices
.............................................................................................................................................. 336
A. keyboard settings
......................................................................................................................... 338
A.1. about keyboard layout
...................................................................................................... 338
A.2. X Keyboard Layout
.......................................................................................................... 338
A.3. shell keyboard layout
....................................................................................................... 338
B. hardware
....................................................................................................................................... 340
B.1. buses
.................................................................................................................................. 340
B.2. interrupts
........................................................................................................................... 341
B.3. io ports
.............................................................................................................................. 342
B.4. dma
.................................................................................................................................... 342
C. License
.......................................................................................................................................... 344
Index
...