Cloud Explainers
Home › AWS

How to Fix AWS CLI 'Unable to Locate Credentials'

AWS8 min video

'Unable to locate credentials' means the AWS CLI looked for keys in a fixed list of places, in order, and found none, before sending anything to AWS. With the real AWS CLI 2.41.1 on an Ubuntu 24.04 server we show the list from its own debug log, then each common cause: never configured, keys saved under a profile the CLI doesn't read, a cron job without AWS_PROFILE, and sudo looking in root's home folder.

Twelve places, all empty

Your AWS command says Unable to locate credentials. Before it said that, the AWS CLI looked in twelve places for your keys.

Before: Unable to locate credentials: figure of 12 places it looked for your keys, source: aws s3 ls --debug, AWS CLI 2.41.1

Here's the error you searched for. Now the same command with debug turned on, showing only the lines where it names a place it checked. Twelve places, all empty. Usually the keys exist, and the CLI is looking under the wrong name, or in the wrong home folder. That's why a command can work when you type it, and fail at two in the morning.

Ana on the box-office server
aws s3 lsaws: [ERROR]: An error occurred (NoCredentials): Unable to locate credentials. You can configure credentials by running "aws login".
Ana on the box-office server
aws s3 ls --debug 2>&1 | grep -o 'credentials via: .*'credentials via: env
credentials via: assume-role
credentials via: assume-role-with-web-identity
credentials via: sso
credentials via: shared-credentials-file
credentials via: login
credentials via: custom-process
credentials via: config-file
credentials via: ec2-credentials-file
credentials via: boto-config
credentials via: container-role
credentials via: iam-role
Ana on the box-office server
aws s3 ls --debug 2>&1 | grep -c 'credentials via'12

Where the CLI looks

Those twelve places come in four kinds. First, environment variables: settings your shell hands to every command. Then the two files in a folder called dot A W S, in your home folder. Third and fourth, only on a machine inside AWS: a role for the container, then a role for the server, permissions AWS gives the machine itself. The first place with keys wins. If none of them has keys, you get the error, and nothing is ever sent to AWS. A profile is a named set of keys in those files; unless you say otherwise, the CLI only reads the one called default. So two things decide what it finds in those files: which profile it reads, and whose home folder it's looking in.

Where the AWS CLI looks, in order: diagram of aws s3 ls, Environment, ~/.aws files, Container role, Instance role, Unable to locate

The usual fix, and its trap

The usual fix first. Meet Ana. She runs the box-office server for a small theatre. She runs aws configure list. It shows what the CLI found, and where. Every line says not set. So she saves the theatre's keys with aws configure, under the name theatre. A key comes in two halves: an ID and a secret. One note: these are AWS's own example keys, and a local emulator stands in for S3. Stored keys are what scripts like Ana's need. If you only type commands yourself, aws login is the simpler way to sign in.

Ana on the box-office server
aws configure listNAME  : VALUE  : TYPE  : LOCATION
profile  : <not set>  : None  : None
access_key : <not set>  : None  : None
secret_key : <not set>  : None  : None
region  : <not set>  : None  : None
Ana on the box-office server
aws configure --profile theatreTip: You can deliver temporary credentials to the AWS CLI using your AWS Console session by running the command 'aws login'.

AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: eu-west-2
Default output format [None]: json

The keys are in the credentials file, under the name theatre. Guess first: does aws s3 ls work now? No. The same error.

Ana on the box-office server
cat ~/.aws/credentials[theatre]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Ana on the box-office server
aws s3 lsaws: [ERROR]: An error occurred (NoCredentials): Unable to locate credentials. You can configure credentials by running "aws login".

aws configure list says why: profile, not set. Without a name, the CLI reads the profile called default, and Ana has none. list profiles shows the one she does have. Name it with dash dash profile, and there's the theatre's bucket.

Ana on the box-office server
aws configure listNAME  : VALUE  : TYPE  : LOCATION
profile  : <not set>  : None  : None
access_key : <not set>  : None  : None
secret_key : <not set>  : None  : None
region  : <not set>  : None  : None
Ana on the box-office server
aws configure list-profilestheatre
Ana on the box-office server
aws s3 ls --profile theatre2026-11-19 12:54:43 riverside-box-office

To stop typing that, set AWS_PROFILE. Spell it wrong, and you get a different error: the profile theater could not be found. That one names its problem. Ana adds the setting to a file called.bashrc, which every new terminal reads. She sets it in this terminal too, and configure list now says the profile came from the environment.

