Section 4.11. Substituting a User: su


[Page 139 (continued)]

4.11. Substituting a User: su

A lot of people think that su stands for "super-user," but it doesn't. Instead, it stands for "substitute user," and allows you to create a subshell owned by another user (Figure 4-23).


[Page 140]

Figure 4-23. Description of the su command.

Utility: su [-] [ userName ] [ args ]

su creates a temporary shell with userName's real and effective user/group IDs. If userName is not specified, "root" is assumed and the new shell's prompt is set to a # as a reminder. While you're in the subshell, you are effectively logged on as that user; when you terminate the shell with a Control-D, you are returned to your original shell. Of course, you must know the other user's password to use this utility. The SHELL and HOME environment variables are set from userName's entry in the password file. If userName is not "root," the USER environment variable is also set. The new shell does not go through its login sequence unless the - option is supplied. All other arguments are passed as command-line arguments to the new shell.


Here's an example of su:

$ whoami         ...find out my current username. glass $ su             ...substitute user. Password: <enter super-user password here> $ whoami       ...confirm my current username has changed. root $ ... perform super-user tasks here $ ^D              ...terminate the child shell. $ whoami          ...confirm current username is restored. glass $ _ 


The su command is probably most often used to become the super-user. If you will act as the system administrator or have a need to become the super-user on a regular basis, you should also see the description of the sudo command on page 577.




Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net