- 1 -
• Table of Contents
• Index
• Reviews
• Reader Reviews
• Errata
• Academic
BSD Hacks
By Dru Lavigne
Publisher: O'Reilly
Pub Date: May 2004
ISBN: 0-596-00679-9
Pages: 300
Looking for a unique set of practical tips, tricks, and tools for administrators and power
users of BSD systems? From hacks to customize the user environment to networking,
securing the system, and optimization, BSD Hacks takes a creative approach to saving time
and accomplishing more with fewer resources. If you want more than the average BSD
user--to explore and experiment, unearth shortcuts, create useful tools--this book is a
must-have.
- 2 -
CREDITS..................................................................................................................................................- 5 -
PREFACE............................................................................................................................................... - 10 -
CHAPTER 1. CUSTOMIZING THE USER ENVIRONMENT..........................................................- 14 -
HACK 0 INTRODUCTION .......................................................................................................................- 15 -
HACK 1 GET THE MOST OUT OF THE DEFAULT SHELL ......................................................................- 16 -
HACK 2 USEFUL TCSH SHELL CONFIGURATION FILE OPTIONS..........................................................- 21 -
HACK 3 CREATE SHELL BINDINGS ......................................................................................................- 25 -
HACK 4 USE TERMINAL AND X BINDINGS ...........................................................................................- 29 -
HACK 5 USE THE MOUSE AT A TERMINAL...........................................................................................- 33 -
HACK 6 GET YOUR DAILY DOSE OF TRIVIA........................................................................................- 35 -
HACK 7 LOCK THE SCREEN.................................................................................................................- 39 -
HACK 8 CREATE A TRASH DIRECTORY...............................................................................................- 42 -
HACK 9 CUSTOMIZE USER CONFIGURATIONS....................................................................................- 46 -
HACK 10 MAINTAIN YOUR ENVIRONMENT ON MULTIPLE SYSTEMS...................................................- 56 -
HACK 11 USE AN INTERACTIVE SHELL................................................................................................- 60 -
HACK 12 USE MULTIPLE SCREENS ON ONE TERMINAL .....................................................................- 64 -
CHAPTER 2. DEALING WITH FILES AND FILESYSTEMS......................................................... - 69 -
INTRODUCTION ....................................................................................................................................- 70 -
HACK 13 FIND THINGS ........................................................................................................................- 71 -
HACK 14 GET THE MOST OUT OF GREP .............................................................................................- 76 -
HACK 15 MANIPULATE FILES WITH SED..............................................................................................- 81 -
HACK 16 FORMAT TEXT AT THE COMMAND LINE ...............................................................................- 84 -
HACK 17 DELIMITER DILEMMA ............................................................................................................- 91 -
HACK 18 DOS FLOPPY MANIPULATION..............................................................................................- 94 -
HACK 19 ACCESS WINDOWS SHARES WITHOUT A SERVER............................................................- 102 -
HACK 20 DEAL WITH DISK HOGS......................................................................................................- 105 -
HACK 21 MANAGE TEMPORARY FILES AND SWAP SPACE...............................................................- 111 -
HACK 22 RECREATE A DIRECTORY STRUCTURE USING MTREE ......................................................- 115 -
HACK 23 GHOSTING SYSTEMS .........................................................................................................- 121 -
HACK 24 CUSTOMIZE THE DEFAULT BOOT MENU............................................................................- 128 -
HACK 25 PROTECT THE BOOT PROCESS .........................................................................................- 134 -
HACK 26 RUN A HEADLESS SYSTEM ................................................................................................- 137 -
HACK 27 LOG A HEADLESS SERVER REMOTELY..............................................................................- 141 -
HACK 28 REMOVE THE TERMINAL LOGIN BANNER...........................................................................- 145 -
HACK 29 PROTECTING PASSWORDS WITH BLOWFISH HASHES......................................................- 149 -
HACK 30 MONITOR PASSWORD POLICY COMPLIANCE ....................................................................- 152 -
HACK 31 CREATE AN EFFECTIVE, REUSABLE PASSWORD POLICY .................................................- 161 -
HACK 32 AUTOMATE MEMORABLE PASSWORD GENERATION .........................................................- 167 -
HACK 33 USE ONE TIME PASSWORDS.............................................................................................- 172 -
HACK 34 RESTRICT LOGINS..............................................................................................................- 176 -
- 3 -
CHAPTER 4. BACKING UP.............................................................................................................. - 180 -
HACK 35 BACK UP FREEBSD WITH SMBFS.................................................................................. - 182 -
HACK 36 CREATE PORTABLE POSIX ARCHIVES ............................................................................ - 186 -
HACK 37 INTERACTIVE COPY........................................................................................................... - 191 -
HACK 38 SECURE BACKUPS OVER A NETWORK ............................................................................. - 195 -
HACK 39 AUTOMATE REMOTE BACKUPS......................................................................................... - 198 -
HACK 40 AUTOMATE DATA DUMPS FOR POSTGRESQL DATABASES............................................. - 204 -
HACK 41 PERFORM CLIENT-SERVER CROSS-PLATFORM BACKUPS WITH BACULA ....................... - 208 -
CHAPTER 5. NETWORKING HACKS............................................................................................- 216 -
HACK 42 SEE CONSOLE MESSAGES OVER A REMOTE LOGIN........................................................ - 218 -
HACK 43 SPOOF A MAC ADDRESS ................................................................................................. - 221 -
HACK 44 USE MULTIPLE WIRELESS NIC CONFIGURATIONS .......................................................... - 225 -
HACK 45 SURVIVE CATASTROPHIC INTERNET LOSS ....................................................................... - 230 -
HACK 46 HUMANIZE TCPDUMP OUTPUT .......................................................................................... - 233 -
HACK 47 UNDERSTAND DNS RECORDS AND TOOLS...................................................................... - 240 -
HACK 48 SEND AND RECEIVE EMAIL WITHOUT A MAIL CLIENT ...................................................... - 246 -
HACK 49 WHY DO I NEED SENDMAIL?............................................................................................. - 251 -
HACK 50 HOLD EMAIL FOR LATER DELIVERY.................................................................................. - 255 -
HACK 51 GET THE MOST OUT OF FTP............................................................................................ - 258 -
HACK 52 DISTRIBUTED COMMAND EXECUTION............................................................................... - 262 -
HACK 53 INTERACTIVE REMOTE ADMINISTRATION.......................................................................... - 265 -
CHAPTER 6. SECURING THE SYSTEM........................................................................................- 269 -
HACK 54 STRIP THE KERNEL ........................................................................................................... - 271 -
HACK 55 FREEBSD ACCESS CONTROL LISTS................................................................................ - 282 -
HACK 56 PROTECT FILES WITH FLAGS............................................................................................ - 289 -
HACK 57 TIGHTEN SECURITY WITH MANDATORY ACCESS CONTROL ............................................ - 295 -
HACK 58 USE MTREE AS A BUILT-IN TRIPWIRE................................................................................ - 299 -
HACK 59 INTRUSION DETECTION WITH SNORT, ACID, MYSQL, AND FREEBSD.......................... - 305 -
HACK 60 ENCRYPT YOUR HARD DISK ............................................................................................. - 317 -
HACK 61 SUDO GOTCHAS................................................................................................................ - 322 -
HACK 62 SUDOSCRIPT...................................................................................................................... - 326 -
HACK 63 RESTRICT AN SSH SERVER.............................................................................................. - 332 -
HACK 64 SCRIPT IP FILTER RULESETS ........................................................................................... - 336 -
HACK 65 SECURE A WIRELESS NETWORK USING PF..................................................................... - 339 -
HACK 66 AUTOMATICALLY GENERATE FIREWALL RULES ............................................................... - 344 -
HACK 67 AUTOMATE SECURITY PATCHES....................................................................................... - 350 -
HACK 68 SCAN A NETWORK OF WINDOWS COMPUTERS FOR VIRUSES......................................... - 355 -
CHAPTER 7. GOING BEYOND THE BASICS...............................................................................- 359 -
HACK 69 TUNE FREEBSD FOR DIFFERENT APPLICATIONS ............................................................ - 361 -
- 4 -
HACK 70 TRAFFIC SHAPING ON FREEBSD ......................................................................................- 366 -
HACK 71 CREATE AN EMERGENCY REPAIR KIT ...............................................................................- 372 -
HACK 72 USE THE FREEBSD RECOVERY PROCESS.......................................................................- 376 -
HACK 73 USE THE GNU DEBUGGER TO ANALYZE A BUFFER OVERFLOW......................................- 381 -
HACK 74 CONSOLIDATE WEB SERVER LOGS...................................................................................- 385 -
HACK 75 SCRIPT USER INTERACTION ..............................................................................................- 391 -
HACK 76 CREATE A TRADE SHOW DEMO.........................................................................................- 396 -
CHAPTER 8. KEEPING UP-TO-DATE ........................................................................................... - 402 -
HACK 77 AUTOMATED INSTALL .........................................................................................................- 404 -
HACK 78 FREEBSD FROM SCRATCH ...............................................................................................- 409 -
HACK 79 SAFELY MERGE CHANGES TO /ETC...................................................................................- 415 -
HACK 80 AUTOMATE UPDATES.........................................................................................................- 419 -
HACK 81 CREATE A PACKAGE REPOSITORY....................................................................................- 425 -
HACK 82 BUILD A PORT WITHOUT THE PORTS TREE ......................................................................- 429 -
HACK 83 KEEP PORTS UP-TO-DATE WITH CTM..............................................................................- 433 -
HACK 84 NAVIGATE THE PORTS SYSTEM.........................................................................................- 436 -
HACK 85 DOWNGRADE A PORT ........................................................................................................- 441 -
HACK 86 CREATE YOUR OWN STARTUP SCRIPTS...........................................................................- 445 -
HACK 87 AUTOMATE NETBSD PACKAGE BUILDS............................................................................- 449 -
HACK 88 EASILY INSTALL UNIX APPLICATIONS ON MAC OS X........................................................- 453 -
CHAPTER 9. GROKKING BSD........................................................................................................ - 457 -
HACK 89 HOW'D HE KNOW THAT?...................................................................................................- 459 -
HACK 90 CREATE YOUR OWN MANPAGES.......................................................................................- 462 -
HACK 91 GET THE MOST OUT OF MANPAGES .................................................................................- 466 -
HACK 92 APPLY, UNDERSTAND, AND CREATE PATCHES.................................................................- 470 -
HACK 93 DISPLAY HARDWARE INFORMATION ..................................................................................- 476 -
HACK 94 DETERMINE WHO IS ON THE SYSTEM ...............................................................................- 481 -
HACK 95 SPELLING BEE....................................................................................................................- 485 -
HACK 96 LEAVE ON TIME ..................................................................................................................- 489 -
HACK 97 RUN NATIVE JAVA APPLICATIONS .....................................................................................- 492 -
HACK 98 ROTATE YOUR SIGNATURE................................................................................................- 495 -
HACK 100 FUN WITH X......................................................................................................................- 501 -
- 5 -
Credits
About the Author
Contributors
Acknowledgments
About the Author
Dru Lavigne is the author of ONLamp.com's FreeBSD Basics column and has been an avid
BSD user since FreeBSD 2.2.1. As an IT instructor, she specializes in networking, routing,
and security. She is also responsible for ISECOM's Protocol Database, which can be found at
http://www.isecom.org
.
Contributors
The following people contributed their hacks, writing, and inspiration to this book:
• John Richard, known locally as JR, is a system administrator in Kingston, Ontario,
Canada. His trademark in the field is his insistence on a FreeBSD box as the primary
firewall on a network. He has enjoyed working with the author in the past at a
private college in Kingston. In his spare time, he experiments with FreeBSD and
rides his Harley-Davidson.
[Hack #64]
• Joe Warner is a Technical Analyst for Siemens Medical Solutions Health Services
Corporation and has been using FreeBSD as a server and desktop since October of
2000. Joe has lived in Salt Lake City, Utah for most of his life and enjoys *BSD,
computing, history, and The Matrix.
[Hacks #35
and #59]
• Dan Langille (http://www.langille.org/) runs a consulting group in Ottawa, Canada.
He has fond memories of his years in New Zealand, where the climate is much more
conducive to year-round mountain biking. He lives in a house ruled by felines.
[Hack #41]
• Robert Bernier's professional career has included engineering, accident investigation,
and Olympic trials. In the 1980s, his interest returned to IT when he realized he
wouldn't have to use a punch card anymore. Eventually he discovered Linux and by
the mid-1990s had developed a passion for all things open source. Today, Robert
teaches at the local community college and writes for a number of IT publications
based in North America and Europe.
[Hack #12]
• Kirk Russell (kirk@qnx.com
) is a kernel tester at QNX Software Systems
(http://www.qnx.com/
).
[Hack #36]