Ana on the box-office server
AWS_PROFILE=theater aws s3 lsaws: [ERROR]: The config profile (theater) could not be found
Ana on the box-office server
echo 'export AWS_PROFILE=theatre' >> ~/.bashrc
Ana on the box-office server
export AWS_PROFILE=theatre
Ana on the box-office server
aws configure listNAME  : VALUE  : TYPE  : LOCATION
profile  : theatre  : env  : ['AWS_PROFILE', 'AWS_DEFAULT_PROFILE']
access_key : ****************MPLE  : shared-credentials-file :
secret_key : ****************EKEY  : shared-credentials-file :
region  : eu-west-2  : config-file  : ~/.aws/config

Environment variables come before the files, so a half-finished export wins too. Here an old test left something behind in this terminal: the key ID is set, but the secret isn't. The CLI stops at the environment and never reaches the profile: partial credentials found in env. Unset it, and the profile works again.

Ana on the box-office server
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
Ana on the box-office server
aws s3 lsaws: [ERROR]: Partial credentials found in env, missing: AWS_SECRET_ACCESS_KEY
Ana on the box-office server
unset AWS_ACCESS_KEY_ID

Works by hand, fails at 2 AM

Now the traps, where the keys exist but the CLI still can't find them. Think of looking for your house keys. You check the same pockets in the same order every time. Keys in the inside pocket while you only check the outside one: that's a profile the CLI doesn't read. Wearing someone else's coat: that's running a command as the admin, with sudo. Your own coat, but the note saying which pocket got left at home: that's a job a scheduler runs for you at night.

Like looking for your house keys: comparison table of Your keys vs The AWS CLI, Search, Profile, sudo, cron

Now the nightly job. Ana uses cron, the Linux scheduler that runs commands at set times. Every night it runs a script that copies the ticket sales to an S3 bucket. When she runs it herself, it works. At two in the morning, from cron, the same line fails with this same error. Same server, same user, same keys. So why can't cron find them?

Tonight's sales, to S3: diagram of Ana, by hand, cron, 2 AM, boxoffice, Backup bucket

Here's that script: one line that copies tonight's sales file to the bucket. She runs it, and it uploads.

Ana on the box-office server
cat backup.sh#!/bin/bash
# Riverside Theatre: copy tonight's box-office sales to the backup bucket.
aws s3 cp /srv/boxoffice/sales.csv s3://riverside-box-office/sales/sales-$(date +%F).csv
Ana on the box-office server
./backup.shupload: ../../srv/boxoffice/sales.csv to s3://riverside-box-office/sales/sales-2026-11-19.csv

Then Ana gives it to cron, set to run a minute from now, standing in for two A M. A second line writes down every setting cron hands the job, to look at later. A minute later, the log, and in the middle, the same words: Unable to locate credentials. Upload failed.

Ana on the box-office server
crontab -l56 12 * * * /home/ana/backup.sh >> /home/ana/backup.log 2>&1
56 12 * * * env > /home/ana/cron-env.txt
Ana on the box-office server
cat backup.logException ignored in: <s3transfer.crt.BotocoreCRTCredentialsWrapper object at 0xffff8ca7d010>
Traceback (most recent call last):
  File "awscli/s3transfer/crt.py", line 1194, in __call__
  File "awscli/s3transfer/crt.py", line 1204, in _get_credentials
botocore.exceptions.NoCredentialsError: Unable to locate credentials
upload failed: ../../srv/boxoffice/sales.csv to s3://riverside-box-office/sales/sales-2026-11-19.csv AWS_AUTH_CREDENTIALS_PROVIDER_DELEGATE_FAILURE: Valid credentials could not be sourced by the delegate provider

Cron gives the job a tiny environment. HOME is there, so the files would be found. AWS_PROFILE isn't. Ana set it in.bashrc, and cron never reads.bashrc. So the job asks for the default profile, which doesn't exist.

Ana on the box-office server
grep -E '^(HOME|AWS_)' cron-env.txtHOME=/home/ana
Ana on the box-office server
grep -n AWS_PROFILE ~/.bashrc118:export AWS_PROFILE=theatre

The fix goes where the job runs. A line at the top of the cron tab sets AWS_PROFILE for every job below it.

Name the profile where the job runs: code change of crontab -e, AWS_PROFILE=theatre (cron never reads.bashrc)

Next minute, the log ends with an upload, and the sales file is in the bucket.

