AWS Credentials File: Profiles, Configuration, and Secure Usage
Learn how AWS credentials work, where the shared credentials file is stored, how profiles and credential resolution work, and how to configure AWS CLI and SDK access securely.
AWS credentials are authentication material used to sign requests to AWS. They let a tool identify a principal, such as an IAM user, an assumed role, or an IAM Identity Center session, and request AWS services.
Authentication and authorization
Authentication answers “Who is making this request?” Authorization answers “What is that principal allowed to do?” AWS credentials help authenticate the request. IAM policies, resource policies, organization controls, and other AWS security controls determine whether the authenticated principal is authorized to perform an action.
A long-lived access key normally has two values:
- Access key ID: the public identifier portion of the key.
- Secret access key: the sensitive value used to sign requests. Treat it like a password.
Temporary credentials have a third required value: a session token. Temporary credentials also have an expiration time. The access key ID, secret access key, and session token must come from the same session.
The shared AWS credentials file
The shared credentials file is a local INI-style file used by the AWS CLI, SDKs, and other AWS-aware tools. Its default locations are:
- Linux and macOS:
~/.aws/credentials - Windows:
%UserProfile%\.aws\credentials
The file contains credential profiles. You can inspect the topic path at the shared credentials file.
The credentials file is separate from the AWS config file, normally ~/.aws/config. The AWS config file commonly stores regions, output formats, role settings, and other non-secret configuration. Some settings can be read from either file depending on the tool, but credentials and configuration should be treated as separate concerns.
| File | Default location | Typical contents | Example profile syntax |
|---|---|---|---|
| Shared credentials file | ~/.aws/credentials | Access keys and session tokens | [development] |
| AWS config file | ~/.aws/config | Region, output, role, SSO, and provider settings | [profile audit] |
Profiles
A profile is a named set of AWS credential or configuration settings. The default profile is used when no other profile is selected. Named profiles let you separate accounts, environments, roles, or users instead of repeatedly replacing one set of values.
Default profile
[default] aws_access_key_id = AKIAEXAMPLE aws_secret_access_key = example-secret-key
Named profiles
[development] aws_access_key_id = AKIADEVEXAMPLE aws_secret_access_key = development-secret [production] aws_access_key_id = AKIAPRODEXAMPLE aws_secret_access_key = production-secret
These examples use placeholder values. Never copy real secret keys into tutorials, tickets, repositories, screenshots, or chat messages.
Temporary credentials in a profile
[temporary] aws_access_key_id = ASIAEXAMPLE aws_secret_access_key = temporary-secret aws_session_token = temporary-session-token
A temporary profile is valid only until its session expires. Do not mix an old session token with newly issued key values.
Selecting a profile
| Method | Example | When to use it | Scope |
|---|---|---|---|
| Command option | aws s3 ls --profile development | One explicit CLI command | One command |
| Environment variable | export AWS_PROFILE=development | Several commands in one shell session | Current process and child processes |
| SDK configuration | Set the SDK's profile or shared-config option | Local application development | That application or client |
| Default behavior | No profile option or variable | When the default profile is intentionally correct | Each command or process |
For a shell session, select a profile with:
export AWS_PROFILE=development
On Windows PowerShell, the equivalent is $env:AWS_PROFILE = "development". An explicit command option is useful when you want the selected account to be visible in the command itself.
Configuring credentials
The AWS CLI can interactively create or update a default profile:
aws configure
To configure a named profile:
aws configure --profile development
These commands prompt for an access key ID, secret access key, default region, and output format. Use them only with credentials obtained through an approved organizational workflow.
For workforce access, prefer IAM Identity Center sign-in or an approved role-based workflow when available. IAM Identity Center provides federated sign-in and permission sets, while IAM roles provide assumable identities. Creating a new IAM user access key may be appropriate for a narrowly defined local or automation use case, but long-lived user keys require careful protection and rotation.
Role assumption and temporary access
An IAM role is an assumable identity with permissions. AWS STS, the AWS Security Token Service, issues temporary credentials when a user, workload, or other trusted principal assumes a role. Temporary access is often safer than distributing persistent user access keys because it can expire and can be limited to a specific role and session.
A role-based profile generally belongs in the config file and points to a source identity or another approved identity provider:
[profile audit] role_arn = arn:aws:iam::123456789012:role/AuditRole source_profile = development region = us-east-1
The source_profile supplies credentials that are allowed to assume the role. In other setups, the source may be IAM Identity Center, a web identity provider, or a compute workload identity. Avoid adding another long-lived access key merely to support a role profile.
Credential provider chain and resolution order
The credential provider chain is the ordered set of sources an AWS tool checks for credentials. Exact behavior varies by SDK and CLI version, but the practical rule is that an explicit setting usually wins over less-specific sources. Common sources include:
- Credentials explicitly supplied in a command, SDK client, or application setting.
- Environment variables such as
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, andAWS_SESSION_TOKEN. - The selected profile in the shared credentials file and AWS config file.
- IAM Identity Center, role-assumption, web-identity, or other configured identity providers.
- Workload identity supplied by an AWS compute environment, such as an instance, container, or task role.
Do not assume that the credentials file is always being used. An environment variable, cached sign-in session, role provider, or workload role may take precedence. An unexpected source can make a command run against the wrong account, even when the profile file looks correct.
| Credential source | Typical use case | Lifetime | Security considerations |
|---|---|---|---|
| Explicit application or command setting | Specific test or controlled integration | Depends on supplied credentials | Easy to embed accidentally; avoid hard-coding secrets |
| Environment variables | CI jobs, containers, temporary shell sessions | Depends on supplied credentials | May leak through process inspection, diagnostics, or logs |
| Shared credentials/config files | Local CLI and SDK development | Often long-lived, unless values are temporary | Protect file permissions and never commit the files |
| IAM Identity Center or assumed role | Workforce access and cross-account work | Usually short-lived | Prefer approved sign-in and role policies |
| Compute workload role | Applications running on AWS compute | Rotated automatically in many services | Use least-privilege role permissions |
Verify identity before doing work
Always confirm the active account and principal before creating, deleting, changing, or inspecting sensitive resources:
aws sts get-caller-identity
The response includes the account ID and an ARN identifying the caller. Also inspect the source selected by the CLI:
aws configure list
When the output is unexpected, check the selected profile and the environment variables in the current shell. Run the identity command again after changing the credential source.
Security practices
- Use least privilege: grant only the actions and resources required for the task.
- Prefer short-lived credentials from IAM Identity Center, STS role assumption, or workload roles.
- Use MFA where applicable, especially for privileged human access.
- Rotate long-lived access keys on an approved schedule and remove keys that are no longer needed.
- Store local files under the correct user account and use restrictive permissions. On Unix-like systems, run
chmod 600 ~/.aws/credentials. - Keep secrets out of shell history, debug output, crash reports, and CI logs.
- Use separate profiles and accounts for development and production, and verify identity before impactful commands.
Managing IAM user keys and sign-in methods
IAM user access keys are persistent credentials associated with an IAM user. They are not the same as IAM Identity Center sign-in sessions or role credentials. For human workforce access, IAM Identity Center or federation is generally preferable. For AWS-hosted applications, use a workload role instead of placing an IAM user key on the host.
If a local CLI workflow genuinely requires an IAM user access key, create it through the AWS console or an approved administrative process, grant the user only the required permissions, and save the values using a protected credential mechanism. The secret access key is normally shown only when the key is created, so do not lose it or request that others send it to you.
To rotate a key, create and test an approved replacement, update the consuming profile or environment, verify the new identity, and then deactivate or delete the old key. If a key is compromised, deactivate or delete it immediately, investigate recent activity, remove it from exposed locations and repository history where appropriate, and create a replacement only if the workload still needs one. Removing text from the latest commit is not sufficient if the secret remains in repository history or logs.
Troubleshooting
| Symptom or error | Likely cause | How to verify | Resolution |
|---|---|---|---|
| Unable to locate credentials | No profile, wrong file location, unselected profile, or a different operating-system user/home directory | Run aws configure list; check the current user's default path, AWS_PROFILE, and --profile | Configure the intended profile or use an approved provider, then run aws sts get-caller-identity |
| The CLI uses the wrong AWS account | Environment variables override the profile, the default profile was selected, or cached role credentials belong to another account | Run identity and configuration checks; inspect AWS_PROFILE, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN | Remove unintended overrides, explicitly select the intended profile, and repeat the identity check |
| The security token is invalid or expired | Temporary credentials expired, the session token is missing, or values came from different sessions | Determine whether credentials are temporary and check that all three values were refreshed together | Renew credentials through the approved sign-in or role workflow; do not mix values manually |
| Access denied after credentials are found | The principal lacks permission, a resource policy denies access, or the account or region is wrong | Confirm caller identity and review the denied action, resource, IAM policies, organization controls, and resource policies | Use the intended role or ask the policy owner for only the necessary permission |
| Credentials were exposed | Keys were committed, logged, pasted, or shared | Identify the key and exposure locations; review recent activity | Deactivate or delete the key immediately, investigate use, remove exposure, and replace only if needed |
SDK use
Most AWS SDKs use a credential provider chain similar to the CLI and can read the shared credentials file, AWS config file, environment variables, IAM Identity Center sessions, role providers, or workload roles. This means an application may use a different source than expected if its process environment, profile setting, or runtime identity differs from your terminal.
For local development, select a named profile through the SDK's documented profile configuration rather than copying secret values into source code. For deployed applications, prefer the runtime's IAM role or another short-lived provider.
Exam-relevant notes
- The access key ID identifies the key; it is not a password by itself.
- The secret access key signs requests and must remain confidential.
- Temporary credentials require a session token and expire.
- The shared credentials file and AWS config file are separate files.
- The default profile is used when no profile is explicitly selected.
- Credential provider precedence can cause environment variables or workload roles to override a file profile.
- Authentication does not grant permissions; authorization is determined by applicable AWS policies and controls.