extracting aws access key and secret key from file

AWS/AWS Command Line Interface

  • outline

extracting AWS Access key or Secret key from file or credentials file.

  • extracting access key
cat ~/.aws/credentials | grep aws_access_key_id | awk '{print $3}'
cat ~/.aws/credentials | grep aws_access_key_id | awk -F = '{print $2}' | tr -d ' '
grep -RP '(?<![A-Z0-9])[A-Z0-9]{20}(?![A-Z0-9])' ~/.aws/credentials  | awk '{print $3}'
  • extracting secret key
cat ~/.aws/credentials | grep aws_secret_access_key | awk '{print $3}'
cat ~/.aws/credentials | grep aws_secret_access_key | awk -F = '{print $2}' | tr -d ' '
grep -RP '(?<![A-Za-z0-9/+=])[A-Za-z0-9/+=]{40}(?![A-Za-z0-9/+=])' ~/.aws/credentials | awk '{print $3}'
  • reference

https://aws.amazon.com/blogs/security/a-safer-way-to-distribute-aws-credentials-to-ec2/