Create A Config File For Oracle Date a Science

Nicholas Toscano
A Guide to Oracle Cloud AI
4 min readDec 2, 2023

--

If you are using cloud services from the Oracle Data Science notebook you need to have API signing keys and a config file. This is super easy to do!

This is well documented, but I will provide the delta for data science.

Step 1: Create .oci directory to store your config file in.

Open a new terminal in your notebook. Make sure you are in the /home/datascience directory. If you are not, then cd to it. List files in the directory to see if there is a .config folder already. If there is not create one.

See the commands below:

$ ls -a
$ mkdir ~/.oci

Your terminal output should look like this now:

Guess what? You are almost done!

Step 2: Upload your key file to .oci directory or generate one.

There are a couple options that you can do here. I use the same keys and config file across all my notebooks. This is mostly due to limits I have on the number of APIs keys I can have.

If you don’t have API signing keys already, then choose one of the following methods:

  1. Create new keys through the cloud console. You can find the option for this under Identity > Users > User Details > API Keys. Click on Add API Key and generate key pair. Then download the private and public keys. Don’t forget to change the file permissions on the keys. For step-by-step, follow the instructions provided in the documentation: Generating an API Signing Key (Console).
  2. Open up a fresh terminal in the data science notebook and generate API signing keys. The RSA key pair needs to be in PEM format (minimum 2048 bits). For step-by-step, follow the instructions provided in the documentation: Generating an API Signing Key (Console). Once signing keys are created you need to copy the public key. Go back to the API Keys page on the Cloud Console. Select Add API Key and paste the copied key.

Step 3: Get the information for the config file.

Once you have created your keys you can view the details. The details will give you all the information for the config file in proper format. Highlight the information and click copy. For more information about this go to SDK and CLI Configuration File.

See the image below for a visual:

Step 4: Create the config file in the Oracle Data Science notebook.

Now you can finish this up. Go back to the data science notebook terminal. Change to the .oci directory. Create a new file called config using the command below:

$ vi config

Paste the information you copied from the console page into the document. You may need to hit ESC and then i to paste in the contents. Finally, hit ESC and then colon and wq to exit vi.

At this point you should be good to go!

Fast Track to Generate API Signing Keys (excerpt from documentation):

If you don’t want to read the full documentation, here is how to generate API Signing Keys in the data science terminal. Note: Oracle Data Science is using Linux.

Step 1: Create an .ssh directory to store the credentials:

mkdir ~/.ssh 

Step 2: Generate the private key with one of the following commands.

  • To generate the key, encrypted with a passphrase you provide when prompted:
openssl genrsa -out ~/.oci/oci_api_key.pem -aes128 2048    
  • To generate the key with no passphrase:
openssl genrsa -out ~/.oci/oci_api_key.pem 2048 

Step 3. Change the file permission to ensure that only you can read the private key file:

chmod go-rwx ~/.oci/oci_api_key.pem

Step 4. Generate the public key from your new private key:

openssl rsa -pubout -in ~/.oci/oci_api_key.pem -out ~/.oci/oci_api_key_public.pem

Step 5. Copy the contents of the public key to the clipboard (you’ll need to paste the value into the Console later).

cat ~/.oci/oci_api_key_public.pem

Oracle documentation explaining all of this in detail is provided below:

--

--

Nicholas Toscano
A Guide to Oracle Cloud AI

I have about 20 years of experience as a national security professional.