Skip to content
Commitpedia
Log in Join & edit

Logging in with oc and working with OpenShift projects

Install the oc client, log in with a password, browser or token, then create, switch and inspect projects. Covers where oc stores its login and how to tell who and where you are.

Not checked by a trusted editor yet Last edited Outdated?

Edit history of Logging in with oc and working with OpenShift projects: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
2 min

oc is the OpenShift command line client. It includes everything kubectl does plus OpenShift-specific commands. You can download a build that matches your cluster from the web console’s command line tools page or, on macOS, install it with Homebrew.

brew install openshift-cli
oc version

Log in

There are three common ways to log in. The API server usually listens on port 6443.

  1. User name and password: run oc login -u USER and answer the prompts for the server URL and password.
  2. Browser: oc login SERVER --web opens the cluster’s login page, which is handy with single sign-on. It runs a small HTTP server on localhost, so be careful on shared machines.
  3. Token: in the web console, open your user name menu and choose Copy login command. It gives you a ready-made oc login command that includes a token.
oc login -u developer https://api.cluster.example.com:6443

oc login https://api.cluster.example.com:6443 --web

oc login https://api.cluster.example.com:6443 --token=CHANGE_ME

If the cluster uses a certificate your machine does not trust, oc asks whether to use an insecure connection. In a lab that is acceptable; on real clusters, get the CA certificate and pass it with --certificate-authority instead.

After the first login, oc writes the server, user and token to ~/.kube/config, or to the file named in the KUBECONFIG environment variable. Treat this file like a password.

Check who and where you are

oc whoami                 # current user
oc project                # current project and server
oc config get-contexts    # saved logins
oc logout                 # end the session and drop the token

Work with projects

A project is a Kubernetes namespace with extra annotations, and it is the unit of access control: users get roles such as admin, edit or view per project. Whether ordinary users may create their own projects depends on the cluster’s configuration.

oc new-project shop-dev --display-name="Shop (dev)" --description="Development project"

oc projects               # list projects you can see
oc project shop-dev       # switch to a project
oc get pods -n shop-prod  # run one command in another project
oc status                 # overview of the current project

Every command uses the current project unless you add -n PROJECT. Most surprises such as “my pod disappeared” come from being in the wrong project, so check oc project first.

Give a teammate access

Project admins can add other users to their project.

oc adm policy add-role-to-user edit alice -n shop-dev
oc adm policy add-role-to-user view bob -n shop-dev
oc get rolebindings -n shop-dev

Delete a project

Warning: deleting a project deletes everything in it, including persistent volume claims and their data when the storage class reclaims volumes on delete. Check what is inside first with oc get all,pvc -n PROJECT and make sure you are pointing at the right cluster and project with oc project, which prints both.

oc get all,pvc -n shop-dev
oc delete project shop-dev

Official documentation

See also

Repos in the wild

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. Commitpedia +3,160 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?