# How to change the controller of a canister?

**URL:** <https://forum.dfinity.org/t/how-to-change-the-controller-of-a-canister/5227>\
**Category:** Developers\
**Created:** [June 15, 2021, 6:50pm UTC](https://forum.dfinity.org/t/how-to-change-the-controller-of-a-canister/5227 "2021-06-15T18:50:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccyanxyz](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ccyanxyz/32/1025_2.png) [@ccyanxyz](https://forum.dfinity.org/u/ccyanxyz)\
**Post date:** [June 15, 2021, 6:50pm UTC](https://forum.dfinity.org/t/how-to-change-the-controller-of-a-canister/5227/1 "2021-06-15T18:50:20Z")

</div>

I have a custom canister A, with a function `createSubCanister`, invoke this function will create a canister B, I assume the controller of canister B is canister A in such scenario, right? Is there a way to set the controller of canister B to another principal? Can I write a `setController` function inside canister A to do this? If yes, how?

---

<div class="post-metadata">

**Author:** ![prithvi](https://avatars.discourse-cdn.com/v4/letter/p/22d042/32.png) [@prithvi](https://forum.dfinity.org/u/prithvi)\
**Post date:** [June 15, 2021, 6:58pm UTC](https://forum.dfinity.org/t/how-to-change-the-controller-of-a-canister/5227/2 "2021-06-15T18:58:18Z")

</div>

`createSubCanister` should invoke the management canister’s `create_canister` method to create B. `create_canister` has this interface definition:

```auto
create_canister : (record {
    settings : opt canister_settings
  }) 

```

where `canister_settings` is similarly defined as:

```auto
type canister_settings = record {
  controllers : opt vec principal;
  compute_allocation : opt nat;
  memory_allocation : opt nat;
  freezing_threshold : opt nat;
};

```

All you need to do is provide a valid Principal(s) for `canister_settings`’ `controllers` field and provide that settings to the `create_canister` call

You can find more info about create\_canister here: [The Internet Computer Interface Specification :: Internet Computer](https://sdk.dfinity.org/docs/interface-spec/index.html)

---

<div class="post-metadata">

**Author:** ![ccyanxyz](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ccyanxyz/32/1025_2.png) [@ccyanxyz](https://forum.dfinity.org/u/ccyanxyz)\
**Post date:** [June 15, 2021, 7:09pm UTC](https://forum.dfinity.org/t/how-to-change-the-controller-of-a-canister/5227/3 "2021-06-15T19:09:59Z")

</div>

Thanks, this solves my problem.

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [June 16, 2021, 12:21am UTC](https://forum.dfinity.org/t/how-to-change-the-controller-of-a-canister/5227/4 "2021-06-16T00:21:18Z")

</div>

Another way:

`dfx canister --network ic --no-wallet call aaaaa-aa update_settings '(record{canister_id = principal "<CANISTER ID>";settings = record {controller = opt principal "<CONTROLLER>"; null; null; null;};})'`

Call this from the current controller of a canister.
