DevOps by Default Blog

Change IAM password from the CLI

Sometimes it’s handy to be able to quickly change the password of an existing IAM user without having to login at the AWS Console to do it. I generally set a long random password using a tool called apg, although I’ve found that AWS don’t like certain characters so I’ve added a few exclusions with the -E option.

First, make sure you have the awscli installed, then:

aws iam update-login-profile --user-name $IAM_USERNAME --password-reset-required \
  --password $(apg -n1 -MSNCL -E\`\'\*\?\"\&\;\\\:\{\}\,\.\~\|\/\< -m24 | tee /dev/stderr)

In the command above replace $IAM_USER with the actual user you wish to change the password for. The new password will be echoed to your terminal, but you could pipe it the clipboard with | xclip -sel clip rather than display it onscreen if you prefer.