Ana on the box-office server
crontab -lAWS_PROFILE=theatre
57 12 * * * /home/ana/backup.sh >> /home/ana/backup.log 2>&1
Ana on the box-office server
tail -n 1 backup.logupload: ../../srv/boxoffice/sales.csv to s3://riverside-box-office/sales/sales-2026-11-19.csv
Ana on the box-office server
aws s3 ls s3://riverside-box-office/sales/2026-11-19 12:57:02  104 sales-2026-11-19.csv

Fails with sudo

One more copy: the ticket system's own log, which only root, the machine's admin account, can read. The CLI skips it: not readable. So Ana puts sudo in front, and the keys are gone again.

Ana on the box-office server
aws s3 cp /var/log/boxoffice.log s3://riverside-box-office/logs/warning: Skipping file /var/log/boxoffice.log. File/Directory is not readable.
Ana on the box-office server
sudo aws s3 cp /var/log/boxoffice.log s3://riverside-box-office/logs/Exception ignored in: <s3transfer.crt.BotocoreCRTCredentialsWrapper object at 0xffff7d6cd010>
Traceback (most recent call last):
  File "awscli/s3transfer/crt.py", line 1194, in __call__
  File "awscli/s3transfer/crt.py", line 1204, in _get_credentials
botocore.exceptions.NoCredentialsError: Unable to locate credentials
upload failed: ../../var/log/boxoffice.log to s3://riverside-box-office/logs/boxoffice.log AWS_AUTH_CREDENTIALS_PROVIDER_DELEGATE_FAILURE: Valid credentials could not be sourced by the delegate provider

sudo runs the command as root, with root's home folder and none of Ana's variables. Someone else's coat. Here's the fix: use sudo just to read the file, and let Ana's own CLI do the upload. The vertical bar is a pipe; it passes the file along. The dash tells aws s3 cp to take its input from that pipe. And the log is in the bucket.

Ana on the box-office server
sudo env | grep -E '^(HOME|AWS_)'HOME=/root
Ana on the box-office server
sudo cat /var/log/boxoffice.log | aws s3 cp - s3://riverside-box-office/logs/boxoffice.log
Ana on the box-office server
aws s3 ls s3://riverside-box-office/logs/2026-11-19 12:57:10  118 boxoffice.log

On a server in AWS

Keys saved on a server are a risk: anyone who gets into the server gets the keys. Inside AWS, you skip them. Attach a role to the server. The CLI's last stop is the metadata service, a special address inside the server. It hands out short-lived keys that change by themselves. Ana's server isn't in AWS, so when the CLI tries that address, nothing answers.

Inside AWS: a role, not keys: diagram of aws s3 cp, Metadata service, Role, S3

Before you trust a script

A backup that fails at two in the morning can go unnoticed until the day you need it. So add two lines to the top of a script like Ana's. First, set dash e, which stops the script at the first command that goes wrong. Then a command that asks AWS who it is: aws sts get caller identity prints the account and the user its keys belong to. Our emulator says all zeros; real AWS shows your own. With no keys, that line fails, and the script stops before it copies anything.

Ana on the box-office server
aws sts get-caller-identity{
  "UserId": "000000000000",
  "Account": "000000000000",
  "Arn": "arn:aws:iam::000000000000:root"
}

Recap

Never set up? Run aws configure. Keys saved under a profile name? Set AWS_PROFILE, and in cron, set it in the cron tab. Partial credentials? Unset the stray key. With sudo, keep the CLI running as you. On AWS, use a role.

Whose home, which profile?: diagram of Never configured, Saved under a name, cron, Partial credentials, sudo, A server in AWS

If your backups are landing in the bucket again, subscribing brings more fixes, shown on real machines.

Every error in this video came from the real AWS CLI, and every command and the lab files are linked in the description. Thanks for watching Cloud Explainers.

Sources

Demos: a container on our own Mac standing in for a theatre's box-office server, with Floci, a local AWS emulator, standing in for S3; the theatre is made up and the keys are AWS's own documentation examples. Every error was the real AWS CLI's. Watch the full video on YouTube.

More videos

Python8 min

How to Fix Python ModuleNotFoundError: No Module Named

Go (Golang)5 min

Golang Pointers in 5 Minutes

Kubernetes8 min

How to Fix a Kubernetes Pod Stuck in CrashLoopBackOff

Homelab & self-hosting9 min

How to Fix a Homelab ESXi Host Not Responding

PostgreSQL24 min

PostgreSQL: Full Tutorial for Beginners

Load balancing & Nginx9 min

How a Load Balancer Works with HAProxy

Python9 min

How Python Virtual Environments Work

Homelab & self-hosting9 min

How to Fix Cloudflare Tunnel Errors in a Homelab

