OpenShift - Display user name and token using the oc whoami command

by
Jeremy Canfield |
Updated: October 29 2022
| OpenShift articles
If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.
The following options can be used to display a users token.
- In the users /home/your_username/.kube/config file | using the oc config view command
- Using the whoami --show-token=true command (this article)
The oc whoami command without any options or flags will simply display your username, like this.
~]# oc whoami
john.doe
The -h or --help flag can be used to display the options or flags that can be used.
~]# oc whoami --help
Show information about the current session
The default options for this command will return the currently authenticated user name or an empty string. Other flags
support returning the currently used token or the user context.
Usage:
oc whoami [flags]
Options:
-c, --show-context=false: Print the current user context name
--show-server=false: If true, print the current server's REST API URL
-t, --show-token=false: Print the token the current session is using. This will return an error if you are using a
different form of authentication.
Use "oc options" for a list of global command-line options (applies to all commands).
The -t or --show-token=true option can be used to display the users token.
~]# oc whoami -t
k8QzC9ZVo9Up7Ov2jn2Qm1bexp77Zy_haKrLdp0t1FR
Did you find this article helpful?
If so, consider buying me a coffee over at