KSU(1)
π ksu β the Kerberized super-user π
okay so bestie, welcome to KSU(1) β the MIT Kerberos manual page for ksu, and she is a whole baddie. sit down, grab a strawberry π, we're doing this properly.
β¨ NAME β¨
ksu β Kerberized super-user π
πΈ SYNOPSIS πΈ
ksu [ target_user ] [ -n target_principal_name ] [ -c source_cache_name
] [ -k ] [ -r time ] [ -p | -P] [ -f | -F] [ -l lifetime ] [ -z | Z ] [
-q ] [ -e command [ args ... ] ] [ -a [ args ... ] ]
π REQUIREMENTS π
- you need Kerberos version 5 installed to even compile
ksu. no Kerberos 5, no build. periodt. - and to actually use it, you need a Kerberos version 5 server running. both. it's giving "two-step verification but make it infrastructure" π«Ά
π¦ DESCRIPTION π¦
ksu is a Kerberized version of the su program, and she has two missions:
- securely change the real and effective user ID to that of the target user
- create a new security context β¨
NOTE: for the sake of clarity, all references to and attributes of the user invoking the program start with "source" (e.g., "source user", "source cache", etc.). likewise, all references to and attributes of the target account start with "target". source user vs target user, source cache vs target cache β that's the whole vocabulary, bestie, and we stay consistent. iykyk π
π₯ AUTHENTICATION π₯
to fulfill that first mission, ksu operates in two phases: authentication and authorization. and the very first step of authentication is resolving the target principal name.
so how do we get that name? you've got two routes:
- you can specify your principal name yourself with the
-noption (e.g.,-n jqpublic@USC.EDU) - or a default principal name gets assigned using a heuristic described in the OPTIONS section (see the
-noption)
also, the target user name must be the first argument to ksu. if you don't specify it, root is the default. and if you specify . then the target user will be the source user (e.g., ksu .). π―
now the easy mode: if the source user is root, or the target user is the source user, then no authentication or authorization takes place. slay, no ticket required. otherwise, ksu looks for an appropriate Kerberos ticket in the source cache.
that ticket can be either for the end-server, or a ticket granting ticket (TGT) for the target principal's realm. here's the whole flow, step by step:
- if the ticket for the end-server is already in the cache, it's decrypted and verified β
- if it's not in the cache but the TGT is, the TGT is used to obtain the ticket for the end-server. the end-server ticket is then verified.
- if neither ticket is in the cache, but
ksuis compiled with theGET_TGT_VIA_PASSWDdefine, the user will be prompted for a Kerberos password, which will then be used to get a TGT. β οΈ and if the user is logged in remotely and does not have a secure channel, the password may be exposed. be careful out there bestie π - if neither ticket is in the cache and
GET_TGT_VIA_PASSWDis not defined, authentication fails. π
π AUTHORIZATION π
this section is about authorization of the source user when ksu is invoked without the -e option. (for a description of the -e option, go see the OPTIONS section β we get there, don't rush me.)
upon successful authentication, ksu checks whether the target principal is authorized to access the target account. in the target user's home directory, ksu attempts to access two authorization files:
.k5login.k5users
in the .k5login file, each line contains the name of a principal that is authorized to access the account. for example:
jqpublic@USC.EDU
jqpublic/secure@USC.EDU
jqpublic/admin@USC.EDU
the format of .k5users is the same, except the principal name may be followed by a list of commands that the principal is authorized to execute (see the -e option in the OPTIONS section for details).
so, the actual vibe check:
- if the target principal name is found in the
.k5loginfile, the source user is authorized to access the target account β - otherwise
ksulooks in the.k5usersfile. if the target principal name is found there without any trailing commands, or followed only by*, then the source user is authorized β - if either
.k5loginor.k5usersexists but an appropriate entry for the target principal does not exist, then access is denied π - if neither file exists, then the principal will be granted access to the account according to the
aname->lnamemapping rules - otherwise, authorization fails π
π EXECUTION OF THE TARGET SHELL π
upon successful authentication and authorization β both, bestie, no shortcuts β ksu proceeds in a similar fashion to su. the environment is unmodified, with the exception of the USER, HOME and SHELL variables:
- if the target user is not
root,USERgets set to the target user name. otherwiseUSERremains unchanged. - both
HOMEandSHELLare set to the target login's default values. - in addition, the environment variable
KRB5CCNAMEgets set to the name of the target cache.
the real and effective user ID are changed to that of the target user. the target user's shell is then invoked (the shell name is specified in the password file). upon termination of the shell, ksu deletes the target cache β unless ksu is invoked with the -k option.
and here's the fun implementation detail: this is implemented by first doing aforkand then anexec, instead of justexec, as done bysu. yes, an extra step, on purpose, and honestly? iconic of her. β¨
π CREATING A NEW SECURITY CONTEXT π
ksu can be used to create a new security context for the target program (either the target shell, or a command specified via the -e option). the target program inherits a set of credentials from the source user. by default, that set includes:
- all of the credentials in the source cache
- plus any additional credentials obtained during authentication
the source user is able to limit the credentials in this set by using the -z or -Z option:
-zrestricts the copy of tickets from the source cache to the target cache to only the tickets whereclient ==the target principal name.-Zprovides the target user with a fresh target cache (no creds in the cache).
heads up, this one matters: for security reasons, when the source user isrootand the target user is non-root,-zis the default mode of operation. π«£
while no authentication takes place if the source user is root or is the same as the target user, additional tickets can still be obtained for the target cache. if -n is specified and no credentials can be copied to the target cache, the source user is prompted for a Kerberos password (unless -Z is specified or GET_TGT_VIA_PASSWD is undefined).
if that works, a TGT is obtained from the Kerberos server and stored in the target cache. otherwise, if a password is not provided (user hit return), ksu continues in a normal mode of operation (the target cache will not contain the desired TGT). and if the wrong password is typed in, ksu fails. π
NOTE: during authentication, only the tickets that could be obtained without providing a password are cached in the source cache.
and bestieβ¦ that's not the whole story, we're so not done here π
β¨ OPTIONS β¨
-ntarget_principal_name β bestie, this is where you name the Kerberos target principal. It gets used in the authentication and authorization phases ofksu.
If you run ksu without -n, a default principal name gets assigned by the following heuristic, and it is a whole journey:
- Case 1: source user is non-root.
If the target user is the source user, the default principal name is set to the default principal of the source cache. If the cache does not exist then the default principal name is set to target_user@local_realm. If the source and target users are different and neither ~target_user/.k5users nor ~target_user/.k5login exist then the default principal name is target_user_login_name@local_realm. Otherwise, starting with the first principal listed below, ksu checks if the principal is authorized to access the target account and whether there is a legitimate ticket for that principal in the source cache. If both conditions are met that principal becomes the default target principal, otherwise go to the next principal.
a. default principal of the source cache
b. target_user@local_realm
c. source_user@local_realm
If a-c fails, try any principal for which there is a ticket in the source cache and that is authorized to access the target account. If that fails, select the first principal that is authorized to access the target account from the above list. If none are authorized and ksu is configured with PRINC_LOOK_AHEAD turned on, select the default principal as follows:
For each candidate in the above list, select an authorized principal that has the same realm name and first part of the principal name equal to the prefix of the candidate. For example if candidate a) is jqpublic@ISI.EDU and jqpublic/secure@ISI.EDU is authorized to access the target account then the default principal is set to jqpublic/secure@ISI.EDU.
- Case 2: source user is root.
If the target user is non-root then the default principal name is target_user@local_realm. Else, if the source cache exists the default principal name is set to the default principal of the source cache. If the source cache does not exist, default principal name is set to root@local_realm.
-csource_cache_name β specify the source cache name (like, e.g.,-c FILE:/tmp/my_cache). If the-coption is not used then the name is obtained from theKRB5CCNAMEenvironment variable. IfKRB5CCNAMEis not defined the source cache name is set tokrb5cc_<source uid>. The target cache name is automatically set tokrb5cc_<target uid>.(gen_sym()), wheregen_symgenerates a new number such that the resulting cache does not already exist. For example:
krb5cc_1984.2
-kβ do not delete the target cache upon termination of the target shell or a command (-e command). Without-k,ksudeletes the target cache. So if you want the cache to survive, say the word. π«Ά-zβ restrict the copy of tickets from the source cache to the target cache to only the tickets where client == the target principal name. Use the-noption if you want the tickets for other then the default principal. Heads up: the-zoption is mutually exclusive with the-Zoption. π«-Zβ don't copy any tickets from the source cache to the target cache. Just create a fresh target cache, where the default principal name of the cache is initialized to the target principal name. And also heads up: the-Zoption is mutually exclusive with the-zoption. π«-qβ suppress the printing of status messages. Silence, but make it fashion. π€«
ποΈ Ticket granting ticket options ποΈ
-l lifetime -r time -p -P -f -Fβ okay so these ticket granting ticket options only apply to the case where there are no appropriate tickets in the cache to authenticate the source user. In this case, ifksuis configured to prompt users for a Kerberos password (GET_TGT_VIA_PASSWDis defined), the ticket granting ticket options that are specified will be used when getting a ticket granting ticket from the Kerberos server.-llifetime β (Time duration string.) Specifies the lifetime to be requested for the ticket; if this option is not specified, the default ticket lifetime (12 hours) is used instead.-rtime β (Time duration string.) Specifies that the renewable option should be requested for the ticket, and specifies the desired total lifetime of the ticket.-pβ specifies that the proxiable option should be requested for the ticket.-Pβ specifies that the proxiable option should not be requested for the ticket, even if the default configuration is to ask for proxiable tickets.-fβ option specifies that the forwardable option should be requested for the ticket.-Fβ option specifies that the forwardable option should not be requested for the ticket, even if the default configuration is to ask for forwardable tickets.-ecommand [args ...] βksuproceeds exactly the same as if it was invoked without the-eoption, except instead of executing the target shell,ksuexecutes the specified command. Example of usage:
ksu bob -e ls -lag
The authorization algorithm for -e is as follows:
If the source user is root or source user == target user, no authorization takes place and the command is executed. If source user id != 0, and ~target_user/.k5users file does not exist, authorization fails. Otherwise, ~target_user/.k5users file must have an appropriate entry for target principal to get authorized.
The .k5users file format:
A single principal entry on each line that may be followed by a list of commands that the principal is authorized to execute. A principal name followed by a * means that the user is authorized to execute any command. Thus, in the following example:
jqpublic@USC.EDU ls mail /local/kerberos/klist
jqpublic/secure@USC.EDU *
jqpublic/admin@USC.EDU
jqpublic@USC.EDU is only authorized to execute ls, mail and klist commands. jqpublic/secure@USC.EDU is authorized to execute any command. jqpublic/admin@USC.EDU is not authorized to execute any command. Note, that jqpublic/admin@USC.EDU is authorized to execute the target shell (regular ksu, without the -e option) but jqpublic@USC.EDU is not.
The commands listed after the principal name must be either a full path names or just the program name. In the second case, CMD_PATH specifying the location of authorized programs must be defined at the compilation time of ksu. Which command gets executed?
If the source user is root or the target user is the source user or the user is authorized to execute any command (* entry) then command can be either a full or a relative path leading to the target program. Otherwise, the user must specify either a full path or just the program name.
-aargs β specify arguments to be passed to the target shell. Note that all flags and parameters following-awill be passed to the shell, thus all options intended forksumust precede-a. This is the "everything after this point belongs to the shell, not me" energy. π
The -a option can be used to simulate the -e option if used as follows:
-a -c [command [arguments]].
-c is interpreted by the c-shell to execute the command.
π οΈ INSTALLATION INSTRUCTIONS π οΈ
ksu can be compiled with the following four flags:
GET_TGT_VIA_PASSWDβ in case no appropriate tickets are found in the source cache, the user will be prompted for a Kerberos password. The password is then used to get a ticket granting ticket from the Kerberos server.
The danger of configuring ksu with this macro is if the source user is logged in remotely and does not have a secure channel, the password may get exposed. π Not the password getting exposed, bestie, please be careful.
PRINC_LOOK_AHEADβ during the resolution of the default principal name,PRINC_LOOK_AHEADenablesksuto find principal names in the.k5usersfile as described in the OPTIONS section (see-noption).CMD_PATHβ specifies a list of directories containing programs that users are authorized to execute (via.k5usersfile).HAVE_GETUSERSHELLβ if the source user is non-root,ksuinsists that the target user's shell to be invoked is a "legal shell".getusershell(3)is called to obtain the names of "legal shells". Note that the target user's shell is obtained from the passwd file.
Sample configuration:
KSU_OPTS = -DGET_TGT_VIA_PASSWD -DPRINC_LOOK_AHEAD -DCMD_PATH='"/bin /usr/ucb /local/bin"
ksu should be owned by root and have the set user id bit turned on. π
ksu attempts to get a ticket for the end server just as Kerberized telnet and rlogin. Thus, there must be an entry for the server in the Kerberos database (e.g., host/nii.isi.edu@ISI.EDU). The keytab file must be in an appropriate location.
π« SIDE EFFECTS π«
ksu deletes all expired tickets from the source cache. It's just tidying up, no cap. π§Ή
π AUTHOR OF KSU π
GENNADY (ARI) MEDVINSKY
π ENVIRONMENT π
See kerberos for a description of Kerberos environment variables.
π¦ SEE ALSO π¦
kerberos, kinit
π AUTHOR π
MIT
π COPYRIGHT π
1985-2026, MIT
and that's the whole page, bestie β version 1.22.2 of KSU(1), dated 1.22.2. go forth and be authorized, iykyk πβ¨π¦
π¦ where this page comes from
- alpine 3.24: krb5-doc 1.22.2-r1 Β· MIT
- arch rolling: krb5 1.22.2-1 Β· custom
- fedora 43: krb5-workstation 1.22.2-4.fc43 Β· Brian-Gladman-2-Clause AND BSD-2-Clause AND (BSD-2-Clause OR GPL-2.0-or-later) AND BSD-2-Clause-first-lines AND BSD-3-Clause AND BSD-4-Clause AND CMU-Mach-nodoc AND FSFULLRWD AND HPND AND HPND-export2-US AND HPND-export-US AND HPND-export-US-acknowledgement AND HPND-export-US-modify AND ISC AND MIT AND MIT-CMU AND OLDAP-2.8 AND OpenVision
- freebsd 15.1: base 15.1
- nixos 26.05: krb5 1.22.2
- nixpkgs unstable: krb5 1.22.2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms