Becoming Another User

Becoming Another User

As we mentioned above, on most Unix systems, a system administrator uses the root account by invoking the su command to substitute the root account's identity for his or her own.

If you have enabled the root account on Mac OS X, then users may use the su command to assume the root account's identity.

The su command allows you to temporarily assume the identity of another user on the system. Therefore, users can log in to the system as themselves , " su to root," perform whatever tasks need to be done as root, and then exit from the su session and reassume their own identities.

You can also use the su command to switch to users other than root, which is useful if you want to test a configuration for another user, or run a particular command as another user without bothering to actually log in as that user. Refer to Figure 11.2 through the following task.

Figure 11.2. Using su to assume the identity of another user.

To switch to another user:

su -l user name

The -l option (in some versions of su it's abbreviated as simply a hyphen: - ) tells su that the new shell should be a login shell. The current directory for the new shell is the home directory of the target user.

User name is the target user; that is, the user you want to switch to. If you omit user name , then the target user is root.

For example, to assume the identity of user puffball:

su -l puffball

To assume the identity of root:

su -l

You are then prompted for the user's password.

Enter the user's password.

su starts a new shell as the target user. If you used the -l option, then the new shell is a login shell that causes the target user's personal configuration files ( .bash_profile , and so on) to be read. (Review Chapter 7, "Configuring Your Environment with Unix.")

If you omitted the -l optionfor example,

su puffball



then only the environment variables USER , HOME , and SHELL are set to the values appropriate for the target user, unless the target user is root, in which case the USER variable is left unchanged. All other environment variables for the new shell are inherited from your environment.

Run commands as the target user.

Every command you run in the new shell is executed with the permission of the target user.

If you used su to become root with

su -l

then when you have finished performing tasks as the target user, exit the shell to go back to being yourself, at your own shell prompt:



  • Once you have a root shell, you can su to another user without having his or her password.

  • You can specify which shell you want su to start up for the target user by giving it as an additional argument. For example:

    su puffball /bin/sh

  • Once again, be aware of the power of root. From the su man page: "By default (unless the prompt is reset by a startup file) the super-user prompt is set to '#' to remind one of its awesome power."

Using the System in Single-User Mode

If you want to use the system in this state, you run the command lines

 /sbin/fsck -fy / /sbin/mount -uw / sh /etc/rc 

These will mount the system disk in read/write mode and run a series of scripts that eventually bring up the familiar Mac OS X graphical interface. However, at the time that this book was being written, this method would not work in Mac OS X 10.4.2. In fact, your machine would hang after the last command line in that sequence. We expect that Apple will soon solve the problem.

Note that Apple intends to phase out the use of the /etc/rc script. To learn more about the Mac OS X boot sequence, see the Mac OS X Developer Documentation at

Unix for Mac OS X 10. 4 Tiger. Visual QuickPro Guide
Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)
ISBN: 0321246683
EAN: 2147483647
Year: 2004
Pages: 161
Authors: Matisse Enzer

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: