Setting up an OCI Command Line (CLI) in Oracle Linux 8
Oracle Cloud Infrastructure Command Line Interface (OCI CLI) is a powerful tool that allows you to manage your Oracle Cloud Infrastructure resources and services through the command line. It provides a way to automate and script tasks, create and manage resources, and interact with your cloud environment programmatically. Here's a step-by-step guide to installing and setting up OCI CLI.
Before you start, ensure you have the following prerequisites:
Oracle Cloud Account: You need an active Oracle Cloud account.
Steps:
1) I will create a server with Oracle Linux 8 on OCI always free to use as a centralized OCI CLI server.
It will be completed within 5 mins in OCI.
2) It would a good choice to update server before installing the CLI. It will be a time taking process.
[opc@ocicliserver ~]$ sudo dnf update
3) Now Lets Install OCI CLI.
[opc@ocicliserver ~]$ sudo dnf -y install oraclelinux-developer-release-el8
[opc@ocicliserver ~]$ sudo dnf install python36-oci-cli
Make sure the installation is successful.
To uninstall the CLI:
sudo dnf remove python36-oci-cli
4) Check the OCI CLI version
[opc@ocicliserver ~]$ oci --version
3.23.2
5) Now we will setup the OCI to work with our Cloud Account.
CLI will provide a guided interface to setup using oci setup config
Please use below method to find the required information that is needed for setup.
To find USER OCID : Go to cloud account and login to OCI Console Profile> User Settings and copy the OCID ID for the user.
To find the Tenancy OCID: Go to cloud account and login to OCI Console Profile>Tenancy and copy the tenancy OCID.
To find the region Name: Go to the top ribbon and check the region name. Click on manage region to find the region identifier. Like in my case ap-hyderabad-1.
After we have all required information, I will do the setup using below command.
[opc@ocicliserver ~]$ oci setup configThis command provides a walkthrough of creating a valid CLI config file.The following links explain where to find the information required by thisscript:User API Signing Key, OCID and Tenancy OCID:https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#OtherRegion:https://docs.cloud.oracle.com/Content/General/Concepts/regions.htmGeneral config documentation:https://docs.cloud.oracle.com/Content/API/Concepts/sdkconfig.htmEnter a location for your config [/home/opc/.oci/config]: -->Hit enter to use default location.Enter a user OCID: ocid1.user.oc1..aaaaaaaarnhjftgeirzqh46eukw3eogdx5qeko2fkpydzgnco7saxyud7ykqEnter a tenancy OCID: ocid1.tenancy.oc1..aaaaaaaa6t2hb4hut3nde4luzi6xelomsgkksar42w7o6tydf5fdkkkz2ieqEnter a region by index or name(e.g.1: af-johannesburg-1, 2: ap-chiyoda-1, 3: ap-chuncheon-1, 4: ap-dcc-canberra-1, 5: ap-hyderabad-1,6: ap-ibaraki-1, 7: ap-melbourne-1, 8: ap-mumbai-1, 9: ap-osaka-1, 10: ap-seoul-1,11: ap-singapore-1, 12: ap-sydney-1, 13: ap-tokyo-1, 14: ca-montreal-1, 15: ca-toronto-1,16: eu-amsterdam-1, 17: eu-dcc-dublin-1, 18: eu-dcc-dublin-2, 19: eu-dcc-milan-1, 20: eu-dcc-milan-2,21: eu-dcc-rating-1, 22: eu-dcc-rating-2, 23: eu-frankfurt-1, 24: eu-madrid-1, 25: eu-marseille-1,26: eu-milan-1, 27: eu-paris-1, 28: eu-stockholm-1, 29: eu-zurich-1, 30: il-jerusalem-1,31: me-abudhabi-1, 32: me-dcc-muscat-1, 33: me-dubai-1, 34: me-jeddah-1, 35: mx-queretaro-1,36: sa-santiago-1, 37: sa-saopaulo-1, 38: sa-vinhedo-1, 39: uk-cardiff-1, 40: uk-gov-cardiff-1,41: uk-gov-london-1, 42: uk-london-1, 43: us-ashburn-1, 44: us-chicago-1, 45: us-gov-ashburn-1,46: us-gov-chicago-1, 47: us-gov-phoenix-1, 48: us-langley-1, 49: us-luke-1, 50: us-phoenix-1,51: us-sanjose-1): ap-hyderabad-1Do you want to generate a new API Signing RSA key pair? (If you decline you will be asked to supply the path to an existing key.) [Y/n]: YEnter a directory for your keys to be created [/home/opc/.oci]: --> Hit Enter to use default locationEnter a name for your key [oci_api_key]:Public key written to: /home/opc/.oci/oci_api_key_public.pemEnter a passphrase for your private key (empty for no passphrase):Repeat for confirmation:Private key written to: /home/opc/.oci/oci_api_key.pemFingerprint: 35:3a:56:4e:32:82:88:d2:44:04:ca:d0:d1:58:b0:26Do you want to write your passphrase to the config file? (If not, you will need to enter it when prompted each time you run an oci command) [y/N]: yConfig written to /home/opc/.oci/config
6) Now the setup is completed on server. We will need to upload the API key on OCI user which will be using for authentication.
Let's see the file which were created in earlier step.
[opc@ocicliserver .oci]$ pwd
/home/opc/.oci
[opc@ocicliserver .oci]$ ls -ltr
total 12
-rw-------. 1 opc opc 451 Aug 15 06:46 oci_api_key_public.pem
-rw-------. 1 opc opc 1874 Aug 15 06:47 oci_api_key.pem
-rw-------. 1 opc opc 324 Aug 15 06:47 config
copy the content from the public key(oci_api_key_public.pem) and go to Cloud console, Profile> User Settings> Go on Resource> API keys and add the key.
Once added, we will see the fingerprint in the API keys list.
Thats complete our OCI CLI setup.
7) Let test if we are able to run a command from CLI now.
[opc@ocicliserver ~]$ oci iam compartment list |grep -i name
"name": "foabox_compartment",
"name": "funoracleapps_site",
"name": "gold1_compartment",
"name": "ManagedCompartmentForPaaS",
"name": "sandbox_compartment",
Hurray we are able to get the information from Command line now.
We can use various commands to manage resources, create instances, configure networking, and perform other tasks in our Oracle Cloud Infrastructure environment.
Post a Comment
Post a Comment