Delete IAM users and key access from cli

0

Good morning, I deleted an IAM user with its security keys and the group it belongs to, and I recreated another one but from the cli when I run the "aws configure" command I always get the access keys of the old IAM user. Why? how can i choose from cli which iam user to select if i have more than one iam user?

Dario
asked a year ago414 views
3 Answers
2
Accepted Answer

The AWS CLI stores the access keys and other configuration settings in a configuration file. By default, this file is located at "~/.aws/credentials" on Linux, macOS, or Unix-based systems, and "C:\Users<username>.aws\credentials" on Windows.

To resolve the issue and ensure you are using the access keys of the newly created IAM user, you can do the following:

Open the AWS CLI configuration file in a text editor. Locate the file "~/.aws/credentials" (or the appropriate file path based on your operating system). Look for the section in the file corresponding to the old IAM user that you deleted. It will have a format like:

[profile_name] aws_access_key_id = YOUR_ACCESS_KEY aws_secret_access_key = YOUR_SECRET_KEY

Delete the section for the old IAM user from the configuration file. Save the changes to the configuration file and close the editor.

Now, when you run the "aws configure" command, it should prompt you to enter the access keys for the new IAM user. Provide the new access keys, and the AWS CLI will use them for subsequent operations.

If you have multiple profiles configured in your AWS CLI, you can also specify the profile explicitly using the "--profile" flag when running AWS CLI commands. For example:

aws s3 ls --profile new_profile

profile picture
answered a year ago
profile picture
EXPERT
reviewed 18 days ago
profile picture
EXPERT
reviewed a year ago
profile picture
EXPERT
reviewed a year ago
  • Wow Mate thanks!! I'm new and I study about AWS solution architect in these days. You help me to solve a great problem. I have another question: how can i choose from cli which iam user to select if i have more than one iam user?

0

Follow below simple steps to reconfigure your AWS credentials.

step1: Delete existing AWS credentials $ sudo nano ~/.aws/credentials step2: Reconfiute AWS credentials. aws configure It should prompt you to enter new access keys for the IAM user.

answered a year ago
  • how can i choose from cli which iam user to select if i have more than one iam user?

0

If you have multiple IAM users and frequently switch between them, you can create separate AWS CLI profiles for each IAM user. This approach allows you to easily switch between different IAM users each time. You can define profiles in the AWS CLI configuration file.

To create a profile for each IAM user:

Open or create the AWS CLI configuration file located at ~/.aws/config (Unix/Linux) or %USERPROFILE%.aws\config (Windows). Add a new profile for each IAM user using the following syntax:

[profile profile_name] region = us-west-2 aws_access_key_id = <ACCESS_KEY> aws_secret_access_key = <SECRET_KEY>

Replace profile_name, <ACCESS_KEY>, and <SECRET_KEY> with the appropriate values for each IAM user. Save the configuration file.

Now, you can specify the desired profile when executing AWS CLI commands using the --profile option. For example:

aws s3 ls --profile profile_name

Replace profile_name with the name of the **desired profile ** you defined in the AWS CLI configuration file.

profile picture
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions