Introduction
In cloud environments, automation and scripting are essential for efficient resource management. While the OCI Console provides a graphical interface, the OCI CLI enables engineers to interact with resources programmatically.
This guide demonstrates how to configure OCI CLI and extract tenancy-level data using real commands
Why OCI CLI
✔ Automation (scripts, pipelines)
✔ Bulk operations
✔ Faster troubleshooting
✔ Integration with DevOps workflows
Architecture
Local Machine
│
▼
OCI CLI
│
▼
API Request (Signed with Key)
│
▼
OCI Services (IAM, Compute, etc.)
Step 1: Install OCI CLI
bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"
oci --version
Step 2: Generate API Keys
-> Create a directory .oci
mkidr .oci
-> Create a configuration file for the oci cli
mkdir config
-> Add the config details like below
[DEFAULT]
user=ocid1.user.oc1..aaaaaaaapjmafzjfgvdf7rohfvuwlwj6otxwxfqtazd6vvcwe24pfailx4cq
fingerprint=5e:b0:45:e2:07:3f:b8:fa:51:25:ee:4b:7b:d5:d6:e9
tenancy=ocid1.tenancy.oc1..aaaaaaaaf2yv5cljkqlepfllkxolhgvmq5tq7vgfu6tns3ajhnuqn4eikmja
region=ap-mumbai-1
key_file=
-> Create one file and add your private key details and change the permissions to read and write only.
chmod 600 ~/.oci/oci_api_key.pem
-> Now check with below command for the configuration setup
oci os ns get
Validate Configuration
oci iam region list
oci iam compartment list --compartment-id
You will get the list of compartments over the entire tenancy level
Get Instances
oci compute instance list --compartment-id
Real Use Case
oci iam user list --compartment-id \
--query "data[].{Name:name,ID:id}" --output table
You will get the user details in a table format
Best Practices
✔ Secure private keys
✔ Use profiles
✔ Avoid hardcoding OCIDs
✔ Use scripts for automation
✔ Rotate keys regularly
Conclusion
OCI CLI enables engineers to automate cloud operations and retrieve critical data efficiently. By combining CLI commands with scripting, organizations can improve operational efficiency and reduce manual effort.








Top comments (0)