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
posta 10 mesi fa350 visualizzazioni
3 Risposte
1
Risposta accettata

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
con risposta 10 mesi fa
profile picture
ESPERTO
verificato 10 mesi fa
profile picture
ESPERTO
verificato 10 mesi fa
  • 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.

con risposta 10 mesi fa
  • 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
con risposta 10 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande