All posts
Stop Keeping AWS Keys in Plaintext

Stop Keeping AWS Keys in Plaintext

Tien Le H.'s avatarTien Le H.19 min read
Protect your AWS credentials with aws-vault: keep keys in your OS keychain, enforce MFA, and use short-lived sessions with Terraform, SSO and AI agents.
Table of Contents26 sections

In my previous articles about running Claude Code inside sandboxes and about developer security in 2026, one theme kept coming back: the most valuable thing on a developer machine is usually not the source code, but the tokens and credentials that sit next to it. For anyone working with AWS, the most famous example is a small text file that almost every tutorial tells you to create on day one: ~/.aws/credentials.

That file holds long-lived access keys in plaintext. Any process running under your user can read it: a malicious postinstall script in an npm package, an infostealer, a careless backup of your dotfiles, or an AI coding agent that decides to "check your AWS setup". When I reviewed how our team handles AWS access across many customer projects, I wanted a solution that was simple enough for every engineer to adopt in one afternoon, did not require changing the AWS CLI or SDKs, and removed plaintext keys completely. That solution is aws-vault.

This article is my hands-on tutorial. It explains what aws-vault does, how it works under the hood, and how I set it up step by step for daily work: running the CLI, opening the console, using Terraform and SDKs, working with IAM Identity Center, and giving AI agents only the access they need.

Version note: The original project 99designs/aws-vault is no longer maintained, and its README now points to the community fork ByteNess/aws-vault. The Homebrew formula aws-vault already builds from this fork. Everything in this article is based on the ByteNess documentation and releases as of November 2026 (the v7.13 series). The fork releases very frequently, so please check aws-vault --help and the release notes before rolling it out to your team.

TL;DR

  • aws-vault stores your long-lived IAM access keys in the operating system's secure store (macOS Keychain, Windows Credential Manager or Windows Hello, Linux Secret Service, pass, 1Password and more) instead of ~/.aws/credentials.

  • When you run a command, aws-vault calls AWS STS (GetSessionToken and/or AssumeRole) to create short-lived credentials, and passes only those temporary credentials to the command. Your long-lived keys never leave the vault.

  • Daily commands: aws-vault add, aws-vault exec <profile> -- <command>, aws-vault login <profile>, aws-vault list, aws-vault clear, aws-vault rotate.

  • It reads your existing ~/.aws/config, so profiles, role_arn, source_profile and mfa_serial work the same way as with the AWS CLI. MFA sessions are cached in the vault, so you do not type a code for every command.

  • For Terraform and other long-running SDK tools, use exec --server so credentials refresh automatically. For IDEs and GUI tools, use credential_process.

  • aws-vault is not magic: the temporary credentials are still visible to the process you start. Combine it with least-privilege roles, MFA, short durations and a locked keychain.

Why plaintext credentials are a real problem

Before installing anything, it is worth being clear about the threat model, because it decides how you configure aws-vault later.

Risk

How ~/.aws/credentials gets exposed

What aws-vault changes

Supply chain malware

A compromised npm, PyPI or VS Code extension reads the file during install and sends it out.

No file to read. The keys sit in an encrypted store that is locked when you are not using it.

Infostealers

Commodity malware collects well-known credential paths in seconds.

Same as above. Stolen temporary credentials expire in about an hour.

Accidental leaks

The file ends up in a dotfiles repository, a Time Machine backup, a support zip or a screen share.

The plaintext file is gone.

AI coding agents

An agent running under your user can cat ~/.aws/credentials or use the default profile without you noticing.

You decide which profile and role the agent gets, for how long, with aws-vault exec.

Long-lived blast radius

Access keys never expire. A leak from last year may still work today.

Every command works with STS credentials (ASIA...) that expire, and MFA can be required for anything sensitive.

The last point matters most. aws-vault does not only hide the key; it changes the default from "permanent credentials everywhere" to "temporary credentials, only for the command that needs them".

How aws-vault works

