05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

By default, sudo will allow root and any user in the admin group to utilize it. If a nonadmin<br />

user attempts to use sudo, instead of their chosen command being executed, they will be presented<br />

with the following warning:<br />

user is not in the sudoers file. This incident will be reported.<br />

To run a command as a user other than root, sudo offers the -u option, which you would use<br />

as follows:<br />

sudo -u username command<br />

On the slight chance that you really must execute a series of commands as another user and<br />

you’d like to maintain the user state for an extended period of time, sudo offers a the -s option,<br />

which will in effect start the shell as the specified user. Since this command starts a shell as the<br />

specified user or root, no additional command is necessary. By default, this is the equivalent of<br />

using the older su command. If you must use this (and it’s recommended that you don’t), it’s<br />

important to remember to quit as soon as you are done—otherwise, you will remain in root state<br />

and are more likely to do something regrettable (or forget you are logged in as root and walk<br />

away from your computer for a cup of coffee or something and allow someone else do something<br />

perhaps even more regrettable)!<br />

NOTE Before there was sudo, there was su (substitute user). Rather than taking a command,<br />

su just dropped you into a shell as root or the specified user. For whatever reason, many oldtime<br />

UNIX users still swear by the su command, and while these are generally intelligent<br />

people who can perform amazing computer tasks in their sleep, their stubbornness in regard<br />

to su is misplaced. You shouldn’t use su on the <strong>Mac</strong> (and yes, it is there). su was written in a<br />

time of relative innocence, when mail servers didn’t require passwords and spam filters didn’t<br />

exist, when virus protection wasn’t a billion-dollar industry, and “god” was an appropriate (and<br />

sadly all too common) password for the root user. Anyway, those days are gone, and su just<br />

doesn’t provide the features and, more importantly, the security that sudo provides (such as<br />

fine-grained per-user and per-group customizability, sophisticated checks on timestamps and<br />

files to assure that nobody has tampered with the file, and more).<br />

sudoers<br />

The sudo defaults are sensible and appropriate for most computer uses. However, for servers or<br />

other computers with many users, sudo can be coaxed into providing very specific, fine-grained<br />

privileges to individual users or groups. To do this requires editing the /etc/sudoers file. The<br />

catch is that to edit this file, you must have root privileges and you must use a special editor<br />

named visudo. visudo is really a special mode of the Vi editor—or more specifically, Vim, which<br />

stands for vi improved, and is installed on <strong>Leopard</strong> in place of Vi. The easiest way to accomplish<br />

all this is to merely use the following:<br />

<strong>Leopard</strong>:~ scott$ sudo visudo<br />

Password:<br />

CHAPTER 18 INTRODUCING DARWIN AND THE SHELL 311<br />

This will immediately open up the sudoers file to be edited (assuming you understand how<br />

Vi works, which if you don’t right now, I will explain in the next section).<br />

Sadly, a discussion on the many specific tweaks that can be made to this file would extend<br />

far beyond the confines of this book. However, typing man sudoers will bring you to the man page<br />

for this particular file and will explain in detail things like the extended Backus-Naur form, what<br />

exactly it means, and how to put it to use.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!