Although you should use the Administrative User identity
to do most of your work, there are times (for installations and editing certain
files, such as /usr/local/etc/sudoers) when
you need to work as the root user.
The su and sudo commands
Just exactly what is meant by su is a subject for debate. A search for su displays such definitions as “switch user,”
“substitute user identity,” and “become superuser.” The main idea is present in
them all: switching users.
Using su
As the Administrative User, you can become root in these
ways:
% su root
% root’s password
switches to Administrative User but retains the shell
settings of root.
% su – root
% root’s password
A hyphen in the command resets the shell settings (by
reading the .rc file) to those of root.
Using sudo
As the Administrative User, you can use the sudo command to do the following:
-
adduser
-
vadduser
-
pw
-
rmuser
-
quota
-
edquota
-
vlistuser
-
vedituser
-
restart_apache
See the sudo man
page for more information.
The following example shows the Administrative User using
the vedituser command:
# sudo vedituser
You can access a list of commands by typing sudo –l. The Administrative User by default,
does not need a password to use the sudo
command.
Remember, only the root user can edit the /usr/local/etc/sudoers file.
As the root user, you can become another user in two ways,
as shown in the following examples:
# su joe
switches to user, Joe, but retains the shell settings of
the previous user, root.
# su – joe
resets the shell settings to those of user, Joe. The pwd command displays Joe’s home directory.
gluttony /root> su - joe
gluttony ~> whoami
joe
gluttony ~> pwd
/home/joe
If ever you have an “identity crisis” from changing users
too many times, type whoami.
|