aws-vault does three things in sequence:

  1. Store. aws-vault add puts your IAM user's access key ID and secret into a secure backend. On macOS, it creates a dedicated keychain called aws-vault, separate from your login keychain, with its own password.

  2. Exchange. When you run aws-vault exec, it reads ~/.aws/config, unlocks the vault, and calls STS. Depending on the profile, it calls GetSessionToken (with your MFA code if mfa_serial is set), then AssumeRole for the target role. The MFA-backed session is cached in the vault so the next command does not ask for MFA again.

  3. Deliver. It passes the temporary credentials to the child process, either as environment variables (the default) or through a local credential server that mimics the ECS/EC2 metadata endpoint (--server).

Figure 1: Long-lived keys stay in the OS vault. aws-vault exchanges them with STS for temporary credentials and hands only those to the command you run.

With the default environment variable mode, the child process sees something like this:

$ aws-vault exec tien -- env | grep AWS
AWS_VAULT=tien
AWS_REGION=ap-northeast-1
AWS_DEFAULT_REGION=ap-northeast-1
AWS_ACCESS_KEY_ID=ASIA...
AWS_SECRET_ACCESS_KEY=...
AWS_SESSION_TOKEN=...
AWS_CREDENTIAL_EXPIRATION=2026-11-20T10:16:27Z

Notice the ASIA prefix: these are STS session credentials. Long-lived IAM user keys start with AKIA. If you ever see AKIA inside an aws-vault session, you are using --no-session with a profile that has no role, and your long-lived key is exposed to that process.

Step 1: Install aws-vault

# macOS and Linux (Homebrew): the formula builds from ByteNess/aws-vault
$ brew install aws-vault

# Windows
> choco install aws-vault

# NixOS
$ nix-env -iA nixos.aws-vault

# Or download a binary from https://github.com/ByteNess/aws-vault/releases/latest

Check what you installed:

$ aws-vault --version
$ brew info aws-vault        # the homepage should be github.com/ByteNess/aws-vault

If you installed aws-vault years ago from the old 99designs Homebrew cask or a direct download, uninstall it first so you do not end up with two binaries on your PATH. On macOS, release builds are code-signed, which reduces repeated Keychain "allow access" prompts. You can verify the signature with codesign -dvv $(which aws-vault).

It is also worth enabling shell completion (bash, zsh and fish are supported, see the shell completion docs), because you will type profile names a lot.

Step 2: Prepare IAM so the stored key is worth very little

aws-vault protects how the key is stored and used, but the best protection is making the long-lived key almost useless on its own. The pattern recommended in the aws-vault documentation, and the one I use, is:

  • One IAM user per engineer, in a central "identity" account, with a virtual MFA device.

  • That user has no permissions to touch resources directly. It may only assume roles, and only with MFA.

  • Real permissions live in roles inside each workload account (dev, staging, prod), for example ReadOnly, Developer, Administrator.

A minimal identity policy for the IAM user could look like this:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AssumeWorkRolesWithMfaOnly",
      "Effect": "Allow",
      "Action": "sts:AssumeRole",
      "Resource": [
        "arn:aws:iam::222222222222:role/Developer",
        "arn:aws:iam::333333333333:role/ReadOnly",
        "arn:aws:iam::333333333333:role/Administrator"
      ],
      "Condition": { "Bool": { "aws:MultiFactorAuthPresent": "true" } }
    },
    {
      "Sid": "RotateOwnAccessKeys",
      "Effect": "Allow",
      "Action": ["iam:GetUser", "iam:CreateAccessKey", "iam:DeleteAccessKey", "iam:ListAccessKeys"],
      "Resource": "arn:aws:iam::111111111111:user/${aws:username}"
    }
  ]
}

The second statement lets aws-vault rotate replace your access key later. You will also want the standard permissions that let users manage their own MFA device; AWS documents a ready-made policy for that.

On each role in the workload accounts, the trust policy also requires MFA:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111111111111:root" },
      "Action": "sts:AssumeRole",
      "Condition": { "Bool": { "aws:MultiFactorAuthPresent": "true" } }
    }
  ]
}

With this design, even if someone steals the access key, they cannot do anything without your MFA device. aws-vault then makes this setup comfortable to use every day.

If your organization already uses AWS IAM Identity Center, you can avoid long-lived keys entirely. aws-vault supports Identity Center too, and I cover that in Step 8.

Step 3: Move your keys into the vault

Add the IAM user's key to aws-vault. Use a profile name that represents you (the source identity), not a project:

$ aws-vault add tien
Enter Access Key Id: AKIA................
Enter Secret Key: ****************************************
Enter MFA Device ARN (If MFA is not enabled, leave this blank): arn:aws:iam::111111111111:mfa/tien-iphone
Added credentials to profile "tien" in vault

On macOS, the first add creates the aws-vault keychain and asks you to choose a password for it. Use a strong, unique password and store it in your password manager.

Check that it worked:

$ aws-vault list
Profile                  Credentials              Sessions
=======                  ===========              ========
tien                     tien                     -

Now the important part: delete the plaintext copy. Open ~/.aws/credentials, remove the section you just migrated, and delete the file when it is empty. Repeat aws-vault add for any other IAM users you have. If you keep the plaintext file "just in case", you have not actually solved the problem.

$ aws-vault exec tien -- aws sts get-caller-identity   # works, through the vault
$ rm ~/.aws/credentials                                 # after migrating every profile

Step 4: Describe your accounts and roles in ~/.aws/config

aws-vault reads the same config file as the AWS CLI, so there is nothing new to learn. My layout for a customer project looks like this:

[default]
region = ap-northeast-1

# A "mixin" profile: shared settings loaded by other profiles
[profile cm-base]
region = ap-northeast-1
mfa_serial = arn:aws:iam::111111111111:mfa/tien-iphone

# The source identity stored in the vault (the IAM user)
[profile tien]
include_profile = cm-base

# Workload roles
[profile acme-dev]
include_profile = cm-base
source_profile = tien
role_arn = arn:aws:iam::222222222222:role/Developer

[profile acme-prod-readonly]
include_profile = cm-base
source_profile = tien
role_arn = arn:aws:iam::333333333333:role/ReadOnly

[profile acme-prod-admin]
include_profile = cm-base
source_profile = tien
role_arn = arn:aws:iam::333333333333:role/Administrator

A few things worth knowing:

  • include_profile is an aws-vault extension (older versions called it parent_profile). It loads settings "horizontally" from another profile, so I write region and mfa_serial once. Since aws-vault v5, each profile must specify mfa_serial itself, like the AWS CLI; include_profile keeps that tidy.

  • The same mfa_serial on the source profile and the role profiles lets aws-vault reuse one MFA-backed session across all roles. You enter one MFA code and then switch between acme-dev, acme-prod-readonly and others without new prompts until the session expires.

  • Only the tien profile has credentials in the vault. The role profiles contain no secrets at all, so this file is safe to share as a team template (just replace the user and MFA ARNs).

  • You can add session_tags, transitive_session_tags and source_identity to profiles if your organization uses them for auditing or attribute-based access control.

Figure 2: One IAM user with MFA in the identity account, no direct permissions. Every real action happens through a role in a workload account, and only the IAM user's key is stored in the vault.

Step 5: Daily usage

Run a single command

$ aws-vault exec acme-dev -- aws s3 ls
Enter MFA code for arn:aws:iam::111111111111:mfa/tien-iphone: 123456
bucket-1
bucket-2

Always put -- between the profile and the command. It tells aws-vault that everything after it belongs to your command, and it keeps shell autocompletion working.

Start a subshell

If you are going to run many commands against one account, start a subshell:

$ aws-vault exec acme-dev
Starting subshell /bin/zsh, use `exit` to exit the subshell
$ aws sts get-caller-identity
$ terraform plan
$ exit

Inside the subshell, AWS_VAULT=acme-dev is set. I add it to my shell prompt so I always see which account I am in:

# ~/.zshrc
PROMPT='${AWS_VAULT:+[aws:$AWS_VAULT] }'$PROMPT

aws-vault also protects you from nesting sessions by accident. If you run aws-vault exec inside an existing aws-vault subshell, it refuses with "running in an existing aws-vault subshell; 'exit' from the subshell or unset AWS_VAULT to force". This prevents the confusing situation where you think you are in dev but are actually in prod.

Open the AWS console

$ aws-vault login acme-prod-readonly

This opens your browser already signed in to the console with the role's temporary session. Useful options:

  • --stdout (or -s) prints the sign-in URL instead of opening the browser, handy if you use separate browser profiles per customer.

  • --browser or AWS_VAULT_BROWSER chooses which browser to open.

  • --auto-logout (-a) tries to log out of the current console session first, which avoids the "you are already signed in to another account" page. Do not use it if you rely on the console's multi-session feature.

Inspect and clear sessions

$ aws-vault list                 # profiles, stored credentials, cached sessions
$ aws-vault clear                # remove all cached sessions now
$ aws-vault clear acme-prod-admin

I run aws-vault clear at the end of the day, or right after finishing a production task.

What gets cached, and when you see MFA prompts

The aws-vault documentation includes a helpful table. Translated to my example profiles:

Command

Credentials given to the command

Cached in the vault

MFA prompt

aws-vault exec tien --no-session

Long-term IAM key (AKIA)

No

No

aws-vault exec tien

Session token

Session token

Yes

aws-vault exec acme-dev

Session token, then role

Session token

Yes

aws-vault exec acme-dev --duration=2h

Role (assumed directly with MFA)

Role

Yes

In practice: the first command in the morning asks for an MFA code, and the cached MFA session is reused for every role that shares the same mfa_serial until it expires. I avoid --no-session except for the few IAM APIs that refuse session credentials.

Step 6: Harden the vault itself (macOS)

The vault is only as strong as its lock. If the aws-vault keychain stays unlocked all day, any process running under your user can quietly call aws-vault exec and receive credentials. Two settings make a big difference.

Lock the keychain automatically:

# Lock after 15 minutes of inactivity and when the Mac sleeps
$ security set-keychain-settings -lut 900 aws-vault.keychain
$ security show-keychain-info aws-vault.keychain

# Lock it immediately, for example at the end of a production task
$ security lock-keychain aws-vault.keychain

You can also do this in the Keychain Access app: right-click the aws-vault keychain, choose "Change Settings", and set "Lock after X minutes of inactivity".

Unlock with Touch ID instead of typing the password:

$ security lock-keychain aws-vault.keychain
$ aws-vault list --biometrics       # first time: asks for the keychain password once in the terminal

# Make it permanent
$ echo 'export AWS_VAULT_BIOMETRICS=true' >> ~/.zshrc

According to the documentation, the first unlock asks for the keychain password once and stores it in your login keychain, then Touch ID is used when the aws-vault keychain is locked. Do this first unlock from a terminal, not from a credential_process call. Touch ID handling has been actively improved in recent releases (v7.13.1 includes a fix to require Touch ID on every credential access), so read the release notes for the version you install.

A short lock timeout plus Touch ID gives you a good balance: unlocking costs one touch, so there is no temptation to keep the vault open all day.

Choose a GUI prompt for MFA when there is no terminal. For tools that call aws-vault in the background, set a prompt driver so the MFA prompt can appear:

export AWS_VAULT_PROMPT=osascript     # macOS dialog. Other drivers exist for Linux and Windows

You can also use ykman as a prompt driver to read TOTP codes from a YubiKey (see the YubiKey docs).

Step 7: Tune session durations

Shorter is safer, but too short becomes annoying. aws-vault gives you two levels of control.

Per command with --duration (or AWS_VAULT_DURATION):

$ aws-vault exec acme-prod-admin --duration=30m -- aws ec2 describe-instances

Defaults with environment variables (values need a unit such as 30m or 8h):

Variable

Default

Controls

AWS_SESSION_TOKEN_TTL

1h

GetSessionToken sessions used directly

AWS_CHAINED_SESSION_TOKEN_TTL

8h

The MFA session used as a base for assuming roles

AWS_ASSUME_ROLE_TTL

1h

Role sessions

AWS_FEDERATION_TOKEN_TTL

1h

Federation tokens (console login)

AWS_MIN_TTL

5m

Minimum remaining lifetime before aws-vault refreshes a cached session

