DEV Community

Faris Durrani
Faris Durrani

Posted on • Edited on

Setting up the OCI Configuration File using API Keys

To manage resources on the Oracle Cloud Infrastructure (OCI) remotely--e.g., using Terraform or the OCI Command Line Interface (CLI) tool--you first need to have an OCI CLI configuration file that contains the credentials (profile) of the user account that you will be using to create and deploy functions. This guide tells you how to do so using API key authentication.

Setting up OCI Configuration profile

1. Create the ~/.oci directory

Create a new directory ~/.oci where you will keep your OCI API credentials

2. Create an API Key

Create your API key on the Oracle Cloud console.

Go to your Profile picture > My Profile > API keys > Add API key

Screenshot - API keys on Profile page

Make sure to download the private key. The public key is optional to download.

The public key can be necessary if you want to use the same private key to access another resource but we'll leave it out here.

Add API key page

Click Add. This configuration file preview will show up.

Configuration file preview for OCI API key

3. Put API key into the config file

Copy the results and paste into your ~/.oci/config file. Create the file if it doesn't exist.

config file preview

where:

  • key_file here means the location of the private key you downloaded. I put my key inside the ~/.oci directory

Alternatively, this step can also be completed using oci setup config if you have the CLI tool already installed. For more info, see An introduction to OCI CLI

Bonus: Multiple profiles

If you have multiple tenancies (or multiple users in a same tenancy), you can have multiple profiles and use the one you need in every command.

For that, repeat the same steps above to create a new API key and add the copied configuration to your config file but with a different profile name other than [DEFAULT]:

Multiple profiles in OCI CLI

Note: notice how the two fingerprints and key_file values are the same? That's because I pasted in the public key used to generate the first API key. So now, these two profiles use the same private key. This is optional, of course.

Verify

This guide isn't extensive enough to cover tools that uses the API, but you may view my two articles here that uses this configuration step:

  1. An introduction to OCI CLI
  2. Using Terraform to Deploy an OCI Compute Instance

Safe harbor statement
The information provided on this channel/article/story is solely intended for informational purposes and cannot be used as a part of any contractual agreement. The content does not guarantee the delivery of any material, code, or functionality, and should not be the sole basis for making purchasing decisions. The postings on this site are my own and do not necessarily reflect the views or work of Oracle or Mythics, LLC.

This work is licensed under a Creative Commons Attribution 4.0 International License.

Top comments (0)