Command Line Interface (CLI) provides the same core functionality as the console, plus additional commands, like the ability to run scripts which extends the console functionality.
To install CLI, you must have
- OCI cloud account
- User in a group with the right permissions
- A key pair used for signing API requests- public key uploaded at Oracle cloud
To install the CLI on Mac OS with HomeBrew:
brew update && brew install oci-cli
To verify the OCI CLI installation
oci --version
To set up the configuration File- there are two ways to do it;
a) Use the set up config Dialog
oci setup config
this command prompts with the information required to create the configuration file and API keys. After the set up, you should upload the public api key on your the API keys section of your profile on OCI.
b) Manual set up
Log into your Oracle cloud, go to your profile, -> API keys & add an API key
Add an API Key in PEM format or generate an API key pair
Download the private key & save config file details – You will use them to set up the config file.
On your MAC OS, navigate to the .oci folder.
cd ~/.oci
if you don’t have the .oci folder, make the directory
mkdir ~/.oci
Paste the private key downloaded from OCI on this folder and edit the permissions to ensure that only you can read the private key file:
chmod go-rwx ~/.oci/<oci_api_key_name.pem
Create a config file and paste the config file details from OCI.
vi config
The config file content looks similar to this- add yours,
[DEFAULT]
user=ocid1.user.oc1..<unique_ID>
fingerprint=<your_fingerprint>
key_file=~/.oci/oci_api_key.pem
tenancy=ocid1.tenancy.oc1..<unique_ID>
region=uk-london-1
(To exit vi, press escape, :wq!)
All done! Test if the OCI CLI is correctly installed and working;
oci os ns get
You should be able to read, create, update, delete the OCI resources. The output from the above command should be the Tenancy name of your OCI cloud.
{
"data": "<tenancyname>"
}
To create an OCI object storage bucket using OCI CLI example
oci os bucket create --compartment-id <Compartment OCID> --name TestCLI

Add a file on Object Storage using the pipe command
echo "Hello World" | oci os object put --bucket-name my-bucket --name file.txt --file -
Delete Objects in a bucket (Use –dry-run at the end if you want to first preview)
oci os object bulk-delete --namespace-name <object_storage_namespace> --bucket-name <bucket_name>
Other useful cmds;
To upgrade your CLI install on Mac OS using Homebrew:
brew update && brew upgrade oci-cli
To uninstall the CLI on Mac OS using Homebrew:
brew uninstall oci-cli
Creating OCI CLI profile
oci setup config --profile myprofile
To use the profile, specify the name on the –profile section
oci os ns get --profile myprofile
To generate new public and private keys on the .oci folder
openssl rsa -pubout -in ~/.oci/oci_api_key.pem -out ~/.oci/oci_api_key_public.pem
References