The defaults explain the behavior you see every day: you enter MFA roughly once per working day (the 8 hour chained session), while each role session is still only one hour. Keep in mind that AWS caps AssumeRole at 1 hour when it is role chaining, so asking for a longer role duration in that situation is capped, and aws-vault logs "capping AssumeRole duration ... for role chaining".

My own settings: I keep the defaults for dev, and use --duration=30m plus aws-vault clear for anything that touches production.

Step 8: Use aws-vault with real tools

Terraform, CDK and SDK-based tools: use --server

With environment variables, credentials are fixed when the process starts. A terraform apply that runs longer than the role session fails halfway. The fix is the local credential server:

$ aws-vault exec acme-dev --server -- terraform apply

--server is an alias for --ecs-server. aws-vault starts a credential endpoint on a random local port, protected by an authorization token, and sets AWS_CONTAINER_CREDENTIALS_FULL_URI and AWS_CONTAINER_AUTHORIZATION_TOKEN instead of access keys. AWS SDKs ask that endpoint for credentials and refresh them automatically, so you can keep sessions short without breaking long runs. Add --lazy to fetch credentials only when the tool first asks for them.

There is also --ec2-server, which emulates the EC2 metadata service on the well-known IP. It needs root privileges, and while it runs any local application can use the profile's credentials, so I do not recommend it for daily work.

IDEs and GUI tools: use credential_process

Some tools do not run from your shell, for example the AWS Toolkit in your IDE or a database client. For those, let the AWS SDK call aws-vault itself:

[profile acme-dev-ide]
mfa_serial = arn:aws:iam::111111111111:mfa/tien-iphone
credential_process = aws-vault --prompt=osascript export --format=json acme-dev

Two rules from the documentation:

  • If MFA is involved, always specify a prompt driver (--prompt=osascript on macOS), otherwise the tool hangs waiting for an MFA code nobody can enter.

  • Do not run aws-vault exec directly on a profile that already uses credential_process calling aws-vault. The SDK invokes aws-vault for you.

Docker containers

Containers do not need any AWS keys. The ByteNess repository includes a small reverse proxy (contrib/_aws-vault-proxy) that exposes the aws-vault credential server to containers on the standard ECS address 169.254.170.2:

$ aws-vault exec --server --lazy base-role -- docker compose up --build aws-vault-proxy

# In another terminal, choose which role the container gets
$ export AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=/role-arn/arn:aws:iam::222222222222:role/app-role
$ docker compose run testapp

The requested role must be assumable by the base role. For simple cases, aws-vault exec acme-dev -- docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -e AWS_REGION ... also works, with the usual limitation that the credentials do not refresh.

AWS IAM Identity Center (SSO)

If your organization uses IAM Identity Center, aws-vault can use it directly. The SSO tokens are stored in the aws-vault backend rather than in the plaintext cache directory used by the AWS CLI:

[sso-session classmethod]
sso_start_url = https://your-portal.awsapps.com/start
sso_region = ap-northeast-1
sso_registration_scopes = sso:account:access

[profile acme-dev-sso]
sso_session = classmethod
sso_account_id = 222222222222
sso_role_name = Developer
region = ap-northeast-1
$ aws-vault exec acme-dev-sso -- aws sts get-caller-identity

By default aws-vault uses the PKCE flow and opens your browser. With sso_registration_scopes set, it can renew the token in the background until the Identity Center session ends. Use --device-code (or AWS_VAULT_DEVICE_CODE) on headless machines; it is used automatically in SSH sessions. You can also chain a role from an SSO profile with source_profile.

Step 9: Give AI coding agents only what they need

This is the part that convinced me to standardize aws-vault in our team. AI agents like Claude Code run commands under your user. Without aws-vault, "your user" includes every key in ~/.aws/credentials, and the default profile is one aws command away.

With aws-vault, I start the agent inside a deliberately limited session:

# Read-only role, short session, agent only sees temporary credentials
$ aws-vault exec acme-prod-readonly --duration=1h -- claude

# For infrastructure work in dev, with automatic refresh through the SDK
$ aws-vault exec acme-dev --server -- claude

