[Yandex Cloud documentation](../../../index.md) > [Yandex Identity and Access Management](../../index.md) > [Step-by-step guides](../index.md) > Service accounts > Deleting a service account

# Deleting a service account

{% note warning %}

Deleting a [service account](../../concepts/users/service-accounts.md) is permanent. You cannot restore a deleted service account; you can only [re-create it](create.md).

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), click ![image](../../../_assets/console-icons/layout-side-content-left.svg) or ![image](../../../_assets/console-icons/chevron-down.svg) in the top panel and select the [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder).
  1. In the left-hand panel, click ![image](../../../_assets/console-icons/dots-9.svg) and select **Identity and Access Management**.
  1. In the left-hand panel, select ![FaceRobot](../../../_assets/console-icons/face-robot.svg) **Service accounts**.
  1. In the row with the service account you need, click ![image](../../../_assets/console-icons/ellipsis.svg) and select **Delete**.
  1. In the window that opens, click **Delete**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. See the description of the delete service account command:

      ```bash
      yc iam service-account delete --help
      ```

  1. Select a service account, e.g., `my-robot`:

      ```bash
      yc iam service-account list
      ```

      Result:

      ```text
      +----------------------+------------------+-------------------------------+
      |          ID          |       NAME       |          DESCRIPTION          |
      +----------------------+------------------+-------------------------------+
      | aje6o61dvog2******** | my-robot         |                               |
      | aje9sda1ufvq******** | account_name     | account_description           |
      +----------------------+------------------+-------------------------------+
      ```

  1. Delete the service account:

      ```bash
      yc iam service-account delete my-robot
      ```

- Terraform {#tf}

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../../terraform/authentication.md) using the appropriate method.

  To delete a service account:

  1. Open the Terraform configuration file and delete the fragment with the service account description.
     Example of the service account description in the Terraform configuration:

     ```hcl
     ...
     resource "yandex_iam_service_account" "sa" {
       name        = "my-robot"
       description = "this is my favorite service account"
      }
     ...
     ```

  1. In the command line, go to the directory with the Terraform configuration file.
  
  1. Check the configuration using this command:
     ```bash
     terraform validate
     ```
     
     If the configuration is correct, you will get this message:
     
     ```text
     Success! The configuration is valid.
     ```

  1. Run this command:
     ```bash
     terraform plan
     ```
  
     The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.

  1. Apply the configuration changes:
     ```bash
     terraform apply
     ```
     
  1. Confirm the changes: type `yes` into the terminal and press **Enter**.

     You can check the deletion of the service account using the [management console](https://console.yandex.cloud) or this [CLI](../../../cli/quickstart.md) command:

     ```bash
     yc iam service-account list
     ```

- API {#api}

  To delete a service account, use the [delete](../../api-ref/ServiceAccount/delete.md) REST API method for the [ServiceAccount](../../api-ref/ServiceAccount/index.md) resource or the [ServiceAccountService/Delete](../../api-ref/grpc/ServiceAccount/delete.md) gRPC API call.

{% endlist %}

You cannot delete a service account while it is linked to some cloud [resources](../../../overview/roles-and-resources.md#resources). First, update the service account in the resource's settings or delete the resource and then delete the service account. For example, if your service account is linked to a VM, first [delete](../../../compute/operations/vm-control/vm-delete.md) the VM and then delete the service account.