oci-cli: ConfigFileNotFound - no config file at ~/.oci/config
Fixes oci-cli failing with ConfigFileNotFound because ~/.oci/config is missing. Use when the CLI errors before any API call saying no config file exists. The fix is oci setup config to generate it, or pointing OCI_CLI_CONFIG_FILE at the real file. Not for wrong-profile errors.
There is no config file. Run oci setup config and answer the prompts (it generates the key pair and writes ~/.oci/config), or set OCI_CLI_CONFIG_FILE to the file's real location. The CLI cannot authenticate with nothing to read.
$ oci iam user list
ConfigFileNotFound: Could not find config file at ~/.oci/configFix
Generate the config:
oci setup configAnswer the prompts (user OCID, tenancy OCID, region, generate a new key pair). Expected:
Private key written to: ~/.oci/oci_api_key.pemandConfig written to: ~/.oci/config.Upload the generated public key to the console (Identity, Users, your user, API Keys, Add API Key, paste
~/.oci/oci_api_key_public.pem). Expected: the fingerprint shown matches the config's fingerprint.If the file lives elsewhere, point the CLI at it:
export OCI_CLI_CONFIG_FILE=/path/to/configVerify:
oci iam user listExpected: user details print.
When this applies
ConfigFileNotFoundon new machines, containers, CI runners.- The
~/.oci/directory does not exist.
When it does NOT apply
ProfileNotFound: the file exists, the named profile does not.- 401 with an existing config: key/fingerprint problem.
- Session-auth expiry: the session token died, not the config.
Compatibility
- oci-cli 3.x.
Why it happens
The CLI's default config path is hardcoded to ~/.oci/config. Anything that changes HOME (sudo, containers, service users, CI) moves the lookup, and a fresh machine simply never had setup run. The error fires before any network call.
Edge cases
oci setup configoverwrites~/.oci/configif it exists; back it up first on machines with working profiles.- The config file holds no secrets itself, but
oci_api_key.pemnext to it does; keep both 0600. - In CI, prefer instance principals over copying config files and private keys around.