Module 127 su

Previous Table of Contents Next


Module 127
su

DESCRIPTION

The external su command lets you become another user without logging off the system. The password of the new user name must be supplied unless you are super-user. Super-user can su to any user name without knowing the user s password. You can use su to log in as a new user with a new user ID and environment or to just take on a new user ID.

COMMAND FORMAT

Following is the general format of the su command.

 su [ -] [ user_name [ -c cmdstring  -r cmdstring ] 

BSD (Berkeley)
su [ -f] [ -] [ user_name ]

Options

The following list describes the options that may be used to control how su functions.

- Informs su to use the new user_name s environment as if you had logged in as that user. The default is to pass your current environment with the possible exception of $PATH. The - specifies that arg0 should have a hyphen placed in front of it. This tells the login shell that you are initially logging in to the system. The login shell will check arg0 for a hyphen and, if found, execute /etc/profile and the new user_name s .profile.

C Shell
The C shell reads the .login and . cshrc shell when the shell is a login session.

-c Su passes the string that follows the -c as a command line to the new user_name s shell. Refer to cmdstring in the argument section.
-r Same as -c except a restricted shell is executed.

BSD (Berkeley)
-f Causes the csh to skip the execution of the .cshrc file. This allows for a faster login but does not set up all environment variables residing in the .cshrc file.
- Forces a simulated full login.

Arguments

The following list describes the arguments that may be passed to the su command.

user_name A valid user name (login name).
cmdstring A shell command that will be passed to the new environment and executed by the new user_name shell.

BSD (Berkeley)
If no user_name is specified, root is assumed. A number sign is substituted in place of the normal super-user prompt.

FURTHER DISCUSSION

su executes a new shell or program defined in the shell field (field 7) of the /etc/passwd file of the specified user. The real and effective user ID and group ID will be set according to the new user. To exit the new environment press Ctrl-D or type exit . You will return to your previous shell.

Each attempt to su to a different user_name is logged in the su log file, /usr/adm/sulog.


BSD (Berkeley)
Without any options su starts a new shell as specified in the shell field of the /etc/passwd file without changing your current directory. Your environment does not change except for HOME and SHELL, which are reset to the values found in the /etc/passwd file.

RELATED COMMANDS

Refer to env , login , passwd , and ksh described in modules 41, 77, 99, and 72, respectively.

RELATED FILES

The following files are read or updated by the su command.

/etc/motd Message of the day file, displayed during login.
/etc/passwd System password file.
/etc/profile System profile, read by login shell to set up environment.
$HOME/.profile New user s profile, read by login shell to set up environment.
/var/adm/sulog Log file for each attempt to su to a different user name.
$HOME/.cshrc Read at beginning of execution by each shell.
$HOME/.login Read by your login shell to set up environment.

APPLICATIONS

The su command is used to change to a new environment without losing your current shell environment. By using su you can become a different user while leaving your current environment alone. When you finish in the new environment you simply return to your previous shell environment.

Sometimes confusion arises about when to use su and when to use login . The login command exec s a new shell, completely replacing the current environment and shell. The su command spawns a new shell, overlaying the current environment. If you use su , you can return to the previous environment. If you use login , you cannot return to the previous environment because it no longer exists.

Single shell commands can be passed to a different user s environment and executed with that user s user ID, group ID, and environment.


Previous Table of Contents Next

Copyright Wordware Publishing, Inc.


Illustrated UNIX System V
Illustrated Unix System V/Bsd
ISBN: 1556221878
EAN: 2147483647
Year: N/A
Pages: 144
Authors: Robert Felps

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