LinuxUnity LinuxUnity

Posts / AWS Fundamentals & Core Infrastructure

AWS IAM: Create IAM Users, Groups, and Configure the CLI from A to Z

Learn how to secure the AWS root user with MFA, create IAM users and groups with appropriate permissions, and install and configure AWS CLI v2.

02/04/2026 5 min read 9 views

Z Zedx

AWS
In this article

Objectives

After this lab, you will have:

  • An AWS Account secured with MFA on the Root User
  • AWS CLI v2 installed and configured to work
  • A dedicated IAM user with the appropriate permissions (do not use Root anymore)
  • An IAM Group with the policy properly attached

Requirements

  • An email address not previously used to register for AWS (or an existing account)
  • A credit/debit card (AWS Free Tier — this lab incurs no charges)
  • A terminal (macOS/Linux) or PowerShell (Windows)

Secure the Root User with MFA

This is a mandatory step to do immediately after creating the account:

  1. Log in to console.aws.amazon.com
  2. Click the account name (top right) → Security credentials
  3. Section Multi-factor authentication (MFA) → Assign MFA device
  4. Select Authenticator app (use Google Authenticator or Authy)
  5. Scan the QR code → Enter two consecutive codes → Add MFA

Check: Sign out and sign in to the console again; it will require the MFA code. ✅

Create an IAM Admin User

From now on, use this IAM user instead of the Root user:

In the console:

creat user

info user

  1. Search for IAM in the console → Users → Create user
  2. Username: admin-yourname (for example: admin-john)
  3. Check Provide user access to the AWS Management Console
  4. Custom password — select “Autogenerated password“: AWS automatically generates a random password and sends the password to you after creation. You can enter a password yourself by selecting “Custom password“
  5. Users must create a new password at next sign-in: The user will be required to change their password at the next sign-in after the account is created.
  6. Next ??? Add user to group
  7. Create group ??? Group name: Administrators
  8. Find and select a policy: AdministratorAccess ??? Create user group
  9. Add user to group Administrators ??? Next ??? Create user
  10. Download .csv or record the Console sign-in URL, username, and password

Enable MFA for the IAM user:

  1. Click the user you just created Security credentials
  2. Assign MFA device Repeat the process as Root

Install and configure the AWS CLI

Linux:

text

text
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version

Windows (PowerShell):

text

text
# Download từ: https://awscli.amazonaws.com/AWSCLIV2.msi
# Chạy installer, sau đó:
aws --version

Create an Access Key for an IAM User

access key

  1. Sign in with IAM user just created (use the Console sign-in URL from step 3)
  2. Click the user name (top right) → Security credentials
  3. Access keys → Create access key
  4. Use case: Command Line Interface (CLI)
  5. Check the confirmation box → Next → Create access key
  6. Download .csv Save it securely, The Secret Key is displayed only once!

Configure AWS CLI

text
#
text
# Cấu hình profile mặc định
aws configure

# Nhập thông tin:
# AWS Access Key ID: <Access Key ID từ bước 5>
# AWS Secret Access Key: <Secret Access Key từ bước 5>
# Default region name: ap-southeast-1  (hoặc region gần bạn nhất)
# Default output format: json

# Kiểm tra cấu hình
aws sts get-caller-identity

Expected result:

If you see the output shown above in the CLI, the connection was successful! ✅

text

text
{
    "UserId": "AIDARA4XYMAICN36K2MWF",
    "Account": "070648356880",
    "Arn": "arn:aws:iam::070648356880:user/admin-lu"
}

Create a Second IAM User Using the CLI (Hands-On)

Create a standard IAM user (not an administrator) using the CLI:

text

text
GROUP="Developers"
USER="developer-01"
POLICY="DeveloperPolicy"
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
POLICY_ARN="arn:aws:iam::${ACCOUNT_ID}:policy/${POLICY}"

## 1. Tạo Group
aws iam create-group --group-name $GROUP

## 2. Tạo Policy (S3 + DynamoDB + Lambda)
cat > developer-policy.json << 'EOF'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:GetObject","s3:ListBucket","s3:PutObject"],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": ["dynamodb:GetItem","dynamodb:PutItem","dynamodb:Query","dynamodb:Scan"],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": ["lambda:InvokeFunction","lambda:GetFunction","lambda:ListFunctions"],
      "Resource": "*"
    }
  ]
}
EOF

aws iam create-policy \
  --policy-name $POLICY \
  --policy-document file://developer-policy.json \
  --description "Policy cho Developer team"

## 3. Gán Policy → Group
aws iam attach-group-policy \
  --group-name $GROUP \
  --policy-arn $POLICY_ARN

## 4. Tạo User → thêm vào Group → tạo password
aws iam create-user --user-name $USER
aws iam add-user-to-group --user-name $USER --group-name $GROUP
aws iam create-login-profile \
  --user-name $USER \
  --password "TempPass123!" \
  --password-reset-required

## 5. Kiểm tra kết quá
aws iam get-user --user-name $USER
aws iam list-groups-for-user --user-name $USER
aws iam list-attached-group-policies --group-name $GROUP

Result:

  • When logging in to the AWS Console for the first time with the user developer-01, the system will require you to change the password before continuing. This is the effect of the flag --password-reset-required when running the command create-login-profile. This is a security best practice to prevent temporary passwords from remaining active for too long. At this point, creating the IAM user via the CLI is complete.

Test whether the policy is working correctly using IAM Policy Simulator:

aws sts get-caller-identity

text

text
# Kiểm tra permission cụ thể bằng CLI
aws iam simulate-principal-policy \
    --policy-source-arn "arn:aws:iam::${ACCOUNT_ID}:user/developer-01" \
    --action-names "s3:GetObject" "ec2:DescribeInstances" \
    --resource-arns "arn:aws:s3:::*"
  • s3:GetObject ??? allowed ✅
  • ec2:DescribeInstances ??? implicitDeny ✅ (not included in the policy)

Summary

Through this lab, you have set up a properly secured AWS environment from the outset:

  • Root user protected by MFA and not used directly for day-to-day work
  • IAM Admin user separate from AdministratorAccess the Root user, protected by MFA and used instead of Root from now on
  • AWS CLI configured and successfully authenticated using an Access Key
  • IAM Group + Policy created correctly: permissions are attached to the group rather than directly to the user
  • Standard IAM User (developer-01) with exactly the permissions required: no more, no less

Find more useful articles about AWS