xref: /openbsd/usr.bin/su/su.1 (revision 8932bfb7)
1.\"	$OpenBSD: su.1,v 1.28 2010/12/10 19:32:21 millert Exp $
2.\"
3.\" Copyright (c) 1988, 1990 The Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"	from: @(#)su.1	6.12 (Berkeley) 7/29/91
31.\"
32.Dd $Mdocdate: December 10 2010 $
33.Dt SU 1
34.Os
35.Sh NAME
36.Nm su
37.Nd substitute user identity
38.Sh SYNOPSIS
39.Nm su
40.Bk -words
41.Op Fl fKLlm
42.Op Fl a Ar auth-type
43.Op Fl c Ar login-class
44.Op Fl s Ar login-shell
45.Op Ar login Op Ar "shell arguments"
46.Ek
47.Sh DESCRIPTION
48The
49.Nm
50utility allows a user to run a shell with the user and group ID of another user
51without having to log out and in as that other user.
52.Pp
53If Kerberos is in use, the password for
54.Ar login
55(or for
56.Dq Ar login Ns /root ,
57if no login is provided) is requested, and
58.Nm
59switches to
60that user and group ID after obtaining a Kerberos ticket granting access.
61A shell is then executed, and any additional
62.Ar "shell arguments"
63after the login name
64are passed to the shell.
65If Kerberos is not configured or if there is a Kerberos error,
66.Nm
67falls back to local password authentication to validate the password for
68.Ar login .
69If
70.Nm
71is executed by root, no password is requested and a shell
72with the appropriate user ID is executed; no additional Kerberos tickets
73are obtained.
74.Pp
75By default, the environment is unmodified with the exception of
76.Ev LOGNAME ,
77.Ev HOME ,
78.Ev SHELL ,
79and
80.Ev USER .
81.Ev HOME
82and
83.Ev SHELL
84are set to the target login's default values.
85.Ev LOGNAME
86and
87.Ev USER
88are set to the target login, unless the target login has a user ID of 0
89and the
90.Fl l
91flag was not specified,
92in which case it is unmodified.
93The invoked shell is the target login's.
94This is the traditional behavior of
95.Nm su .
96.Pp
97If not using
98.Fl m
99and the target login has a user ID of 0 then the
100.Ev PATH
101variable and umask value
102(see
103.Xr umask 2 )
104are always set according to the
105.Pa /etc/login.conf
106file (see
107.Xr login.conf 5 ) .
108.Pp
109The options are as follows:
110.Bl -tag -width Ds
111.It Fl
112Same as the
113.Fl l
114option (deprecated).
115.It Fl a Ar auth-type
116Specify an authentication type such as
117.Dq skey ,
118.Dq securid ,
119or
120.Dq krb5 .
121.It Fl c Ar login-class
122Specify a login class.
123You may only override the default class if you're already root.
124.It Fl f
125If the invoked shell is
126.Xr csh 1 ,
127this option prevents it from reading the
128.Dq Pa .cshrc
129file.
130.It Fl K
131Do not attempt to use Kerberos to authenticate the user.
132This is shorthand for
133.Dq Nm Fl a Ar passwd ,
134provided for backwards compatibility.
135.It Fl L
136Loop until a correct username and password combination is entered,
137similar to
138.Xr login 1 .
139Note that in this mode target
140.Ar login
141must be specified explicitly, either on the command line or interactively.
142Additionally,
143.Nm
144will prompt for the password even when invoked by root.
145.It Fl l
146Simulate a full login.
147The environment is discarded except for
148.Ev HOME ,
149.Ev SHELL ,
150.Ev PATH ,
151.Ev TERM ,
152.Ev LOGNAME ,
153and
154.Ev USER .
155.Ev HOME
156and
157.Ev SHELL
158are modified as above.
159.Ev LOGNAME
160and
161.Ev USER
162are set to the target login.
163.Ev PATH
164is set to the value specified by the
165.Dq path
166entry in
167.Xr login.conf 5 .
168.Ev TERM
169is imported from your current environment.
170The invoked shell is the target login's, and
171.Nm
172will change directory to the target login's home directory.
173.It Fl m
174Leave the environment unmodified.
175The invoked shell is your login shell, and no directory changes are made.
176As a security precaution, if the target user's shell is a non-standard
177shell (as defined by
178.Xr getusershell 3 )
179and the caller's real UID is
180non-zero,
181.Nm
182will fail.
183.It Fl s Ar login-shell
184Specify the path to an alternate login shell.
185You may only override the shell if you're already root.
186This option will override the shell even if the
187.Fl m
188option is specified.
189.El
190.Pp
191The
192.Fl l
193and
194.Fl m
195options are mutually exclusive; the last one specified
196overrides any previous ones.
197.Pp
198If the optional
199.Ar "shell arguments"
200are provided on the command line, they are passed to the login shell of
201the target login.
202This allows it to pass arbitrary commands via the
203.Fl c
204option as understood by most shells.
205Note that
206.Fl c
207usually expects a single argument only; you have to quote it when
208passing multiple words.
209.Pp
210If group 0 (normally
211.Dq wheel )
212has users listed then only those users can
213.Nm
214to
215.Dq root .
216It is not sufficient to change a user's
217.Pa /etc/passwd
218entry to add them to the
219.Dq wheel
220group; they must explicitly be listed in
221.Pa /etc/group .
222If no one is in the
223.Dq wheel
224group, it is ignored, and anyone who knows the root password is permitted to
225.Nm
226to
227.Dq root .
228.Pp
229By default (unless the prompt is reset by a startup file) the superuser
230prompt is set to
231.Dq Sy \&#
232to remind one of its awesome power.
233.Sh ENVIRONMENT
234.Bl -tag -width LOGNAME
235.It Ev HOME
236Default home directory of real user ID unless modified as
237specified above.
238.It Ev LOGNAME
239The user ID is always the effective ID (the target user ID) after an
240.Nm
241unless the user ID is 0 (root).
242.It Ev PATH
243Default search path of real user ID unless modified as specified above.
244.It Ev TERM
245Provides terminal type which may be retained for the substituted
246user ID.
247.It Ev USER
248Same as
249.Ev LOGNAME .
250.El
251.Sh EXAMPLES
252Run the command
253.Dq makewhatis
254as user
255.Dq bin .
256You will be asked for bin's password unless your real UID is 0.
257.Pp
258.Dl $ su bin -c makewhatis
259.Pp
260Same as above, but the target command consists of more than a
261single word:
262.Pp
263.Dl $ su bin -c 'makewhatis /usr/local/man'
264.Pp
265Same as above, but the target command is run with the resource
266limits of the login class
267.Dq staff .
268Note that the first
269.Fl c
270option applies to
271.Nm
272while the second is an argument to the shell.
273.Pp
274.Dl $ su -c staff bin -c 'makewhatis /usr/local/man'
275.Pp
276Pretend a login for user
277.Dq foo :
278.Pp
279.Dl $ su -l foo
280.Pp
281Same as above, but use S/Key for authentication:
282.Pp
283.Dl $ su -a skey -l foo
284.Sh SEE ALSO
285.Xr csh 1 ,
286.Xr kinit 1 ,
287.Xr login 1 ,
288.Xr sh 1 ,
289.Xr skey 1 ,
290.Xr setusercontext 3 ,
291.Xr group 5 ,
292.Xr login.conf 5 ,
293.Xr passwd 5 ,
294.Xr environ 7 ,
295.Xr sudo 8
296.Sh HISTORY
297A
298.Nm
299command appeared in
300.At v7 .
301.Sh BUGS
302The login name is not optional for root if there are shell arguments.
303