APIs9 min

How to Fix API CORS Errors: No 'Access-Control-Allow-Origin'

Auth (OAuth, JWT)9 min

How Authenticator App Login Codes Work (TOTP)

Git22 min

Git and GitHub: Full Tutorial for Beginners

Homelab & self-hosting10 min

How a Homelab Hypervisor Works (VMware ESXi)

Kubernetes9 min

How to Fix Kubernetes ImagePullBackOff Errors

DNS8 min

How to Fix DNS 'Temporary Failure in Name Resolution' on Linux

Homelab & self-hosting10 min

Proxmox vs ESXi for Your Homelab: When Each One Wins

PostgreSQL10 min

PostgreSQL UUID vs Auto Increment: Which Primary Key Should You Use?

Kubernetes21 min

Kubernetes: Full Tutorial for Beginners

Networking9 min

How TCP Sockets Work

PostgreSQL7 min

How to Fix PostgreSQL 'Could Not Connect to Server'

Claude & the Claude Developer Platform9 min

Claude Code Hooks Will Finally Make Sense After This

DevOps & CI/CD9 min

DevOps with Ansible Will Finally Make Sense After This

Networking9 min

How SNMP Network Monitoring Works

Git8 min

How to Fix GitHub 'Permission Denied (publickey)' Errors

Docker21 min

Docker: Full Tutorial for Beginners

PostgreSQL7 min

How to Fix PostgreSQL 'Password Authentication Failed'

Linux8 min

Why One Linux Server Handles More Users Than You Think

Networking7 min

How to Fix Network 'Connection Refused' Errors

DevOps & CI/CD9 min

DevOps Pipelines: Jenkins vs GitHub Actions

Linux11 min

Linux Nginx Reverse Proxy: Full Tutorial for Beginners

Networking11 min

Every Networking Term a Beginner Needs in 12 Minutes

Docker6 min

How to Fix Docker 'Permission Denied' on docker.sock

Git7 min

How to Fix Git 'Updates Were Rejected' When You Push

Linux7 min

How to Fix nginx 502 Bad Gateway Errors on Linux

Linux8 min

How to Fix Linux apt 'Could Not Get Lock' Errors (Ubuntu)

Networking9 min

How Email Works on the Internet (SMTP) in 10 Minutes

Python8 min

The Python Roadmap for Beginners

Go (Golang)21 min

Golang REST API with Gin: Full Tutorial for Beginners

Networking10 min

How a WireGuard VPN Network Works

Linux9 min

Linux Makefiles Will Finally Make Sense After This

Auth (OAuth, JWT)9 min

SAML vs OAuth vs OpenID Connect: What's the Difference?

Python7 min

How to Fix Python cron Jobs That Never Run

Linux22 min

Linux Bash Scripting: Full Tutorial for Beginners

Networking10 min

How PXE Network Boot Works

Active Directory9 min

How Active Directory Works

Linux10 min

How to Fix a Linux systemd Service That Won't Start

Linux9 min

Linux Logs: syslog vs journald

Auth (OAuth, JWT)9 min

JWT vs Session Cookies: Which One Should You Use?

Docker10 min

Docker vs Docker Compose: Which One Should You Use?

Docker9 min

How to Fix Docker Compose Containers That Can't Talk to Each Other

Django (Python web framework)22 min

Django Full Tutorial for Beginners

Linux9 min

How Linux systemd Works

Networking8 min

How to Fix 'Windows Cannot Access' Network Share Errors (SMB)

APIs10 min

REST vs gRPC: Which One Should You Use?

Certificates & PKI (ADCS)9 min

How to Fix SSL Certificate Chain Errors (Missing Intermediate)

Python9 min

Every Python Concept for Beginners in 10 Minutes

Databases & SQL9 min

Every SQL Join Type in 10 Minutes

OpenRouter (one API for many AI models)9 min

Why OpenRouter Free Models Hit Their Limit So Fast

Gemini API & Google AI Studio9 min

Why Your Gemini API Free Tier Runs Out So Fast

OpenRouter (one API for many AI models)10 min

OpenRouter Will Finally Make Sense After This

Caching & Redis10 min

How Redis Caching Works

Gemini API & Google AI Studio10 min

Gemini API vs Vertex AI: Which One Should You Use?

Gemini API & Google AI Studio8 min

How to Fix a Leaked Gemini API Key

Go (Golang)9 min

Why Golang Uses Goroutines Instead of Threads

Gemini API & Google AI Studio9 min

How to Fix Gemini API Error 429: Resource Exhausted

