Install OCI-cli and configure a default profile

Carlos Giraldo
3 min readAug 24, 2022

--

OCI-cli, is a tool to access and manage all Oracle cloud resources from the command line.

To configure the OCI-cli it’s necessary to authenticate against your tenant. There are several ways to do that, but I’m going to show you what I think is the best one.

First, we are going to install OCI-cli, depending on your OS, you’ll have to follow different instructions.

# MAC
brew install oci-cli
# Linux
bash -c “$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"
# There are more detailed options in the link for other OS

You can verify that everything is ok by executing.

oci --version

The next step is to create an API key for your user.

Open the OCI console and click on the profile button at the top right of the screen, click on top of your user ID.

In the user profile information go down to the user options and select “API Keys”, and click on the option “Add API Key”

A popup will appear. Download the private and the public key and click on the “Add” button.

A window will appear with the details of the profile, copy the contents of the text box and click on close.

The last part is to include the content of the previous step into a config file inside your user folder.

# Create a hidden directory (if does'not exists)
mkdir ~/.oci
# Create a config file inside the directory
touch ~/.oci/config
# Change the name of your ssh keys and move them to the .oci dir
mv ssh-key-2022-08-16.key ~/.oci/ssh-key.key
mv ssh-key-2022-08-16.key.pub ~/.oci/ssh-key.key.pub
# Open the config file and paste the content you copy from last step
vi ~/.oci/config
# Modify the last field of the config file using the absolute path of the private key

In the end, your file should be looking something like this.

Test that everything is working.

# List of regions of Oracle cloud
oci iam region list

To check all the options on the OCI-cli check the next link.

One interesting functionality of OCI-cli is to use the interactive mode. In interactive mode, the tool helps you autocomplete the commands, so you don't need to remember much.

# Entering interactive mode
oci -i

It does several interesting things.

  • Auto complete the commands and options
  • Mark on red mandatory parameters
  • Autocomplete the resources OCID showing the user-friendly name.

All this configuration only need to be done once, and is not only helpful for the OCI-cli, but also for SDKs of python or java.

Thanks!

--

--