# Create an IAM user

Create an IAM user for someone who signs in with a user name, or a service account for a program.

People who sign in with their own email address get an IAM user when they join; invite them
instead (see [Invite a person](invite-a-person.md)). Create one yourself for a program, a CI job, or
someone who signs in with a user name your organization gives them. Replace alice with the
user name.

## Prerequisites

- Permission for `iam:CreateUser`.
- For the console, also `iam:ListUsers` to open **Users**, and `iam:GetUser` for the user's page
  that opens afterwards (it answers 404 without it).

## Create the user

**Console**
1. Open **Identity**, then choose **Users**.
2. Choose **Create user**.
3. For **Username**, enter alice: lower-case letters, digits, hyphens and underscores, up to
   64 characters.
4. (Optional) For **Display name**, enter the name shown in lists.
5. For **Type**, choose **User** (the default) or **Service account**.
6. Choose **Create user**. The user's page opens.

**CLI**
```sh
dcloud iam users create --username alice --display-name "Alice Example"
```

**API**
```http
POST /iam/api/users
{ "username": "alice", "type": "user" }
```

**Terraform**
```hcl
resource "dcloud_iam_user" "alice" {
  username = "alice"
  type     = "user"
}
```

## Result

The user exists and holds no permissions. Give it some by attaching a policy, adding it to a group
or assigning it a role; see [Attach a policy](attach-a-policy.md).

| Type                | How it signs in                                                                                                                      |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| **User**            | With an access key, and to the console once you give it a password; see [Give a user console access](give-a-user-console-access.md). |
| **Service account** | With an access key only; see [Create an access key](create-an-access-key.md).                                                        |

The type cannot be changed later. The user name is what the user is called in the audit log and at
the console sign-in. A policy names the user by its id:
`rn:ews::org-EXAMPLE1234:iam:user/user-id`.

## If the user is refused

- 409 `An IAM user called "alice" already exists in this organization.`
- 409 `Quota exceeded: …` when the organization has as many IAM users as its quota allows; see
  [Quotas](quotas.md).
- 400 when the user name breaks the rules above.

## Related

- [Delete an IAM user](delete-an-iam-user.md)
- [Principals and policies](principals-and-policies.md)
- `iam.users.create` · `dcloud iam users create` · `dcloud_iam_user`