Claude & the Claude Developer Platform10 min

Claude Token Pricing Will Finally Make Sense After This

Python11 min

Why Python Web Scraping Returns Nothing (and the Fix)

Python10 min

Python uv vs pip: Which One Should You Use?

Python22 min

Python Automation: Full Tutorial for Beginners

Auth (OAuth, JWT)9 min

How OAuth Login Works

Gemini API & Google AI Studio10 min

Google AI Studio Will Finally Make Sense After This

Docker10 min

What Happens When You Run a Docker Container

Claude & the Claude Developer Platform8 min

How to Fix Claude Code Billing Your API Key Instead of Your Plan

Auth (OAuth, JWT)9 min

Why Passkeys Can't Be Phished Like Passwords

PowerShell10 min

PowerShell vs Bash: Which One Should You Learn?

Linux10 min

The Linux Roadmap for Beginners

Django (Python web framework)9 min

Django vs FastAPI: Which One Should You Use?

Databases & SQL10 min

Why SQLite Is the Most Used Database in the World

Databases & SQL11 min

How a NoSQL Database Like MongoDB Works

Python11 min

How to Fix Python pip error: externally-managed-environment

Databases & SQL9 min

How to Fix MySQL Too Many Connections Database Errors

Go (Golang)9 min

Golang Concurrency Will Finally Make Sense After This

AWS10 min

How Amazon S3 Works

Kubernetes10 min

How Kubernetes Works

Git10 min

How Git Works

Docker10 min

How to Fix Docker Port Already Allocated Errors

PostgreSQL10 min

How PostgreSQL Works

Git8 min

How to Fix Git Merge Conflicts

Linux9 min

How to Fix No Space Left on Device in Linux

Networking10 min

How the Internet Works

Databases & SQL9 min

SQL vs NoSQL: When Each One Wins

Auth (OAuth, JWT)8 min

How to Fix JWT Token Expired Errors (401 Unauthorized)

Claude & the Claude Developer Platform9 min

Claude API vs Claude Pro: Why Your Subscription Doesn't Include It

AI agent skills9 min

Why AI Agent Skills Beat Giant Prompts

Linux10 min

Linux Cron Jobs Will Finally Make Sense After This

Cybersecurity10 min

Security Logs Will Finally Make Sense After This

Cybersecurity8 min

How to Fix a Security Leak: An API Key Pushed to GitHub

DNS9 min

DNS Will Finally Make Sense After This

Cybersecurity9 min

Never Ignore a Security Update

Auth (OAuth, JWT)9 min

Two-Factor Authentication Will Finally Make Sense

Networking8 min

Never Expose a Database to the Internet

Cybersecurity10 min

SSH Keys vs Passwords: Which Is Safer for Security?

Linux10 min

The 5 Levels of Linux Boot: From Power On to Login

Networking12 min

The 5 Levels of Network Firewalls

Cybersecurity10 min

Password Security: Why Hackers Crack Weak Passwords

Linux9 min

Why Your Linux Server Runs Out of Memory

Networking10 min

HTTP vs HTTPS: What Actually Changes on Your Network

Linux12 min

Every Linux File Permission You Need to Know

Linux10 min

Linux Processes vs Threads: When Each One Wins

Networking11 min

The OSI Model Will Finally Make Sense After This

Git11 min

The 7 Levels of Git

Networking10 min

Every Network Troubleshooting Command You Need

Cybersecurity10 min

Hashing vs Encryption in Cybersecurity: When Each One Wins

Networking11 min

Why the Internet Ran Out of IP Addresses

Linux11 min

Linux Package Managers: apt vs Snap vs Flatpak

Python9 min

Why Python Is Slow (and When It Doesn't Matter)

Networking11 min

TCP vs UDP: When Each One Wins

Linux8 min

Stop Running Linux as Root (Do This Instead)

Linux11 min

Linux Users and Groups Will Finally Make Sense

Cybersecurity9 min

Why Phishing Beats Good Security (and How to Spot It)

Docker12 min

The 7 Levels of Docker

AI agents & MCP12 min

AI Agents Will Finally Make Sense After This

Git8 min

Stop Using git push --force (Use This Instead)

AI agent skills10 min

Agent Skills vs MCP: When Each One Wins

Networking12 min

Networking Will Finally Make Sense After This

Linux12 min

Every Linux Command You Actually Need

Cybersecurity12 min

The 7 Levels of Cybersecurity

System design12 min

Every System Design Concept You Need, in One Diagram

PostgreSQL10 min

Why PostgreSQL Ignores Your Index