Home Page Icon
Home Page
Table of Contents for
Cover
Close
Cover
by Dru Lavigne
BSD Hacks
Credits
About the Author
Contributors
Acknowledgments
Preface
Why BSD Hacks?
How to Use this Book
How This Book Is Organized
Conventions Used in This Book
Using Code Examples
We’d Like to Hear from You
1. Customizing the User Environment
Introduction
1. Get the Most Out of the Default Shell
History and Auto-Completion
Editing and Navigating the Command Line
Learning from Your Command History
Silencing Auto-Complete
See Also
2. Useful tcsh Shell Configuration File Options
Making Your Prompt More Useful
Setting Shell Variables
3. Create Shell Bindings
Creating a Binding
Specifying Strings
See Also
4. Use Terminal and X Bindings
Creating Temporary Mappings
Shell Bindings Versus Terminal Bindings
More Mapping Caveats
Making Mappings Work with X
See Also
5. Use the Mouse at a Terminal
If X Is Already Installed
Configuring a two-button mouse
If X Is Not Installed
See Also
6. Get Your Daily Dose of Trivia
A Fortune a Day
Pursuing Trivia
Sundry Amusements
The current time
The phase of the moon
Adding Some Color to Your Terminal
See Also
7. Lock the Screen
Using lock
Using autologout
Enforcing Logout
See Also
8. Create a Trash Directory
Shell Scripting for the Impatient
The Code
Replacing rm with ~/bin/trash
Running the Code Safely
Taking Out the Trash
Hacking the Hack
9. Customize User Configurations
Default Files
dot.cshrc
dot.login
dot.login_conf
dot.mail_aliases and dot.mailrc
dot.profile
dot.rhosts
dot.shrc
Missing (but Useful) Dot Files
dot.logout
dot.xinitrc
Editing /usr/src/share/skel/Makefile
The Other BSDs
NetBSD
OpenBSD
See Also
10. Maintain Your Environment on Multiple Systems
Enter unison
Using unison
Automating the Process
Creating Portable Files
See Also
11. Use an Interactive Shell
Recording All Shell Input and Output
Cleaning Up script Files
Recording an Interactive Shell Session
Letting Other People Watch Your Live Shell Sessions
See Also
12. Use Multiple Screens on One Terminal
What Is screen?
Getting Started
Multitasking with screen
Using windows with screen
Switching between windows
Splitting windows
Better window switching
Naming windows
Attaching and Deattaching
Additional Features
See Also
2. Dealing with Files and Filesystems
Introduction
13. Find Things
Finding Program Paths
Finding Commands
Finding Words
See Also
14. Get the Most Out of grep
Finding Text
Searching by Relevance
Document Extracts
Using Regular Expressions
Combining grep with Other Commands
See Also
15. Manipulate Files with sed
Removing Blank Lines
Searching with sed
Replacing Existing Text
Multiple Transformations
See Also
16. Format Text at the Command Line
Adding Comments to Source Code
Removing Comments
Using the Holding Space to Mark Text
Translating Case
Translating Characters
Removing Duplicate Line Feeds
Deleting Characters
Translating Tabs to Spaces
See Also
17. Delimiter Dilemma
Attacking the Problem
The Code
Hacking the Hack
See Also
18. DOS Floppy Manipulation
Mounting a Floppy
Common Error Messages
Managing the Floppy
Allowing Regular Users to Mount Floppies
Formatting Floppies
Automating the Format Process
See Also
19. Access Windows Shares Without a Server
Installing and Configuring Sharity-Light
Accessing Microsoft Shares
See Also
20. Deal with Disk Hogs
Periodic Scripts
daily_clean_disks
daily_clean_tmps
daily_clean_preserve
Limiting Files
The Other BSDs
NetBSD
OpenBSD
See Also
21. Manage Temporary Files and Swap Space
Clearing /tmp
Moving /tmp to RAM
Creating a Swap File on Disk
Monitoring Swap Changes
OpenBSD Differences
See Also
22. Recreate a Directory Structure Using mtree
Necessary Interaction
Using mtree
Customizing mtree
See Also
23. Ghosting Systems
Creating the Ghost Disk
Creating an Image
Deploying the Image
See Also
3. The Boot and Login Environments
Introduction
24. Customize the Default Boot Menu
The Default Boot Menu
Configuring the Splash Screen
The Terminal Screensaver
See Also
25. Protect the Boot Process
Limiting Unauthorized Reboots
Password Protecting Single-User Mode
Password Protecting loader
See Also
26. Run a Headless System
Preparing the System
If the Headless System Becomes Inaccessible
See Also
27. Log a Headless Server Remotely
Enabling a Serial Console
Setting Up the Logging Server
Setting Up the Headless System
Shutting Down the Server Using wsmoused
Beep on Halt
See Also
28. Remove the Terminal Login Banner
Changing the Copyright Display
Changing the Message of the Day
Changing the Login Prompt
Testing Your Changes
See Also
29. Protecting Passwords With Blowfish Hashes
Protecting System Passwords in General
Protecting System Passwords with Blowfish
Converting existing passwords
Forcing new passwords to use Blowfish
See Also
30. Monitor Password Policy Compliance
Installing and Using crack
Monitoring the results
Cleanup
Customizing Password Dictionaries
See Also
31. Create an Effective, Reusable Password Policy
Introducing pam_passwdqc
Enabling pam_passwdqc
Adding Your Own Options
Additional Configuration
See Also
32. Automate Memorable Password Generation
Installing and Using apg
Improving apg
Script Walkthrough
See Also
33. Use One Time Passwords
Configuring OPIE
Generating Responses
Choosing When to Use OTP
See Also
34. Restrict Logins
/etc/ttys
/etc/login.access
/etc/ssh/sshd_config
/etc/login.conf
See Also
4. Backing Up
Introduction
35. Back Up FreeBSD with SMBFS
Adding NETSMB Kernel Support
Establishing an SMB Connection with a Host System
Mounting a Share
Archiving and Compressing Data with tar and gzip
Hacking the Hack
See Also
36. Create Portable POSIX Archives
GNU Versus POSIX tar
Replacing tar with pax
Compress Archives Without Using Intermediate Files
Attribute-Preserving Copies
Rooted Archives and the Substitution Argument
Useful Resources for Multiple Volume Archives
See Also
37. Interactive Copy
Finding Your Source Files
Renaming a Batch of Source Files
Renaming Files Interactively
See Also
38. Secure Backups Over a Network
Initial Preparation
The Backup
Automating the backup
See Also
39. Automate Remote Backups
Installing and Configuring rsnapshot
Specifying backup intervals
Preparing for script automation
Testing your config file
Scheduling rsnapshot
The Snapshot Storage Scheme
Accessing Snapshots
See Also
40. Automate Data Dumps for PostgreSQL Databases
Creating the Script
The Code
Running the Hack
See Also
41. Perform Client-Server Cross-Platform Backups with Bacula
Introducing Bacula
Installation
Configuration Files
File Daemon on the backup client
Storage Daemon on the backup server
Director on the backup server
Database Setup
Testing Your Tape Drive
Running Without Root
Starting the Bacula Daemons
Using the Bacula Console
Creating Backup Schedules
Creating a Client-only Install
See Also
5. Networking Hacks
Introduction
42. See Console Messages Over a Remote Login
The Console
Seeing Remote Console Messages
An Alternate Method
Hacking the Hack
See Also
43. Spoof a MAC Address
Spoofing on FreeBSD
Spoofing on NetBSD
Spoofing with OpenBSD
See Also
44. Use Multiple Wireless NIC Configurations
Initial Preparation
Preparing the Script
The Code
Running the Hack
Hacking the Hack
See Also
45. Survive Catastrophic Internet Loss
Hardware Configuration
Connectivity Software
Jabber and Ruby to the Rescue!
The Last Piece
See Also
46. Humanize tcpdump Output
The Basics
Display Filters
More Complicated Filters
Deciphering tcpdump Output
See Also
47. Understand DNS Records and Tools
Exploring Your ISP’s DNS
Understanding DNS entries
Securing DNS
The two-pronged approach
Testing DNS
See Also
48. Send and Receive Email Without a Mail Client
Sending Email with telnet
Testing for Relaying
Testing SMTP Server Availability
Reading Email with telnet
Security Considerations
See Also
49. Why Do I Need sendmail?
Closing Port 25
Simple sendmail Configuration with a Local MTA
Simple sendmail Configuration Without a Local MTA
See Also
50. Hold Email for Later Delivery
Configuring sendmail Queueing
Configuring PPP
Dealing with DNS
See Also
51. Get the Most Out of FTP
Automating Logins
Automating Transfers
Scripting an Entire Session
A Better FTP?
See Also
52. Distributed Command Execution
The Obvious Approach
How tentakel Can Help
Installing and Configuring tentakel
Using tentakel
See Also
53. Interactive Remote Administration
Why ClusterIt?
Installation and Configuration
Testing Noninteractive Commands
Using dvt
Hacking the Hack
See Also
6. Securing the System
Introduction
54. Strip the Kernel
Customizing Your Kernel
CPU options
System-specific options
Supported buses and media devices
Peripheral support and power management
Interface support
USB support
Building the New Kernel
Keeping Track of Your Options
Installing the New Kernel
See Also
55. FreeBSD Access Control Lists
Enabling ACLs
Additional UFS1 Configuration
Viewing ACLs
Adding and Subtracting ACLs
Using ACLs with Samba and Windows
Setting Default ACLs
See Also
56. Protect Files with Flags
Preventing File Changes
Watch Your Directories
Preventing Some Changes and Allowing Others
Log Protection
Protecting Binaries
Controlling Backups
See Also
57. Tighten Security with Mandatory Access Control
Preparing the System
Seeing Other Users
Quickly Disable All Interfaces
See Also
58. Use mtree as a Built-in Tripwire
Creating the Integrity Database
Preparing the Database for Storage
Using the Integrity Database
Deciding on Which Files to Include
See Also
59. Intrusion Detection with Snort, ACID, MySQL, and FreeBSD
Installing the Software
Install PHP4, Apache, and MySQL
Install MySQL-server
More installations
Configuring
Configure Apache and PHP
Configure PHP
Configure MySQL
Configure Snort
Configure ACID
Running ACID
Running Snort
Hacking the Hack
See Also
60. Encrypt Your Hard Disk
The Cryptographic Disk Device
Preparing the Disk
Scrubbing the Disk
Creating the Encrypted Disk Device
Modifying Configuration Files
Restoring Data
Hacking the Hack
Final Thoughts and Warnings
See Also
61. Sudo Gotchas
Limitations of sudo
sudo Configuration Gotchas
Shell Access with sudo
See Also
62. sudoscript
sudoscript Overview
Is sudoscript Secure?
Using sudoscript
The sudoscript Log File
See Also
63. Restrict an SSH server
Installing scponly
Testing the chroot
Now What?
See Also
64. Script IP Filter Rulesets
Limiting Access with IP Filter
Switching Rules on a Schedule
Hacking the Hack
See Also
65. Secure a Wireless Network Using PF
DHCP Configuration
PF Configuration
Apache Configuration
Putting it All Together
Security Concerns
Hacking the Hack
See Also
66. Automatically Generate Firewall Rules
What the Script Does
Installation
Example Usage
See Also
67. Automate Security Patches
Preparing the Script
Running the Hack
Automating the Process
See Also
68. Scan a Network of Windows Computers for Viruses
Preparing the Windows Systems
Preparing the FreeBSD System
Installing and Running the Virus Scanner
Automating the Process
See Also
7. Going Beyond the Basics
Introduction
69. Tune FreeBSD for Different Applications
Optimizing Software Compiling
Kernel Optimizations
Optimizing Network Performance
Optimizing Mail Servers
Optimizing File Servers
Optimizing Web Servers
See Also
70. Traffic Shaping on FreeBSD
Configuring Your Kernel for Traffic Shaping
Creating Pipes and Queues
Using Masks
Simple Configurations
Complex Configurations
See Also
71. Create an Emergency Repair Kit
Inventory of the Kit
Preparing the Floppies
The Rest of the Kit
Testing the Recovery Media
See Also
72. Use the FreeBSD Recovery Process
Using the fixit Floppy
Using the Live Filesystem
Emergency Repair
See Also
73. Use the GNU Debugger to Analyze a Buffer Overflow
An Example Exploit
Using the GNU Debugger
Hacking the Hack
See Also
74. Consolidate Web Server Logs
logproc Described
Preparing the Web Servers
Preparing the Log Host
Testing the Configuration
Configuring Scripts on the Log Host
Viewing Live Log Data
See Also
75. Script User Interaction
The Key Generation Process
A Simple Script
Adding User Interaction
Handling Incorrect Input
Hacking the Hack
See Also
76. Create a Trade Show Demo
Introducing eesh
Discovering Commands
Sample Scripts
More Complex Scripts
See Also
8. Keeping Up-to-Date
Introduction
77. Automated Install
Preparing the Install Script
Test-Drive
See Also
78. FreeBSD from Scratch
Stage One: System Installation
Stage Two: Ports Installation
Stage Three: Post-Configuration
See Also
79. Safely Merge Changes to /etc
Initial Preparations
Using etcmerge
See Also
80. Automate Updates
Assembling the Pieces
An Example Dry Run
Automating the Process
See Also
81. Create a Package Repository
Creating Custom Packages
Creating the NFS Share
See Also
82. Build a Port Without the Ports Tree
Connecting to Anonymous CVS
Checking Out Port Skeletons
Finding a Port and Its Dependencies
See Also
83. Keep Ports Up-to-Date with CTM
Using ftp and ctm to Stay Current
Hacking the Hack
See Also
84. Navigate the Ports System
Finding the Right Port
Dealing with Installed Ports
Checking Dependencies Before Uninstalling
Checking the Disk Space Your Ports Use
See Also
85. Downgrade a Port
Using portdowngrade
Preventing Automated Re-Upgrades
See Also
86. Create Your Own Startup Scripts
Was a Script Installed?
Creating Your Own Startup Script
Testing the Script
Hacking the Hack
See Also
87. Automate NetBSD Package Builds
Installing pkg_comp
Configuration Variables
Initializing and Using the Sandbox
Automating the Process
Hacking the Hack
See Also
88. Easily Install Unix Applications on Mac OS X
Installing DarwinPorts
Finding Ports to Install
Installing Ports
Updating the Ports Tree
See Also
9. Grokking BSD
Introduction
89. How’d He Know That?
Online Resources
Keeping Offline Resources Up-to-Date
What Did the Manpage Forget to Say?
See Also
90. Create Your Own Manpages
Manpage Basics
Creating a Manpage
Getting Fancier
Printing Manpages
Hacking the Hack
See Also
91. Get the Most Out of Manpages
Finding Installed Manpages
Navigational Tricks
Customizing less
Searching Text
See Also
92. Apply, Understand, and Create Patches
Finding Differences
Applying Patches
Creating Patches
Revision Control
See Also
93. Display Hardware Information
Viewing Boot Messages
Viewing Resource Information
Gathering Interface Statistics
Viewing Kernel Environment
See Also
94. Determine Who Is on the System
Who’s on First?
When Did That Happen?
Details, Details
See Also
95. Spelling Bee
Quick Spellcheck
Creating a Dictionary or Thesaurus
Improved Dictionary
Become a Crossword Champion
See Also
96. Leave on Time
Don’t Forget to Leave
Creating Terminal Sticky Notes
Saving Your Schedule
See Also
97. Run Native Java Applications
Choosing Which Java Port to Install
Running Java Applications
Standalone Java Applications
Javavmwrapper
Applets
Servlets
Java WebStart
See Also
98. Rotate Your Signature
If Your Mail Program Supports a Pipe
Pipeless Signature Rotation
Hacking the Hack
See Also
99. Useful One-Liners
Simultaneously Download and Untar
When Did I Change That File?
Finding Symlinks
Making cron More User-Friendly
See Also
100. Fun with X
Seeing Console Messages
Managing Your Clipboard
Sending Pop-up Messages
Understanding X authorization
Taking Screenshots
See Also
Index
About the Author
Copyright
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
BSD Hacks
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset