- •Table of Contents
- •Introduction
- •Saving Time with This Book
- •Foolish Assumptions
- •Part I: Making the Desktop Work for You
- •Part II: Getting the Most from Your File System
- •Part III: Good Housekeeping with Linux
- •Part IV: Tweaking the Kernel on Your Linux System
- •Part V: Securing Your Workspace
- •Part VI: Networking Like a Professional
- •Part VII: Monitoring Your System
- •Part VIII: Serving Up the Internet and More
- •Part X: Programming Tricks
- •Part XI: The Scary (Or Fun!) Stuff
- •Icons Used in This Book
- •Discovering Your Protocols
- •Managing Snapshots with the camera: Protocol
- •Remote File Management with fish:
- •Getting Help with help:, info:, and man:
- •Other KDE Protocols
- •Using GNOME VFS Modules
- •Stacking VFS Modules
- •Working with Packages: rpm and rpms
- •Putting VFS to Work at the Command Line
- •Burning CDs with a VFS
- •Skinning Your Desktop with VFS
- •Classifying Data with MIME
- •Creating KDE File Associations
- •Creating New MIME Types with GNOME
- •Making Basic Prompt Transformations
- •Adding Dynamically Updated Data to Your Prompt
- •Colorizing Your Prompt
- •Seeing a Red Alert When You Have Superuser Privileges
- •Saving Your Work
- •Completing Names Automatically
- •Using the Escape Key to Your Advantage
- •Customizing Completion for Maximum Speed
- •Using cd and ls to Navigate through bash
- •Setting Your CDPATH Variables to Find Directories Fast
- •Streamlining Archive Searches
- •Turning the Output of a Command into a Variable with $( )
- •Using $UID and $EUID in Shell Scripts
- •Customizing Variables for Rapid Transit
- •Finding the Right Shell Script
- •Choosing your victims
- •Timing is everything
- •Cleaning up made easy
- •Changing prototype scripts
- •Customizing Your Autostart File
- •Navigating the History List
- •Scrolling
- •Summoning a command by number
- •Searching through history
- •Customizing the History List
- •Adjusting key default settings
- •Filtering the history list
- •Executing Commands Quickly with History Variables
- •Viewing Your Aliases
- •Using Aliases for Complex Commands
- •Automating Tedious Tasks with Functions
- •Filtering file searches by file type
- •Automatic downloading
- •Monitoring Your System in a Snap
- •Un-tarring the Easy Way
- •What Is Samba?
- •Getting Up and Running with Samba
- •Checking whether Samba is installed
- •Enabling Samba
- •Adjusting the workgroup name and creating user accounts
- •Giving a Windows machine access to your home directory
- •Sharing Linux files and directories with other computers
- •Hooking Everyone Up to the Printer
- •Sharing Linux printers with SWAT
- •Using a Windows printer from Linux
- •Plugging In to Remote Data with Linux Programs Quickly
- •Finding Files with locate
- •Finding Files with find
- •Qualifying Your Search with the find Command
- •Doing updated filename searches
- •Adding time-based qualifications
- •Filtering by file size
- •Perusing commonly used qualifications
- •Acting on What You Find
- •Displaying specific info with -printf
- •Checking disk usage by user
- •Executing commands with find
- •Building Complex Commands with xargs
- •Creating Archives with File Roller
- •Inspecting and Extracting Archives with File Roller
- •Adding Functionality to tar with Complex Commands
- •Building archives from the command line
- •Archiving complex search results
- •Backing up an installed package
- •Uprooting Entire Directory Trees with scp
- •Splitting Big Files into Manageable Chunks
- •Building Software from Downloaded tarballs
- •Compiling a tarball: The basic steps
- •Downloading and compiling SuperKaramba
- •Versatile Downloading with wget
- •Mirroring sites with wget
- •Verifying your bookmarks with wget
- •Downloading files with wget
- •Downloading and unpacking in one quick step
- •Downloading and Uploading with curl
- •Setting Up ADIOS
- •Downloading ADIOS
- •Burning ADIOS to CD
- •Installing ADIOS
- •Finding Your Way around UML
- •Connecting to the Internet from an ADIOS VM
- •Using a GUI with UML
- •Installing Software into UML
- •Merging Changes to Your Prototype
- •Querying RPM Packages for Content
- •Digesting Information
- •Creating a Package Index
- •Querying for Prerequisites
- •Dissecting an RPM Package
- •Using RPM at the Command Line
- •Removing RPMs
- •Flagging Down RPM
- •Getting Graphic with RPM
- •Using Rpmdrake to install from media
- •Installing from your Konqueror browser
- •Verifying Your System
- •Reading the Tamper-Proof Seal
- •Setting Up Synaptic and apt in a Snap
- •Keeping Up-to-Date with apt and Synaptic: The Basics
- •Handy Hints about Synaptic
- •Changing repositories
- •Viewing package details
- •Installing new packages with Synaptic
- •Importing the Keys to the Repository
- •Letting Task Scheduler Work for You
- •Scheduling a new task
- •Editing a task
- •Adding environment variables
- •Reining In Resources with Disk Quotas
- •Installing the quota RPM package
- •Enabling file system quotas
- •Getting your files together
- •Setting quotas
- •Reviewing your quotas
- •Using System Accounting to Keep Track of Users
- •Setting up system accounting
- •Looking up user login hours
- •Checking out command and program usage
- •Running Down the Runlevels
- •Runlevel basics
- •Customizing runlevels in Fedora
- •Customizing runlevels in SuSE
- •Customizing runlevels in Mandrake
- •Customizing runlevels at the command line
- •Switching to a new runlevel
- •Disabling Unused Services
- •Removing Unneeded Services
- •Learning about modules
- •Installing a module with insmod
- •Taking care of dependencies automatically with modprobe and depmod
- •Loading a module for a slightly different kernel with insmod and modprobe
- •Removing modules with rmmod
- •Step 1: Making an Emergency Plan, or Boot Disk
- •Step 2: Finding the Source Code
- •Step 4: Customizing the Kernel
- •Step 5: Building the Kernel
- •Understanding the Principles of SELinux
- •Everything is an object
- •Identifying subjects in SELinux
- •Understanding the security context
- •Disabling or Disarming SELinux
- •Playing the Right Role
- •Exploring the Process-Related Entries in /proc
- •Surveying Your System from /proc
- •Popping the Cork: Speeding Up WINE with /proc
- •Reading and Understanding File Permissions
- •Controlling Permissions at the Command Line
- •Changing File Permissions from a Desktop
- •Encryption Made Easy with kgpg and the KDE Desktop
- •Creating keys with kgpg
- •Sharing your key with the world
- •Importing a public key from a public-key server
- •Encrypting and decrypting documents with drag-and-drop ease
- •Encrypting Documents with gpg at the Command Line
- •Sharing a secret file
- •Creating a key pair and receiving encrypted documents
- •Encrypting documents on your home system
- •Encrypting E-Mail for Added Security
- •Encrypting with Ximian Evolution
- •Setting up Mozilla e-mail for encryption
- •Sending and receiving encrypted messages with Mozilla mail
- •Using Cross-Platform Authentication with Linux and Windows
- •Prepping for cross-platform authentication
- •Setting up cross-platform authentication
- •Using PAM and Kerberos to Serve Up Authentication
- •Establishing synchronized system times
- •Testing your domain name server (DNS)
- •Setting up a Key Distribution Center
- •Setting up automatic ticket management with Kerberos and PAM
- •Adding users to the Key Distribution Center
- •Building Good Rules with PAM
- •Phase
- •Control level
- •Module pathname
- •Arguments
- •Dissecting a Configuration File
- •Skipping a Password with PAM
- •Feeling the Power
- •Gaining Superuser Privileges
- •Pretending to Be Other Users
- •Limiting Privileges with sudo
- •Installing sudo
- •Adding Up the Aliases
- •Adding Aliases to the sudo Configuration File
- •Defining the Alias
- •Creating a User_Alias
- •Creating a Runas_Alias
- •Simplifying group managment with a Host_Alias
- •Mounting and unmounting CDs without the superuser password
- •Managing access to dangerous commands with command aliases
- •Using SSH for Top-Speed Connections
- •Setting Up Public-Key Authentication to Secure SSH
- •Generating the key pair
- •Distributing your public key
- •Passing on your passphrase
- •Logging In with SSH and Key Authentication
- •Starting from the command line
- •Getting graphic
- •Creating Shortcuts to Your Favorite SSH Locations
- •Copying Files with scp
- •Secure (And Fast) Port Forwarding with SSH
- •Finding Your Firewall
- •Setting up a simple firewall in Mandrake Linux
- •Setting up a simple firewall in Fedora Linux
- •Setting up a simple firewall in SuSE Linux
- •Editing the Rules with Webmin
- •Starting a Webmin session
- •Reading the rules with Webmin
- •Changing the rules
- •Editing existing rules
- •Adding a new rule with Webmin
- •Sharing Desktops with VNC
- •Inviting Your Friends to Use Your Desktop
- •Serving Up a New Desktop with VNC Server
- •Using tsclient to View Remote Desktops from Linux
- •Using tsclient with a VNC server
- •Using tsclient with an RDP server
- •Creating New VNC Desktops on Demand
- •Switching display managers in SuSE Linux
- •Switching display managers in Mandrake Linux
- •Connecting gdm and VNC
- •Exploring Your Network with lsof
- •Running lsof
- •Interpreting the lsof output
- •Reading file types
- •Discovering Network Connections
- •Other Timesaving lsof Tricks
- •Packet Sniffing with the Ethereal Network Analyzer
- •Starting Ethereal
- •Capturing packets
- •Applying filters to screen packets
- •Peeking in packets
- •Color-coding packets coming from your network
- •Getting Up and Running with Nessus
- •Installing programs Nessus needs to run
- •Installing Nessus
- •Adding a user to Nessus
- •Generating a certificate
- •Starting the daemon and the interface
- •Reading the grim results
- •Keeping Your Plug-ins Up-to-Date
- •Chatting in the Fedora Chat Room
- •Looking for Answers in the SuSE Chat Room
- •Processing Processes with procps
- •Using ps to filter process status information
- •Viewing ps output the way you want to see it
- •Making parent-child relationships stand out in a ps listing
- •Climbing the family tree with pstree
- •Finding processes with pgrep
- •Killing Processes with pkill
- •Killing Processes with killall
- •Closing Windows with xkill
- •Managing Users and Groups with the Fedora/Mandrake User Manager
- •Adding new users
- •Modifying user accounts
- •Adding groups
- •Filtering users and groups
- •Managing Users and Groups with the SuSE User Administrator
- •Adding new users
- •Modifying user accounts
- •Adding groups
- •Filtering users and groups
- •Adding and deleting log files from the viewer
- •Setting up alerts and warnings
- •Viewing your log files from SuSE
- •Monitoring your log files from SuSE
- •Customizing Your Log Files
- •Keeping an Eye on Resources with KDE System Guard
- •Finding and killing runaway processes
- •Prioritizing processes to smooth a network bottleneck
- •Watching your system load
- •Creating a new worksheet
- •Creating system resource logs
- •Displaying network resources
- •Using Synaptic to download and install Apache
- •Installing Apache from disc
- •Starting the Apache Service
- •Building a Quick Web Page with OpenOffice.org
- •Taking Your Site Public with Dynamic DNS
- •Understanding how dynamic DNS works
- •Setting up dynamic DNS
- •Updating your IP address
- •Installing the Fedora HTTP Configuration tool
- •Putting the HTTP Configuration tool to work
- •Watching Your Web Server Traffic with apachetop
- •Installing apachetop
- •Running and exiting apachetop
- •Navigating apachetop
- •Switching among the log files (or watching several at once)
- •Changing the display time of apachetop statistics
- •Accessing MySQL Control Center features
- •Viewing, managing, and repairing a database with the Databases controls
- •Putting the Server Administration controls to work
- •Adding a new user
- •Watching Your MySQL Traffic with mtop
- •Gathering all the packages that mtop needs
- •Installing mtop
- •Monitoring traffic
- •Building a MySQL Server
- •Installing the necessary packages
- •Starting the MySQL server
- •Replicating MySQL Data
- •Configuring replication: The three topologies
- •Setting up replication for a single slave and master
- •Choosing a Method to Back Up MySQL Data
- •Backing Up and Restoring with mysqldump
- •mysqldump backup options
- •Backing up multiple databases
- •Compressing the archive
- •Restoring a mysqldump archive
- •Making a mysqlhotcopy of Your Database
- •Archiving a Replication Slave
- •Taking Care of Business with MySQL Administrator
- •Installing MySQL Administrator
- •Starting MySQL Administrator
- •Choosing an SSL Certificate
- •Creating a Certificate Signing Request
- •Creating a Signing Authority with openssl
- •Creating a certificate authority
- •Signing a CSR
- •Exploring Your Certificate Collection with Mozilla
- •Introducing hotway
- •Getting Started with hotway
- •Setting Up Evolution to Read HTTPMail Accounts with hotway
- •Ringing the Bells and Blowing the Whistles: Your Evolution Summary Page
- •Installing SpamAssassin
- •Installing from the distribution media
- •Installing from RPM downloads
- •Starting the service
- •Fine-Tuning SpamAssassin to Separate the Ham from the Spam
- •Customizing settings
- •Saving your settings
- •Adding a New Filter to Evolution
- •Serving Up a Big Bowl of the RulesDuJour
- •Registering Your Address
- •Taming a Sendmail Server
- •Tweaking Your Configuration Files with Webmin
- •Serving up mail for multiple domains
- •Relaying e-mail
- •Using aliases to simplify mail handling
- •Deciding What to Archive
- •Choosing Archive Media
- •Tape drives
- •Removable and external disk drives
- •Removable media
- •Optical media (CDs and DVDs)
- •Online storage
- •Choosing an Archive Scheme
- •Full backups
- •Differential backups
- •Incremental backups
- •Incremental versus differential backups
- •Choosing an Archive Program
- •Estimating Your Media Needs
- •Creating Data Archives with tar
- •Backing up files and directories
- •Backing up account information and passwords
- •Targeting bite-sized backups for speedier restores
- •Rolling whole file systems into a tarball
- •Starting an Incremental Backup Cycle
- •Restoring from Backup with tar
- •Backing Up to CD (Or DVD) with cdbackup
- •Creating the backup
- •Restoring from a CD or DVD backup
- •Restoring from a disc containing multiple archives
- •Combining the Power of tar with ssh for Quick Remote Backups
- •Testing the ssh connection to the remote host
- •Creating a tar archive over the ssh connection
- •Backing up to tape drives on remote machines
- •Backing Up to a Remote Computer with rdist and ssh
- •Testing the ssh connection to the remote host
- •Creating the distfile
- •Backing up
- •Getting Started with CVS
- •Checking whether CVS is installed
- •Discovering what to use CVS for
- •Creating a CVS Repository
- •Populating Your Repository with Files
- •Simplifying CVS with cervisia
- •Installing cervisia
- •Putting files in your sandbox
- •Adding more files to your repository
- •Committing your changes
- •Browsing your log files
- •Marking milestones with tags
- •Branching off with cervisia
- •Using the libcurl Library (C Programming)
- •Uploading a File with a Simple Program Using libcurl
- •Line 7: Defining functions and data types
- •Line 14: Calling the initialization function
- •Lines 18– 21: Defining the transfer
- •Line 23: Starting the transfer
- •Line 26: Finishing the upload
- •Installing the Ming Library
- •Building a Simple Flash Movie with Ming
- •Examining the program
- •Compiling the program
- •Running the program
- •Building Interactive Movies with Ming
- •Examining the program
- •Compiling the program
- •Running the program
- •Doing the curl E-shuffle with PHP
- •Combining PHP with curl and XML: An overview
- •Checking out the XML file
- •Downloading and displaying the XML file with a PHP script (and curl)
- •Sending E-Mail from PHP When Problems Occur
- •Debugging Perl Code with DDD
- •Installing and starting DDD
- •Examining the main window
- •Reviewing and stepping through source code
- •Making Stop Signs: Using Breakpoints to Watch Code
- •Setting a breakpoint
- •Modifying a breakpoint
- •Opening the data window
- •Adding a variable to the data window
- •Changing the display to a table
- •Using the Backtrace feature
- •Using the Help menu
- •Making Fedora Distribution CDs
- •Downloading the ISO images
- •Verifying the checksums
- •Burning an ISO File to Disc at the Command Line
- •Finding the identity of your drive
- •Running a test burn
- •Burning the distribution discs
- •Burning CDs without Making an ISO First
- •Finding setuid quickly and easily with kfind
- •Finding setuid and setgid programs at the command line
- •Deciding to Turn Off setuid or setgid
- •Changing the setuid or setgid Bit
- •Who Belongs in Jail?
- •Using UML to Jail Programs
- •Using lsof to Find Out Which Files Are Open
- •Debugging Your Environment with strace
- •Investigating Programs with ltrace
- •Handy strace and ltrace Options
- •Recording Program Errors with valgrind
- •Hardening Your Hat with Bastille
- •Downloading and installing Bastille and its dependencies
- •Welcome to the Bastille
- •Addressing file permission issues
- •Clamping down on SUID privileges
- •Moving on to account security
- •Making the boot process more secure
- •Securing connection broker
- •Limiting compiler access
- •Limiting access to hackers
- •Logging extra information
- •Keeping the daemons in check
- •Securing sendmail
- •Closing the gaps in Apache
- •Keeping temporary files safe
- •Building a better firewall
- •Port scanning with Bastille
- •Turning LIDS On and Off
- •Testing LIDS before Applying It to Your System
- •Controlling File Access with LIDS
- •Hiding Processes with LIDS
- •Running Down the Privilege List
- •Getting Graphical at the Command Line
- •Getting graphical in GNOME
- •Getting graphical with KDE
- •Staying desktop neutral
- •Index
210 Technique 31: Gaining Privileges
Sometimes, you need to do those things because users come and go, passwords are forgotten, and files need changing. Save yourself a lot of time by limiting your powers and minimizing the damage that you can do. Save the power for when you really need it.
Gaining Superuser Privileges
Given all the exciting and hazardous things that a superuser can do, how do you become one? Simple: Just type su at the command prompt. Okay, the process is not quite as simple as that — you also have to know the superuser’s password.
Here’s a short example. Say that you want to modify the /etc/motd file. (The content of /etc/motd is displayed whenever you log in to your system — motd stands for message of the day.) Customizing /etc/ motd is a quick way to alert your users that something important is happening today. On most systems, /etc/motd can be modified only by the superuser, as described in the following steps:
1. Log in to your system as a normal (that is, nonsuperuser) user.
2. Type the su command at the prompt:
[freddie@bastille /]$ su
su requests the superuser password:
Password: <enter the superuser password here>
3. Enter the password.
If you’ve entered the correct password, the prompt changes from $ to # to remind you that you hold elevated privileges. See the “Do- it-yourself identity checking” sidebar for details on an even better way to see your privileges at the prompt.
[root@bastille /]#
At this point, su starts a new, highly privileged shell for you.
4. Overwrite the /etc/motd file as follows:
[root@bastille /]# echo “Bastille will be down this evening for an upgrade” > /etc/motd
[root@bastille /]#
5. Now here’s the most important part: Exit the privileged shell, forfeiting your new privileges:
[root@bastille /]# exit [freddie@bastille /]$
Do-it-yourself identity checking
The bash shell is just trying to be helpful when it changes your prompt from $ to # (and back again), but if you modify your prompt, you can’t rely on this cue. For a more definitive hint, the id command is your answer. id prints out your current identity:
[freddie@bastille /]$ id uid=501(freddie) gid=501(freddie)
groups=501(freddie)
Notice that id printed your user ID (and name) and a list of groups to which you belong (in this case, a single group named freddie). Now give yourself superuser privileges and try the id command again:
[freddie@bastille /]$ su Password:
[root@bastille /]# id uid=0(root) gid=0(root) groups=
0(root),1(bin), ...
[root@bastille /]# exit [freddie@bastille /]$ id uid=501(freddie) gid=501(freddie)
groups=501(freddie)
You see that the su command changes more than just your privileges: It changes your identity as well.
Pretending to Be Other Users
Because su gives you a way to become the superuser, you may be thinking that su stands for superuser.
In fact, su stands for substitute user: You can impersonate any user with su (as long as you know the right password).
Limiting Privileges with sudo 211
One reason that you might want to impersonate another user is to gain privileges to a particular piece of software, but you may not need all the privileges of the superuser to accomplish what you need to do. If you give yourself only the privileges that you need instead of giving yourself the power to accidentally destroy your system, you’ll save yourself a lot of grief and wasted time.
To see how impersonating a user without gaining all the powers of the superuser works, take MySQL as an example. When you install a MySQL database, you usually create a new user account for the MySQL administrator. The MySQL administrator is not a real person (in most cases), it’s just a name for a set of privileges. To fire up your MySQL database, you must become the MySQL administrator for a while:
[freddie@bastille /]$ su – mysql [mysql@bastille /]$ id
uid = 301(mysql) gid=301(mysql) groups=301(mysql)
[mysql@bastille /]$ mysqld_safe & [mysql@bastille /]$ exit
Notice the hyphen in this command, which tells su to invoke the login scripts for user mysql. When you run su without a hyphen, you’re impersonating another user. When you run su with a hyphen, you’re impersonating another user and inheriting the environment variables (and shell aliases and functions) that belong to that user.
The most common problem you run into
(if you forget the hyphen) is that your $PATH environment variable is wrong. For example, if you forget the hyphen when you su mysql, it’s pretty unlikely that the mysqld_safe command will be in your $PATH search path: mysqld_safe is on mysql’s search path. In other words, su - is a complete impersonation.
Limiting Privileges with sudo
a bazooka; sure, you can hunt squirrels that way, but it’s safer to use a smaller armament. If you’re running a shell while you have superuser privileges, it’s just too easy to make a typing mistake that deletes important information. (Trust us, we’ve done that a few too many times.)
One way to avoid shooting yourself in the foot is to use sudo instead of su. From a user’s point of view, sudo is very similar to su: Each command starts a new program that holds elevated privileges. su gives you all privileges, but sudo gives you only the privileges granted by an administrator. In other words, sudo gives you a way to grant partial privileges to those who need them, without giving them the whole bazooka. Really, you need to su only when you configure sudo.
The whole point of using sudo (instead of su) is to save yourself time by avoiding disasters. If you decide to use su in your normal course of work, be sure to read Techniques 49 and 50 (backup and recovery).
sudo is controlled by a configuration file named /etc/sudoers. The layout of a sudoers file can be a bit confusing at first, but don’t be intimidated. Here’s a simple /etc/sudoers file:
# file: |
/etc/sudoers |
freddie |
bastille = /bin/mount |
The first line is a comment (anything that follows a # is treated as a comment). The second line grants user freddie the right to run the /bin/mount command as long as he’s logged into a computer named bastille.
Now if freddie wants to mount a file system, he’ll have to ask sudo to do the work for him:
[freddie@bastille /]$ sudo mount /dev/cdrom /mnt/cdrom
[freddie@bastille /]$
|
|
When you add entries to the sudoers file, be |
What’s wrong with the su command? Running a shell |
|
sure to include the complete pathname to |
|
each command. If you don’t, dastardly users |
|
as the superuser is sort of like hunting squirrels with |
|
|
|
|
212 Technique 31: Gaining Privileges
can simply slip a bogus program (with the same name) into their search path and gain privileges that you don’t want them to have.
The first time you edit the /etc/sudoers file, you’ll notice that it’s already filled in with sample entries. Don’t even look at them. They’re too confusing. Just add the one or two lines that you need and ignore the samples.
Freddie can now mount CDs, but he can’t unmount them. That’s easy to fix; just add the umount command to the list of privileges:
# file: /etc/sudoers
freddie bastille = /bin/mount, /bin/ umount
Now freddie can mount and unmount file systems. But what if you want freddie to mount and unmount only CDs, not other file systems? That’s easy, too:
# file: /etc/sudoers
freddie bastille = /bin/mount /dev/cdrom, /bin/umount /dev/cdrom
Save time by including host names in the sudoers file, maintaining a single master copy of the file, and copying it to each machine on your network. That way, you don’t have to create a separate sudoers file for each machine. In fact, you can store the sudoers file in CVS
(see Technique 13) to maintain a complete history of all the privileges you’ve ever granted on your entire network.
Of course, you can also list multiple users in the same sudoers file:
# file: /etc/sudoers
freddie bastille = /bin/mount /dev/cdrom, /bin/umount /dev/cdrom
franklin,tex versaille = /usr/bin/reboot, /sbin/dump, /sbin/restore
The third line grants two users (franklin and tex) the right to reboot and the rights to backup and restore, but only on a host named versaille.
You can see the pattern: Each entry starts with a user name (or a list of user names), a host name (or a list of host names), an equals sign, and then a command (or list of commands). Each entry grants a set of privileges to one or more users on one or more hosts.
The man pages for sudo (and sudoers) state that you must use the visudo command to edit the /etc/sudoers file. That’s not really true; you can use any editor you like. visudo does some extra error checking whenever you save your file, but we find the error messages to be more confusing than helpful.
32 sudo Pseudonyms
Technique
Save Time By
Creating a User_Alias to manage group privileges
Using a Host_Alias to assign resource privileges to groups
Creating a Cmnd_Alias to keep dangerous com-
mands under control
Sharing superuser commands without sharing the password
Every system administrator walks a thin tightrope. On one hand, you must secure your system against both accidental and intentional damage. On the other hand, you can’t tighten security to the point
where average users can’t get their jobs done. In a traditional Linux (or UNIX) system, privileges are granted to the superuser. If you need a privilege, you impersonate the superuser (with the su command). The problem with this approach is that you gain all privileges as soon as you know the superuser password. Give yourself enough privileges to mount a CD, and you’ve also gained enough privileges to delete every file on your computer. sudo (see Technique 31) can help by handing out privileges to specific users and programs. But if you have a mediumto large-sized network, managing sudo privileges can become a time consuming chore.
Assigning privileges with sudo aliases can help make quick work of the task. A sudo alias is an easy way to refer to a group of users, hosts, or commands when handing out privileges that are normally given to the superuser. The elements of the superuser privileges can be assigned individually, so the administrator doesn’t have to give out the root password. Only the privileges that a user really needs are given out.
With sudo aliases, you can create User_Alias groups to assign privileges to groups of users. If the group (or department) gains new users, just add those new users to the User_Alias, and they automatically have all the privileges shared by that group. No one gets the superuser password, so you don’t need to worry about runaway superuser privileges.
Host aliases allow you to control groups of computers with one set of privilege assignments. You can quickly combine user aliases and host aliases to grant access to machine resources to the users that really need the resources, but still restrict the superuser privileges that might pose a security threat to the system.
In this technique, we show you how to save time by using sudo’s aliases to assign privileges to groups. When you become a sudo superuser, you really start to save time. In this technique, we show you how to use sudo aliases to save time assigning privileges. And your system will be a safer place for it.