How to Clear your AWS CLI Credentials

Borislav Hadzhiev

Last updated: Feb 26, 2024
2 min


# Clear your AWS CLI Credentials

In order to clear your AWS CLI Credentials you have to:

  1. Locate the credentials and config files. The path depends on your operating system:
# on Linux and macOS ~/.aws/credentials ~/.aws/config # on Windows C:\Users\USERNAME\.aws\credentials C:\Users\USERNAME\.aws\config
  1. Open the files in a text editor and remove the unnecessary profiles. A profile's configuration is split between the credentials and config files in the following way:
[default] aws_access_key_id=YOUR_ACCESS_KEY_ID aws_secret_access_key=YOUR_SECRET_ACCESS_KEY [admin] aws_access_key_id=YOUR_ACCESS_KEY_ID aws_secret_access_key=YOUR_SECRET_ACCESS_KEY
[default] region = us-east-1 output=json [profile admin] region=us-east-1 output=json
  1. Once the unnecessary profiles are deleted from your credentials and config files, save the changes and the profile is removed from your machine.
If your credentials and config files contain a single profile, you can just delete the files to clear your AWS CLI credentials. The next time you run the aws configure command, the AWS CLI will automatically re-create them for you.

Be sure to delete any configuration referencing a profile from both files - credentials and config.

The next time you need to add your AWS CLI credentials, run the aws configure command to either add a profile to the list or re-create the config and credentials files on your machine:

# For the Default profile aws configure # For a profile named admin aws configure --profile admin

The access and secret access keys will be stored in the credentials file, whereas the region and output format will be in the config file.

The two files are located in the same directory.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.