// Module included in the following assemblies:
//
// * cli_reference/openshift_cli/configuring-cli.adoc

:_mod-docs-content-type: PROCEDURE
[id="cli-accessing-kubeconfig-using-cli_{context}"]
= Accessing kubeconfig by using the oc CLI

[role="_abstract"]
You can use the `oc` CLI to log in to your OpenShift cluster and retrieve a kubeconfig file for accessing the cluster from the command line.

[IMPORTANT]
====
If you plan to reuse the exported `kubeconfig` file across sessions or machines, store it securely and avoid committing it to source control.
====

.Prerequisites

* You have access to the {product-title} web console or API server endpoint.

.Procedure

. Log in to your OpenShift cluster by running the following command:
+
[source,terminal]
----
$ oc login <api_server_url> -u <username> -p <password>
----
+
where:

`<api_server_url>`:: Specifies the full API server URL; for example, `https://api.my-cluster.example.com:6443`.
`<username>`:: Specifies a valid username; for example, `kubeadmin`.
`<password>`:: Specifies the password for the specified user; for example, the `kubeadmin` password generated during cluster installation.

. Save the cluster configuration to a local file by running the following command:
+
[source,terminal]
----
$ oc config view --raw > kubeconfig
----

. Set the `KUBECONFIG` environment variable to point to the exported file by running the following command:
+
[source,terminal]
----
$ export KUBECONFIG=./kubeconfig
----

. Use `oc` to interact with your OpenShift cluster by running the following command:
+
[source,terminal]
----
$ oc get nodes
----