What this gives me:

  • The agent never sees a long-lived key. The worst case is a read-only, one hour credential for one account.

  • The role, not my personal identity, decides what the agent can do. I can create an AgentReadOnly role with an even narrower policy if needed.

  • CloudTrail shows the role session, so it is easy to review what happened.

What it does not give me, and why I keep the other habits:

  • Temporary credentials in environment variables are readable by everything inside that process tree, including the agent. Scope the role, not just the duration.

  • If the aws-vault keychain is unlocked, a process running as your user could call aws-vault exec for another profile, or unset AWS_VAULT and start a nested session. A short keychain lock timeout and Touch ID (Step 6) close most of this gap. For stronger isolation, run the agent inside a sandbox or a microVM as described in my Docker Sandboxes article, and pass in only the credentials it needs.

Step 10: Rotate keys regularly

Because only one long-lived key per person exists, rotating it is easy:

$ aws-vault rotate tien

aws-vault creates a new access key, stores it in the vault, verifies it, and deletes the old key. Rotation needs MFA configured on the profile (or --no-session), because IAM restricts which APIs session credentials can call. The RotateOwnAccessKeys statement in Step 2 grants exactly the permissions this command needs. I put a recurring reminder in my calendar every 90 days.

Other operating systems and backends

aws-vault picks a sensible default per platform, and you can choose another with --backend or AWS_VAULT_BACKEND:

Platform

Default backend

Other useful options

macOS

keychain (optional Touch ID)

pass, passage, op-desktop (1Password app), file

Windows

wincred (Credential Manager)

winhello (encrypted, PIN or biometrics on every read)

Linux desktop

secret-service (GNOME Keyring, KWallet, oo7)

kwallet, keyctl, pass, passage, oo7

Headless or CI-like

file (passphrase-encrypted, ~/.awsvault/keys/)

op (1Password Service Accounts), op-connect

If you change your mind later, aws-vault migrate-backend --from <backend> --to <backend> copies long-lived credentials between backends (--dry-run first, --delete-source when you are confident). On Windows, migrating from wincred to winhello is a nice upgrade because every read then requires Windows Hello.

Troubleshooting

Symptom

Cause and fix

InvalidClientTokenId when calling some IAM APIs such as aws iam get-user

IAM restricts session credentials from GetSessionToken without MFA. Add mfa_serial to the profile, or use --no-session for that one command.

"running in an existing aws-vault subshell"

You are already inside aws-vault exec. Type exit first. Only unset AWS_VAULT if you really mean to nest.

The keychain asks "allow access" again and again

Usually a self-built or unsigned binary. Use the signed release from Homebrew or GitHub.

An IDE or GUI tool hangs when using credential_process

No prompt driver for MFA. Add --prompt=osascript (macOS) to the command in the config.

Terraform fails with expired credentials during a long apply

Use aws-vault exec <profile> --server -- terraform apply so the SDK refreshes credentials.

Requested a 4 hour role session but got 1 hour

Role chaining caps AssumeRole at 1 hour. Use --duration on a profile that assumes the role directly with MFA, or accept 1 hour with --server refresh.

The console opens the wrong account

Use aws-vault login -a to log out first, or --stdout and paste the URL into the right browser profile.

Conclusion

When I started this investigation, I expected aws-vault to be "a nicer place to store keys". It turned out to be a small change in tooling that drives a bigger change in habits: long-lived keys stay locked away, every command runs with short-lived credentials, and you decide explicitly which identity each tool or agent receives. Because it reuses ~/.aws/config and works with the standard AWS CLI and SDKs, adoption cost is close to zero, and the first afternoon of setup pays off immediately.

The two ideas I would like you to take away are:

  1. Make the stored key worth as little as possible. An IAM user that can only assume roles with MFA turns a leaked key into a non-event.

  2. Treat every session as temporary and scoped. Pick the narrowest profile, the shortest duration that is still comfortable, and lock the vault when you are done.

I hope this guide helps you and your team remove one of the most common plaintext secrets from your machines. If you have a different setup for managing AWS access across many projects, I would love to hear about it.

References