How to Clear your AWS CLI Credentials

This short article will guide you through finding and clearing your AWS CLI credentials in simple steps.

What are AWS CLI Credentials?

As a quick reminder, in case you stumbled upon this article with no context, AWS CLI credentials are the access keys that allow you to interact with Amazon Web Services (AWS) directly from your command line. They are crucial for performing various AWS tasks and should be handled carefully.

Step-by-Step Guide

  1. Open the Terminal: Start by opening your command line terminal.

  2. Navigate to the AWS Directory:

    • For Windows users, the AWS CLI credentials are usually stored in C:\Users\[Your User Name]\.aws.
    • For Mac and Linux users, the path is typically ~/.aws.
  3. Locate the Credentials File:

    • Inside the .aws directory, you'll find a credentials file.
    • This file contains your access keys.
  4. Edit or Delete the Credentials File:

    • You can open the file in a text editor and manually remove the credentials.
    • Or, delete the file if you want to remove all the stored credentials completely.
    • Caution: Deleting this file will remove all stored credentials, so ensure you have backups if needed.

Note: There is also a file called config (~/.aws/config) that you might want to look into and see if you need to delete any data inside this. It doesn't include information that is as sensitive, but if you're doing a complete cleanup, this might be worth looking at too.

Alternative Method - Using AWS CLI Commands

  • You can also use the AWS CLI to remove specific credentials with the command:
    aws configure --profile [profile-name] set aws_access_key_id ""
    aws configure --profile [profile-name] set aws_secret_access_key ""
    
  • Replace [profile-name] with your profile name.

Verify the Changes

  • Try running an AWS CLI command to ensure your credentials have been cleared.
  • If the credentials are cleared, you'll receive an error stating that AWS could not locate credentials.

Why Clear AWS CLI Credentials?

There are several reasons why you might need to clear your AWS CLI credentials:

  • Security: To prevent unauthorized access to your AWS resources. It is very useful to know if you are on a machine that is not your own.
  • Account Switching: When switching between different AWS accounts.
  • Troubleshooting: Sometimes clearing credentials and resetting things can help when switching between too many configurations.

Always handle AWS credentials carefully and clear them when they are no longer necessary.

Happy coding! 🔨

SecurityAws
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses: Lead Developer, Software Architect, Product Manager, CTO, and now happily a Founder.

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.