事前に、OCIの管理コンソールから、Profile → User information にて、「User OCID」を確認します。続けて、Profile → Tenancy informationにて、「Tenancy OCID」を確認します。
以下のコマンドを実行します。
oci setup config
niikawa@niikawa2:~$ 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 [/home/niikawa/.oci/config]:
Enter a user OCID: ocid1.user.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Enter a tenancy OCID: ocid1.tenancy.oc1..yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
Enter a region by index or name(e.g.
1: af-johannesburg-1, 2: ap-batam-1, 3: ap-chiyoda-1, 4: ap-chuncheon-1, 5: ap-chuncheon-2,
6: ap-dcc-canberra-1, 7: ap-dcc-gazipur-1, 8: ap-delhi-1, 9: ap-hyderabad-1, 10: ap-ibaraki-1,
11: ap-melbourne-1, 12: ap-mumbai-1, 13: ap-osaka-1, 14: ap-seoul-1, 15: ap-seoul-2,
16: ap-singapore-1, 17: ap-singapore-2, 18: ap-suwon-1, 19: ap-sydney-1, 20: ap-tokyo-1,
21: ca-montreal-1, 22: ca-toronto-1, 23: eu-amsterdam-1, 24: eu-budapest-1, 25: eu-crissier-1,
26: eu-dcc-dublin-1, 27: eu-dcc-dublin-2, 28: eu-dcc-milan-1, 29: eu-dcc-milan-2, 30: eu-dcc-rating-1,
31: eu-dcc-rating-2, 32: eu-dcc-zurich-1, 33: eu-frankfurt-1, 34: eu-frankfurt-2, 35: eu-jovanovac-1,
36: eu-madrid-1, 37: eu-madrid-2, 38: eu-marseille-1, 39: eu-milan-1, 40: eu-paris-1,
41: eu-stockholm-1, 42: eu-zurich-1, 43: il-jerusalem-1, 44: me-abudhabi-1, 45: me-abudhabi-2,
46: me-abudhabi-3, 47: me-abudhabi-4, 48: me-alain-1, 49: me-dcc-doha-1, 50: me-dcc-muscat-1,
51: me-dubai-1, 52: me-jeddah-1, 53: me-riyadh-1, 54: mx-monterrey-1, 55: mx-queretaro-1,
56: sa-bogota-1, 57: sa-santiago-1, 58: sa-saopaulo-1, 59: sa-valparaiso-1, 60: sa-vinhedo-1,
61: uk-cardiff-1, 62: uk-gov-cardiff-1, 63: uk-gov-london-1, 64: uk-london-1, 65: us-ashburn-1,
66: us-ashburn-2, 67: us-chicago-1, 68: us-gov-ashburn-1, 69: us-gov-chicago-1, 70: us-gov-phoenix-1,
71: us-langley-1, 72: us-luke-1, 73: us-newark-1, 74: us-phoenix-1, 75: us-saltlake-2,
76: us-sanjose-1, 77: us-somerset-1, 78: us-thames-1): ap-tokyo-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]:
Enter a directory for your keys to be created [/home/niikawa/.oci]:
Enter a name for your key [oci_api_key]:
File /home/niikawa/.oci/oci_api_key_public.pem already exists, do you want to overwrite? [y/N]: y
Public key written to: /home/niikawa/.oci/oci_api_key_public.pem
Enter a passphrase for your private key ("N/A" for no passphrase):
Repeat for confirmation:
Private key written to: /home/niikawa/.oci/oci_api_key.pem
Fingerprint: ab:cd:12:34:ab:cd:12:34:ab:cd:12:34:ab:cd:12:34
Do 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]:
Config written to /home/niikawa/.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
niikawa@niikawa2:~$
niikawa@niikawa2:~$ oci iam compartment list
Private key passphrase:
ServiceError:
{
"client_version": "Oracle-PythonSDK/2.159.0, Oracle-PythonCLI/3.65.0",
"code": "NotAuthenticated",
"logging_tips": "Please run the OCI CLI command using --debug flag to find more debug information.",
"message": "The required information to complete authentication was not provided or was incorrect.",
"opc-request-id": "FE6B8E76EAD04ED285340B37830097DE/D6D2DC285B307B29FE9DAF684E525438/F0EB892DE22D15889FF5BC043AD26965",
"operation_name": "list_compartments",
"request_endpoint": "GET https://identity.ap-tokyo-1.oci.oraclecloud.com/20160918/compartments",
"status": 401,
"target_service": "identity",
"timestamp": "2025-08-28T00:08:30.931587+00:00",
"troubleshooting_tips": "See [https://docs.oracle.com/iaas/Content/API/References/apierrors.htm] for more information about resolving this error. If you are unable to resolve this issue, run this CLI command with --debug option and contact Oracle support and provide them the full error message."
}