如何将 MFA 与 AWS CLI 结合使用?

如何将 MFA 与 AWS CLI 结合使用?

问题描述:

在使用 AWS CLI 时如何输入 MFA 代码?我检查了 IAM 的文档页面 http://docs.aws.amazon.com/cli/latest/reference/iam/index.html.

How do I type in the MFA code when using the AWS CLI? I have checked the documentation page of IAM http://docs.aws.amazon.com/cli/latest/reference/iam/index.html.

我已经在我的用户名下启用了 MFA 设备.

I have the MFA-Devices already enabled under my username.

aws iam list-mfa-devices --user-name X

返回

{
"MFADevices": [
    {
        "UserName": "X", 
        "SerialNumber": "arn:aws:iam::+++:mfa/X", 
        "EnableDate": "2016-01-13T23:15:43Z"
    }
]
}

调用 aws sts get-session-token --serial-number --token-code 记录在 此处.这将为您提供一个临时安全令牌.可以在此处找到有关使用临时安全令牌的文档.

Call aws sts get-session-token --serial-number <serial> --token-code <code> documented here. This will give you a temporary security token. Documentation on using the temporary security token can be found here.