1.Requirements:
Python =>3
Cloud User OCID
Cloud Tenancy OCID
Cloud Region
Directory of public and private keys
2.How to get Python:
Download python3.6 from below link on the machine where you want to access Oracle cloud.
$curl -O https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
$tar -xvzf Python-3.6.0.tgz
# cd < Python-3.6.0 unzip directory>
# ./configure
# make
# make install
Once done the same can be verified using below command:
[root@mumbai ~]# python3 –version
Python 3.6.0
[root@mumbai ~]#
3.How to get Cloud User OCID:
Login to cloud console using the account details and click on the profile icon at the right corner.
Clicking on Profile->User Setting will land you to below page.
You can copy the highlighted OCID which is User ocid.
4.How to get Tenancy OCID:
To get the tenancy id, login to the cloud console page and click on the profile->Tenancy
Copy OCID which is tenancy OCID.
5.How to get Cloud Region:
You get the region details from the address bar of the URL as well as by clicking Manage Regions
6.Install OCI:
Dowload oci-cli.zip from following URL: https://github.com/oracle/oci-cli/releases and ship and unzip the same on desired machine. The unzipped contents look similar to below.
#cd oci-cli # ls -lrt total 7888 drwxr-xr-x 5 root root 4096 Apr 20 20:04 oci_cli_docs -rw-r--r-- 1 root root 41334 Apr 20 20:07 THIRD_PARTY_LICENSES.txt -rw-r--r-- 1 root root 7871263 Apr 20 20:07 oci_cli-2.10.0-py2.py3-none-any.whl -rw-r--r-- 1 root root 41206 Apr 20 20:07 LICENSE.txt -rw-r--r-- 1 root root 108688 Apr 20 20:07 CHANGELOG.rst
Run the following command to install the oci binaries.
[root@mumbai oci-cli]# pip3 install /root/oci-cli/oci_cli-2.10.0-py2.py3-none-any.whl
7.Configure CLI:
Following steps are required to configure CLI.
A) Setup Config. B) Upload Public Keys to OCI Console C) Verify the CLI
A) Setup Config.
To set up confi execute command “oci setup config” from the local machine. The command asks for the details (user ocid,tenancy ocid,cloud region and key location )which were captured in previous steps. Please refer below output of the same.
[root@mumbai oci-cli]# oci setup config This command provides a walkthrough of creating a valid CLI config file. The following links explain where to find the information required by this script: User API Signing Key, OCID and Tenancy OCID: https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#Other Region: https://docs.cloud.oracle.com/Content/General/Concepts/regions.htm General config documentation: https://docs.cloud.oracle.com/Content/API/Concepts/sdkconfig.htm Enter a location for your config [/root/.oci/config]: Enter a user OCID: <user OCID from previous steps> Enter a tenancy OCID: <Tenancy OCID from previous steps> Enter a region (e.g. ap-melbourne-1, ap-mumbai-1, ap-osaka-1, ap-seoul-1, ap-sydney-1, ap-tokyo-1, ca-montreal-1, ca-toronto-1, eu-amsterdam-1, eu-frankfurt-1, eu-zurich-1, me-jeddah-1, sa-saopaulo-1, uk-gov-london-1, uk-london-1, us-ashburn-1, us-gov-ashburn-1, us-gov-chicago-1, us-gov-phoenix-1, us-langley-1, us-luke-1, us-phoenix-1): ap-mumbai-1 Do 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]: Y Enter a directory for your keys to be created [/root/.oci]: Enter a name for your key [oci_api_key]: Public key written to: /root/.oci/oci_api_key_public.pem Enter a passphrase for your private key (empty for no passphrase): Private key written to: /root/.oci/oci_api_key.pem Fingerprint: 00:0f:3d:95:c3:59:36:b6:40:50:4e:3d:95:4b:b3:cc Config written to /root/.oci/config If you haven't already uploaded your API Signing public key through the console, follow the instructions on the page linked below in the section 'How to upload the public key': https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#How2
The key points to make note of from above output for the next steps are:
Public key
Fingerprint
B) Upload Public Keys to OCI Console:
cat the public key from above output file and upload to OCI console.
[root@mumbai oci-cli]# cat /root/.oci/oci_api_key_public.pem
—–BEGIN PUBLIC KEY—–
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArhKuxh82TS6m29btmC0Y
YupEoHcSFEZOfPiCFWrb62QFuuAtevdcRaMjaHp5vR8Zma1t23xd4eJLZU2M+GgE
f9tYIa7A9y7Z+nO4sEP6y3+lVtbSJ1A2XQMPxMgP2WFVcfMIMd8BtqrOCS5Vbm0Y
j2JqTZT13d55yvpNa6O7CdisFp9JtbEnS/ahrjoceqAUYj0JUxY6Ui9OHEVpHNUV
29ZcrMv1eCzEiPGYi8YydJUSZIAV0ayIGB4cEOPWFXCczUqgDHj0IKQIML46QBIN
JUdSkErzudlsdpHRx1yv1OgpgfXCD96CKYroIrkte8C/7gbUN2WH5JrYU6Jxl2IM
qQIDAQAB
—–END PUBLIC KEY—–
For uploading to OCI console, login to the cloud account and go to Profile->user setting as below.
As highlighted, please check if the Fingerprint from the console matches with
the one captured earlier.
C) Verify the CLI:
Once done verify if you are able to list the resources and contents hosted in your respective
account. Below command gives the output in JSON format.
[root@mumbai oci-cli]# oci os ns get
{
“data”: “bmb9ypusa0sd”
}
The details can also can be obtained from tabular format using below command.
oci iam compartment list --output table --query "data [*].{Cname:name,OCID:id}" [root@mumbai ~]# oci iam compartment list --output table --query "data [*].{Cname:name,OCID:id}" +---------------------------+-------------------------------------------------------------------------------------+ | Cname | OCID | +---------------------------+-------------------------------------------------------------------------------------+ | DEMO_COMPARTMENT | ocid1.compartment.oc1..aaaaaaaalvxje3bl3ux2zcixns5mdcqpz5bgduojcncavbhcbblcxlkkrlxq | | dmeo_compartment.1HGlZnBO | ocid1.compartment.oc1..aaaaaaaa7lv27x5ylupxfaquwnc6zbdmr4zmus6cumdu7n7xmqomysdf2lca | | ManagedCompartmentForPaaS | ocid1.compartment.oc1..aaaaaaaa3p67buwftfhvfgcqekyy42pv2ynzyszkwahkwcii4dopopnnxcbq | | Rajesh | ocid1.compartment.oc1..aaaaaaaacphfut6uqg3tmuw5k2xjz7blrrgeyy3cwbsxjxss3fa7amd5hcuq | | TC | ocid1.compartment.oc1..aaaaaaaasgjbxzx3bj6bqqerak44zxgcvytktztxbly7lbigc23xek5kwb2a | +---------------------------+-------------------------------------------------------------------------------------+
References: [OCI]: How to Install and Configure Command Line Interface For Oracle Cloud Infrastructure In Linux (Doc ID 2432759.1)