Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Set up MFA for CloudHSM CLI

Focus mode
Set up MFA for CloudHSM CLI - AWS CloudHSM

Follow these steps to set up multi-factor authentication (MFA) for CloudHSM CLI.

  1. To setup MFA using the Token Sign Strategy you must first generate a 2048 bit RSA private key and associated public key.

    $ openssl genrsa -out officer1.key 2048 Generating RSA private key, 2048 bit long modulus (2 primes) ...........................................................+++++ ....................................................................+++++ e is 65537 (0x010001) $ openssl rsa -in officer1.key -outform PEM -pubout -out officer1.pub writing RSA key
  2. Using the CloudHSM CLI, login to your user account.

    $ cloudhsm-cli interactive aws-cloudhsm > login --username admin --role admin --cluster-id <cluster ID> Enter password: { "error_code": 0, "data": { "username": "admin", "role": "admin" } }
  3. Next, execute the command to change you MFA strategy. You must provide the parameter --token. This parameter specifies a file that will have unsigned tokens written to it.

    aws-cloudhsm > user change-mfa token-sign --token unsigned-tokens.json --username <USERNAME> --role crypto-user --change-quorum Enter password: Confirm password:
  4. You now have a file with unsigned tokens that need to be signed: unsigned-tokens.json. The number of tokens in this file depends on the number of HSMs in your cluster. Each token represents one HSM. This file is JSON formatted and contains tokens that need to be signed to prove you have a private key.

    $ cat unsigned-tokens.json { "version": "2.0", "tokens": [ { { "unsigned": "Vtf/9QOFY45v/E1osvpEMr59JsnP/hLDm4ItOO2vqL8=", "signed": "" }, { "unsigned": "wVbC0/5IKwjyZK2NBpdFLyI7BiayZ24YcdUdlcxLwZ4=", "signed": "" }, { "unsigned": "z6aW9RzErJBL5KqFG5h8lhTVt9oLbxppjod0Ebysydw=", "signed": "" } ] }
  5. The next step is to sign these tokens with the private key created in step 1. Place the signatures back in the file. First, you have to extract and decode the base64 encoded tokens.

    $ echo "Vtf/9QOFY45v/E1osvpEMr59JsnP/hLDm4ItOO2vqL8=" > token1.b64 $ echo "wVbC0/5IKwjyZK2NBpdFLyI7BiayZ24YcdUdlcxLwZ4=" > token2.b64 $ echo "z6aW9RzErJBL5KqFG5h8lhTVt9oLbxppjod0Ebysydw=" > token3.b64 $ base64 -d token1.b64 > token1.bin $ base64 -d token2.b64 > token2.bin $ base64 -d token3.b64 > token3.bin
  6. Now, you have binary tokens that you can sign using the RSA private key created in step 1.

    $ openssl pkeyutl -sign \ -inkey officer1.key \ -pkeyopt digest:sha256 \ -keyform PEM \ -in token1.bin \ -out token1.sig.bin $ openssl pkeyutl -sign \ -inkey officer1.key \ -pkeyopt digest:sha256 \ -keyform PEM \ -in token2.bin \ -out token2.sig.bin $ openssl pkeyutl -sign \ -inkey officer1.key \ -pkeyopt digest:sha256 \ -keyform PEM \ -in token3.bin \ -out token3.sig.bin
  7. Now, you have binary signatures of the tokens. You must encode them using base64, and then place them back in your token file.

    $ base64 -w0 token1.sig.bin > token1.sig.b64 $ base64 -w0 token2.sig.bin > token2.sig.b64 $ base64 -w0 token3.sig.bin > token3.sig.b64
  8. Finally, you can copy and paste the base64 values back into your token file:

    { "version": "2.0", "tokens": [ { "unsigned": "1jqwxb9bJOUUQLiNb7mxXS1uBJsEXh0B9nj05BqnPsE=", "signed": "eiw3fZeCKIY50C4zPeg9Rt90M1Qlq3WlJh6Yw7xXm4nF6e9ETLE39+9M+rUqDWMRZjaBfaMbg5d9yDkz5p13U7ch2tlF9LoYabsWutkT014KRq/rcYMvFsU9n/Ey/TK0PVaxLN42X+pebV4juwMhN4mK4CzdFAJgM+UGBOj4yB9recpOBB9K8QFSpJZALSEdDgUc/mS1eDq3rU0int6+4NKuLQjpR+LSEIWRZ6g6+MND2vXGskxHjadCQ09L7Tz8VcWjKDbxJcBiGKvkqyozl9zrGo8fA3WHBmwiAgS61Merx77ZGY4PFR37+j/YMSC14prCN15DtMRv2xA1SGSb4w==" }, { "unsigned": "LMMFc34ASPnvNPFzBbMbr9FProS/Zu2P8zF/xzk5hVQ=", "signed": "HBImKnHmw+6R2TpFEpfiAg4+hu2pFNwn43ClhKPkn2higbEhUD0JVi+4MerSyvU/NN79iWVxDvJ9Ito+jpiRQjTfTGEoIteyuAr1v/Bzh+HjmrO53OQpZaJ/VXGIgApD0myuu/ZGNKQTCSkkL7+V81FG7yR1Nm22jUeGa735zvm/E+cenvZdy0VVx6A7WeWrl3JEKKBweHbi+7BwbaW+PTdCuIRd4Ug76Sy+cFhsvcG1k7cMwDh8MgXzIZ2m1f/hdy2j8qAxORTLlmwyUOYvPYOvUhc+s83hx36QpGwGcD7RA0bPT5OrTx7PHd0N1CL+Wwy91We8yIOFBS6nxo1R7w==" }, { "unsigned": "dzeHbwhiVXQqcUGj563z51/7sLUdxjL93SbOUyZRjH8=", "signed": "VgQPvrTsvGljVBFxHnswduq16x8ZrnxfcYVYGf/N7gEzI4At3GDs2EVZWTRdvS0uGHdkFYp1apHgJZ7PDVmGcTkIXVD2lFYppcgNlSzkYlftr5EOjqS9ZjYEqgGuB4g//MxaBaRbJai/6BlcE92NIdBusTtreIm3yTpjIXNAVoeRSnkfuw7wZcL96QoklNb1WUuSHw+psUyeIVtIwFMHEfFoRC0t+VhmnlnFnkjGPb9W3Aprw2dRRvFM3R2ZTDvMCiOYDzUCd43GftGq2LfxH3qSD51oFHglHQVOY0jyVzzlAvub5HQdtOQdErIeO0/9dGx5yot07o3xaGl5yQRhwA==" } ] }
  9. Now that your token file has all the required signatures, you can proceed. Enter the name of the file containing the signed tokens and press the enter key. Finally, enter the path of your public key.

    Enter signed token file path (press enter if same as the unsigned token file): Enter public key PEM file path:officer1.pub { "error_code": 0, "data": { "username": "<USERNAME>", "role": "crypto-user" } }

    Now you have setup your user with MFA.

    { "username": "<USERNAME>", "role": "crypto-user", "locked": "false", "mfa": [ { "strategy": "token-sign", "status": "enabled" } ], "cluster-coverage": "full" },
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.