[Yandex Cloud documentation](../../index.md) > [Yandex Virtual Private Cloud](../index.md) > [Step-by-step guides](index.md) > Security groups > Moving a security group between folders

# Moving a security group to a different folder

{% list tabs group=instructions %}

- Management console {#console}

  To move a [security group](../concepts/security-groups.md) to a different folder:

  1. In the [management console](https://console.yandex.cloud), select the folder containing the security group.
  1. Navigate to **Virtual Private Cloud**.
  1. In the left-hand panel, select ![image](../../_assets/console-icons/shield.svg) **Security groups**.
  1. Click ![image](../../_assets/console-icons/ellipsis.svg) in the row of the security group you need to move and select **Move**.
  1. Select the destination folder from the drop-down list.
  1. Click **Move**.

- 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.

  To move a [security group](../concepts/security-groups.md) to a different folder:

  1. View the description of the CLI command for moving a security group:

      ```bash
      yc vpc security-group move --help
      ```

  1. Get the name or ID of the security group to move:

      ```bash
      yc vpc security-group list
      ```

      Result:

      ```text
      +----------------------+---------------------------------+------------------------------------+----------------------+
      |          ID          |              NAME               |          DESCRIPTION               |      NETWORK-ID      |
      +----------------------+---------------------------------+------------------------------------+----------------------+
      | enc2ta63h3q2******** | default-sg-enc39op1vq9m******** | Default security group for network | enc39op1vq9m******** |
      | enc612keceq8******** | default-sg-encb4ubvmief******** | Default security group for network | encb4ubvmief******** |
      | encnn4l7b3lp******** | default-sg-enc772aa2rgq******** | Default security group for network | enc772aa2rgq******** |
      | encemkpqg8fh******** | my-sg-1                         | Custom security group              | encb4ubvmief******** |
      +----------------------+---------------------------------+------------------------------------+----------------------+
      ```

  1. Get a list of available folders:

      ```bash
      yc resource-manager folder list
      ```

      Result:

      ```text
      +----------------------+------------------------+--------+--------+
      |          ID          |          NAME          | LABELS | STATUS |
      +----------------------+------------------------+--------+--------+
      | b1cs8ie21pk1******** | default                |        | ACTIVE |
      | b1chgf288nvg******** | my-folder-1            |        | ACTIVE |
      | b1cu6g9ielh6******** | my-folder-2            |        | ACTIVE |
      +----------------------+------------------------+--------+--------+
      ```

  1. Move the security group by specifying the name or ID of the group and destination folder:

     ```bash
     yc vpc security-group move <group_name_or_ID> \
       --destination-folder-name <destination_folder_name> \
       --destination-folder-id <destination_folder_ID>
     ```

     Use either `--destination-folder-name` or `--destination-folder-id`.

     If the security group is not in the current folder (default folder), specify the source folder using `--folder-name` or `--folder-id`.

     Result:

     ```text
     id: encemkpqg8fh********
     folder_id: b1chgf288nvg********
     created_at: "2022-10-10T13:24:59Z"
     name: my-sg-1
     network_id: encb4ubvmief********
     status: ACTIVE
     ```

     For more information about the `yc vpc security-group move` command, see the [CLI reference](../../cli/cli-ref/vpc/cli-ref/security-group/move.md).

- API {#api}

  To move a [security group](../concepts/security-groups.md) to a different folder, use the [move](../api-ref/SecurityGroup/move.md) REST API method for the [SecurityGroup](../api-ref/SecurityGroup/index.md) resource or the [SecurityGroupService/Move](../api-ref/grpc/SecurityGroup/move.md) gRPC API call, and provide the following in the request:

  * ID of the security group you need to move, in the `securityGroupId` parameter.

    To get the subnet ID, use the [list](../api-ref/Subnet/list.md) REST API method for the [Subnet](../api-ref/Subnet/index.md) resource or the [SubnetService/List](../api-ref/grpc/Subnet/list.md) gRPC API call and provide the folder ID in the `folderId` request parameter.

  * ID of the folder you want to move the security group to, in the `destinationFolderId` parameter.

    To learn how to find out the folder ID, see [Getting the folder ID](../../resource-manager/operations/folder/get-id.md).

{% endlist %}

## Examples {#examples}

### Security group in the current folder {#from-default-folder}

Move a security group from the current folder by specifying the group name and destination folder name:

{% list tabs group=instructions %}

- CLI {#cli}

  ```bash
  yc vpc security-group move my-sg-1 \
    --destination-folder-name my-folder-1
  ```

{% endlist %}

### Security group in a different folder {#from-another-folder}

Move a security group from a different folder. Specify the group ID and the source and destination folder IDs:

{% list tabs group=instructions %}

- CLI {#cli}

  ```bash
  yc vpc security-group move encemkpqg8fh******** \
    --folder-id b1chgf288nvg******** \
    --destination-folder-id b1cs8ie21pk1********
  ```

{% endlist %}

#### Useful links {#see-also}

* [Moving a cloud network to a different folder](network-move.md)