113

I have deleted the AWS credentials in sudo nano ~/.aws/config. But, the credentials are still in aws configure. Is there a way to reset aws configure with clear state?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
ultraInstinct
  • 4,063
  • 10
  • 36
  • 53

7 Answers7

152

just remove ~/.aws/credentials along with ~/.aws/config

EDIT: Note path references user home directory and specific to each user in system.

Steven K7FAQ
  • 798
  • 1
  • 9
  • 17
pavan
  • 1,825
  • 1
  • 11
  • 10
127

Do not delete the files if you have multiple profiles created as all will be lost if you delete these files! unless thats what you want :)

Go to each of the file -

 - ~/.aws/credentials
 - ~/.aws/config

and remove just the part profiles you want to delete. Eg.

~/.aws/credentials

[default]
aws_access_key_id=yourAccessKeyId
aws_secret_access_key=yourSecretAccessKey

[user2]
aws_access_key_id=yourAccessKeyId
aws_secret_access_key=yourSecretAccessKey

and

~/.aws/config

[default]
region=us-west-2
output=json

[profile user2]
region=us-east-1
output=text

Just delete entries corresponding to user2 profile if thats what you want. And you should also give a profile name to profile you configure -

aws configure --profile user2

Else it will just be [default]

More details - http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
  • Thanks @Steven for pointing it out but it was a typo as you can see the path used elsewhere corresponds to users home dir only. – Aniket Thakur Dec 28 '17 at 04:03
  • 12
    This answer is more appropriate than the one that is accepted. – Shazic Dec 19 '18 at 03:17
  • 3
    In Windows it is also helpful to note that credentials can be stored in the locations above, but can also be stored in `~\AppData\Local\AWSToolkit\RegisteredAccounts.json` as defined here: https://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html#specifying-your-aws-credentials-store – Randall Borck Jun 17 '19 at 21:54
  • @RandallBorck just a note of thanks for this - developed scripts on my Mac and couldn't figure out why on Windows when I removed the profiles the scripts were still working .. ! – suitedupgeek Jun 23 '19 at 10:57
  • @AniketThakur Sir any command for cmd to delete specific profile or user ? – Ankit gupta Nov 01 '21 at 12:25
  • You can't delete credentials or profile with the `aws` command but you can overwrite them with invalid data eg `aws configure set --profile user2 aws_access_key_id=DELETED` – JamesP Jun 16 '23 at 14:01
5

Here is the graphical presentation for mac user Graphical

Kirtikumar A.
  • 4,140
  • 43
  • 43
3

For windows users just open aws credentials file and update based on your requirements.

File is located in C:> Users > yourusername > .aws - credentials

Aamer
  • 417
  • 3
  • 9
0

Not sure if this clears the credentials but I was able to simply change the credentials by running aws configure again and entering in new credentials. I was also able to make multiple profiles by running aws configure --newusername and I could run a future command with that user by appending --profile newusername. Good tutorial here: https://www.crybit.com/configure-iam-user-on-your-linux-machine/

Jeffrey Kozik
  • 201
  • 4
  • 8
0

Maybe just a Windows thing but if you edit the ~.\aws\config and ~.\aws\credentials files like is suggested by Aniket Thakur, you might run into an issue where aws configure complains about a profile you deleted not being available. This seems to be because the AWS_PROFILE environment variable is referencing that profile. Unset that variable and you should be back in business.

Tried to comment under his answer but I don't have enough points (on this account).

dbrouwer2
  • 31
  • 2
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31692320) – Dan May 09 '22 at 19:33
0

Instead of deleting from disk, you can override them with env vars like so:

export AWS_ACCESS_KEY_ID=''
export AWS_SECRET_ACCESS_KEY=''

or in the shell:

unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817