# End CLI sessions

See your CLI sessions, end one or all of them, and remove a lost or retired device's key.

A CLI session ends by itself 12 hours after sign-in. End it sooner when you are done on a machine,
and remove a device's key when the device is lost or no longer yours: removing the key ends every
session it opened, and the device can no longer sign in with it.

## Prerequisites

- A console session or a CLI session of your own. No IAM action is needed for your own sessions
  and devices. An access key has no CLI sessions: 403 `Only a person has CLI sessions`.

## End sessions

**Console**
1. Open [My account](/account) and go to **Command line sign-in**. Each session is listed with the
   device's name, how it signed in (**Signed in on this device, confirmed** for a device key that verified you, **Signed in with the device key (not confirmed)** for one that did not, **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.
2. Choose **End** beside a session. With more than one session, **Sign out of every CLI** ends them
   all.

The console says **Session ended.**, or how many sessions were ended.

**CLI**
```sh
dcloud auth sessions           # your CLI sessions; * marks this one
dcloud auth logout             # end this session and forget this profile; the device stays enrolled
dcloud auth logout --all       # end every CLI session of yours
```

The list holds your sessions in every organization you belong to, and **Sign out of every CLI** and
`--all` end them all. Ending a session never removes a device key: the next `dcloud login` on an
enrolled device is its prompt again.

## Remove a device

**Console**
1. Open [My account](/account) and go to **Command line sign-in**. Each enrolled device is listed
   with **Touch ID**, **Security key**, **Windows Hello** or **Software key** (the key type as the
   device reported it), when it was enrolled and when it was last used.
2. Choose **Remove** beside the device, then **Remove device** to confirm.

The device's key stops working, and every CLI session it opened ends now.

**CLI**
On the device itself:

```sh
dcloud auth logout --forget-device
```

While the profile's session is still running, this removes the device's key on the server, ends
the session, and forgets the key on the device. When the session has already ended, it only
forgets the key on the device, and the key stays enrolled: remove it in the console.

## Other ways sessions end

- **Sign out all other sessions** under **Sessions** on [My account](/account) ends every CLI
  session too; your devices stay enrolled (see [Manage your sessions](manage-your-sessions.md)).
- A changed password and a password reset end every CLI session and also remove every device key.
  For an IAM user with console access, so does an administrator turning that console access off,
  deleting it, or removing its second factors.
- An administrator of an organization can end one of your CLI sessions there, block one of your
  devices there, or sign you out (with `iam:RevokeUserSessions`), which ends your CLI sessions in
  that organization and blocks every device of yours there. A blocked device still signs in to your
  other organizations (see [Manage a member's CLI devices](manage-a-members-cli-devices.md)).
- A session stops working as soon as you are no longer an active member of its organization, or
  your IAM user is no longer active: its next request is refused with 403.

`dcloud auth logout <profile>` of a profile that holds an access key only deletes the key from this
machine; it still works until it expires. To stop it working, deactivate or delete it (see
[Manage access keys](manage-access-keys.md)).

## Related

- [Sign in the CLI](sign-in-the-cli.md)
- [Manage your sessions](manage-your-sessions.md)
- [Manage a member's CLI devices](manage-a-members-cli-devices.md)
- [Manage access keys](manage-access-keys.md)
