# Manage a member's CLI devices

See the devices a person signs in to the CLI with and their CLI sessions in your organization, block a device here, and end a session.

A member's device keys (Touch ID, a security key, Windows Hello) belong to them and work in every
organization they belong to. As an administrator you act for your organization only: blocking a
device stops it signing in here and ends its CLI sessions here, and it keeps working in the
person's other organizations. Only the member removes a device (see
[End CLI sessions](end-cli-sessions.md)).

An IAM user with console access belongs to your organization alone. Their devices are removed, with
every CLI session they opened, when you set a new password for them, turn their console access off
or delete it, or remove their second factors (see [Manage console access](manage-console-access.md)).

Replace user-id with the person's IAM user id from `dcloud iam users list`, and
key-id and session-id with ids from `dcloud iam users cli-access`.

## Prerequisites

- `iam:ListUserSessions` on the person's IAM user to see their devices and sessions. Without it, the
  **Command line** tab shows **Access denied** and names the action.
- `iam:BlockUserDeviceKey` to block a device, `iam:UnblockUserDeviceKey` to unblock one, and
  `iam:RevokeUserSessions` to end a session, each on the person's IAM user. Without one, its button
  is shown but cannot be chosen.
- In the console, also `iam:GetUser` on the IAM user to open its page (without it the page is not
  found), and `iam:ListUsers` to open **Users**.
- The IAM user is a person: a member, or an IAM user with console access. A service account has no
  CLI devices or sessions: its page has no **Command line** tab, and the API answers 404 `Not found`
  for one. The tab is also missing for a member who was removed from the organization.
- Blocking, unblocking and ending a session are IAM changes. From a CLI session that confirms
  sensitive commands, the CLI asks for a confirmation when your last one is more than five minutes
  old (see [Confirm sensitive CLI commands](confirm-sensitive-cli-commands.md)).

## See a person's devices and sessions

**Console**
1. Open **Identity**, choose **Users**, then choose the person's IAM user.
2. Choose **Command line**.

Under **Devices**, each device is listed with its name, its key type as the device reported it
(**Touch ID**, **Security key**, **Windows Hello** or **Software key**), **Blocked** when your
organization blocked it, when it was enrolled and when it was last used. Under
**Command line sessions in this organization**, each session is listed with the device's name, how
it signed in (**Signed in on this device, confirmed**, **Signed in with the device key (not confirmed)**, **Signed in in the browser with a passkey** or **Signed in in the browser without a passkey**), when it ends and the address it was last used from.

**CLI**
```sh
dcloud iam users cli-access user-id
```

**API**
```http
GET /iam/api/users/user-id/cli
```

The answer lists `deviceKeys`, each with `blocked` saying whether your organization blocked it, and
`sessions`, the person's live CLI sessions in your organization only.

## Block a device in your organization

**Console**
1. On the person's **Command line** tab, choose **Block in this organization** beside the device.
2. Choose **Block device**.

The console says how many sessions were ended, and the device shows **Blocked**.

**CLI**
```sh
dcloud iam users block-device-key user-id key-id
```

**API**
```http
POST /iam/api/users/user-id/cli/device-keys/key-id/block
```

The answer says how many of the device's CLI sessions in your organization were ended
(`sessionsEnded`). From now on, signing in to your organization with that device is refused with
403 and the code `DEVICE_KEY_BLOCKED`
(`An administrator of … blocked this device for the organization. Sign in another way, or ask them to unblock it.`),
and the device cannot confirm sensitive commands here. The person can still sign in to your
organization in the browser, and with the device in their other organizations. The block holds for
that device only: a device the person enrols later is not blocked. Blocking a device that is already
blocked succeeds again. A device that is not one of the person's enrolled devices answers 404
`Not found`.

## Unblock a device

**Console**
1. On the person's **Command line** tab, choose **Unblock** beside the device.

The console says the device can sign in here again.

**CLI**
```sh
dcloud iam users unblock-device-key user-id key-id
```

**API**
```http
DELETE /iam/api/users/user-id/cli/device-keys/key-id/block
```

Sessions the block ended stay ended. A device that is not blocked in your organization answers
404 `Not found`.

## End a session

**Console**
1. On the person's **Command line** tab, under **Command line sessions in this organization**, choose
   **Sign out** beside the session.

The console says **Session ended.**

**CLI**
```sh
dcloud iam users end-cli-session user-id session-id
```

**API**
```http
DELETE /iam/api/users/user-id/cli/sessions/session-id
```

The session stops working at its next request. Its device stays enrolled and unblocked, so the
person can sign in again; on an enrolled device, the CLI asks for its prompt itself when the next
command runs in a terminal. A session that is not one of the person's live CLI
sessions in your organization, an ended one included, answers 404 `Not found`.

## Related

- [Manage members](manage-members.md): signing a member out everywhere also blocks every device of
  theirs in your organization.
- [End CLI sessions](end-cli-sessions.md)
- [Require Touch ID or a passkey for the CLI](require-touch-id-for-the-cli.md)
- `iam.users.cli-access` · `dcloud iam users block-device-key`
