<<

. 33
( 69 .)



>>


SHUT DOWN AND RESTART THE COMPUTER
You can also specify a warning message that appears to

Y
ou can shut down or restart a Mac OS X system from
users. You can tell users that, although the system will be
the command line instead of the Aqua interface if you
shutting down, it will be available again at a specified time.
have access privilege. This is useful if you are not
For example, the command shutdown +15 "ferro
sitting at the system keyboard. The command to shut down
must be shut down for emergency service,
Mac OS X is shutdown. Although it is not the only way to
please log off" allows your users to finish work they
shut the system down, it is the safest. Using the shutdown
are doing, while letting them know that the system may be
command allows you to send warning messages to users
down for quite a while.
still logged onto the system that you are shutting down the
system. This gives them time to finish up what they are
The halt and reboot commands do not provide users
doing and log off.
with a grace period to complete their work, but terminate
running processes before the shutdown. Both commands
You can specify the time at which the system shuts down by
have options that change the way they run. For example,
entering a time in the yymmddhhmm format, or you can
with a -q argument, both of these commands shut down
enter a number, such as +15, to specify that the system
without terminating processes first.
shuts down in 15 minutes.



SHUT DOWN AND RESTART THE COMPUTER




› If a prompt appears, type ‹ Type your password at the
SHUT THE SYSTEM DOWN RESTART THE SYSTEM
your password, and press prompt, and press Return.
„ Type sudo followed by a „ Type sudo followed by a
Return.
– The system restarts
space. space.
– The system displays a immediately.
¤ Type shutdown followed ¤ Type reboot and press
warning and shuts down after
by space. Return.
five minutes.
‹ Type +5 "the system must
be shut down" and press
Return.

156
11
SYSTEM ADMINISTRATION COMMANDS




You can simplify the process of restarting or halting
If you enable the root account, you can shut
a system by using the fastboot or fasthalt
down or restart the system without using the
commands. These commands save time in the boot
sudo command. When you do not have the root
and halt processes, respectively, by skipping the
account enabled, you need the sudo command
process of checking your disks for integrity. Though
to give you the authority of root while you
these commands may save you time, you should
execute the shutdown command. The same is
use the more comprehensive shutdown and halt
true of the reboot and halt commands. Though
commands as they help ensure that your file systems
the shutdown, reboot, and halt commands
remain intact.
may appear simple, there is a lot that happens
during the shutting down or booting of a system.
If you look at /rc.boot and /etc/rc files, you can get
an idea about the processes that run when a system
boots. The scripts in these files manage a large part
of the boot process.




‹ If a prompt appears, type › Type sudo kill followed
HALT THE SYSTEM STOP A SHUTDOWN
your password, and press by the process ID of the
„ Type sudo followed by a „ Type sudo shutdown +5
Return. shutdown process, then
space. "system going down for
press Return.
– The system halts maintenance" and press
¤ Type halt and press
ˇ If a prompt appears, type
Return.
immediately.
Return.
your password, and press
¤ If a prompt appears, type Return.
your password, and press
– The shutdown aborts.
Return.
‹ Type ps -aux | grep shut
157
and press Return.
UNIX FOR MAC




CREATE A NEW USER
of commands that add the new users to the system.

Y
ou can easily add a new user to your Mac OS X
Current account information may or may not appear in
system by using the Accounts tool found in System
the /etc/passwd file on your system. Mac OS X does not
Preferences, or from the command line in a Terminal
use the information in the /etc/passwd file but uses similar
window. When you add a new user to your system using
information stored in a database called NetInfo.
the Accounts tool, you must fill out a form with information
describing the new user. You need to assign a username and
You can use the nidump command to list the password
a password. If you want, you can supply a password hint to
information that your system uses. Similarly, you can load
help the user when they cannot remember the password.
new information into the NetInfo databases using the
You can also incorporate an image into the logon page.
niload command. The niutil command allows you to
read and write NetInfo data. For example, using the
When you use the command line method to add new users,
niutil command, you can add each portion of a user
you can create a file containing the information describing
record to the database using a separate command, or
the new users, or you can build a script containing a series
modify a portion of a user record.




CREATE A NEW USER




– The text editor opens with
„ Type nidump passwd . and ¤ Type nidump passwd . > ‹ Type vi passwd.txt and
press Return. passwd.txt and press Return. press Return. a copy of the current user
information.
– A copy of your current – A copy of your current
user information appears. user information is placed
into a text file.



158
11
SYSTEM ADMINISTRATION COMMANDS

If you add users frequently or manage a efficient. The script below contains niutil
system remotely, you can build a script to commands that prompt for each piece of
reduce typing and make the process more information it needs to create a new user, $user.

Example:
#!/bin/sh
# add a user

echo -n "username: " ; read user
echo -n "full name: " ; read fname
echo -n "shell: " ; read shell
uhome=/Users/$user

niutil -create . /users/$user
niutil -createprop . /users/$user passwd
niutil -createprop . /users/$user uid $uid
niutil -createprop . /users/$user gid $gid
niutil -createprop . /users/$user realname $fullname
niutil -createprop . /users/$user shell $shell
niutil -createprop . /users/$user home $homedir
niutil -createprop . /users/$user _shadow_passwd ""

mkdir $uhome
chmod 755 $uhome
chown $user $uhome

echo "password: "
passwd $user




› Press Shift + G, and then ˇ Press O, and then ‡ Type sudo niload passwd . · Type nidump passwd . and
press Return. type sbob::512:20:Spong < passwd.txtPassword: and press Return.
press Return.
Bob:/Users/sbob:/bin/tcsh,
– Your changes are loaded
ensuring no other user is
° If a prompt appears, type into NetInfo.
assigned UID 512.
your password, and press
– The new password
Á Save your file, and exit vi. Return.
information appears,
confirming your changes.
159
UNIX FOR MAC




ENABLE THE ROOT USER ACCOUNT
must always be careful when you do so. Use of root

Y
ou can enable the root user account, which allows
privilege allows you to modify system configuration files,
you to switch user to root ” or to log on as root ”
store files in directories that are owned by root, shut down
in addition to exercising root authority using the
or reboot the system, and add or remove user accounts.
sudo command that allows you to run commands as root if
you are an administrator. The root account on a Unix system
The root account is disabled by default in the root account
is the only account that can perform any action; you should
information stored in your NetInfo database. This means
use it sparingly as the system is not protected from any
that you cannot log on as root, nor can you use the su
action that this user takes. While normal users cannot
command to switch users. You can enable it in one of two
overwrite files that do not belong to them, root can
ways. The first is to use the NetInfo Manager. To do this, you
overwrite any file on the system, regardless of who owns it
need to authenticate yourself by entering your password,
and how important it is to the proper running of the
after which you can initiate the change in the root account
system. To use the sudo command, you type sudo followed
by selecting an option to enable the root account. The
by the command you want to run as root.
second method is to change the root password from the
command line.
There are times when logging on as root or switching user
to root simplifies the work that you have to do, but you



ENABLE THE ROOT USER ACCOUNT
Security
Authenticate...




– The NetInfo Manager – An administrator name
Note: For instructions on locating
ENABLE ROOT USING
NETINFO MANAGER the NetInfo Manager in the Utilities window opens. and password dialog box
„ Open the NetInfo folder, see page 4. appears.
¤ Click Security ➪
Manager application. ‹ Type your password.
Authenticate.
› Click OK.

<<

. 33
( 69 .)



>>