# How to add all the groups to a newly created user?

**URL:** <https://discourse.chef.io/t/how-to-add-all-the-groups-to-a-newly-created-user/6348>\
**Category:** Chef Infra (archive)\
**Created:** [February 25, 2015, 4:41am UTC](https://discourse.chef.io/t/how-to-add-all-the-groups-to-a-newly-created-user/6348 "2015-02-25T04:41:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anthony\_Kong](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/anthony_kong/32/73_2.png) [@Anthony\_Kong](https://discourse.chef.io/u/Anthony_Kong)\
**Post date:** [February 25, 2015, 4:41am UTC](https://discourse.chef.io/t/how-to-add-all-the-groups-to-a-newly-created-user/6348/1 "2015-02-25T04:41:31Z")

</div>

Hi,

it is my user json file in the data bag

{

```
"id": "project",

"shell": "/bin/bash",

 "groups": ["vagrant", "wheel", "admin", "sensu", "chef", "adm", "cdrom",

```

“sudo”, “dip”, “plugdev”, “lpadamin”]

}

In my default.rb cookbook, I have these lines

include\_recipe “users”

users\_manage “admin” do

action [:create]

end

After the user is created, it looks like this:

$ id

uid=1000(project) gid=1000(project) groups=1000(project),2302(admin)

How can I get the user to be member of all the groups mentioned in the json  
file?

Cheers,

Tony

---

<div class="post-metadata">

**Author:** ![George\_Miranda1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/george_miranda1/32/156_2.png) [@George\_Miranda1](https://discourse.chef.io/u/George_Miranda1)\
**Post date:** [February 25, 2015, 4:52am UTC](https://discourse.chef.io/t/how-to-add-all-the-groups-to-a-newly-created-user/6348/2 "2015-02-25T04:52:42Z")

</div>

The users\_manage resource from the community "users" cookbook takes the  
name of a group you want to configure and only ensures that group (and any  
of its users) are on the system. If you want to ensure "vagrant", "wheel",  
etc are on your system you must use a users\_manage resource for all of the  
groups you want configured on the system. Then you will see that your  
"project" user is associated with the groups you expect.

A detailed look at how that works can be found on the Chef blog

> **[Managing Users and SSH Keys in a Hybrid World - Chef Blog | Chef](https://www.chef.io/blog/managing-users-and-ssh-keys-in-a-hybrid-world)**
>
> Managing users is one of the contrived (but applicable) examples we use in Chef Fundamentals training to help onboard new Chefs to the idea of writing data-driven cookbooks.

On Tue, Feb 24, 2015 at 8:41 PM, Anthony Kong [anthony.hw.kong@gmail.com](mailto:anthony.hw.kong@gmail.com)  
wrote:

> Hi,
> 
> it is my user json file in the data bag
> 
> {
> 
> ```
> "id": "project",
> 
> "shell": "/bin/bash",
> 
> "groups": ["vagrant", "wheel", "admin", "sensu", "chef", "adm",
> 
> ```
> 
> "cdrom", "sudo", "dip", "plugdev", "lpadamin"]
> 
> }
> 
> In my default.rb cookbook, I have these lines
> 
> include\_recipe "users"
> 
> users\_manage "admin" do
> 
> action [:create]
> 
> end
> 
> After the user is created, it looks like this:
> 
> $ id
> 
> uid=1000(project) gid=1000(project) groups=1000(project),2302(admin)
> 
> How can I get the user to be member of all the groups mentioned in the  
> json file?
> 
> Cheers,
> 
> Tony

---

<div class="post-metadata">

**Author:** ![Nico\_Kadel\_Garcia](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@Nico\_Kadel\_Garcia](https://discourse.chef.io/u/Nico_Kadel_Garcia)\
**Post date:** [February 27, 2015, 11:00pm UTC](https://discourse.chef.io/t/how-to-add-all-the-groups-to-a-newly-created-user/6348/3 "2015-02-27T23:00:00Z")

</div>

The ‘users’ cookbook basically requires a separate cookbook and recipes to manage your own group or list of groups. It would be potentially quite helpful to have that information selectable on a role or environment basis, rather than requiring in-house recipes.

Nico Kadel-Garcia  
Lead DevOps Engineer  
[nkadel@skyhookwireless.com](mailto:nkadel@skyhookwireless.com)[mailto:nkadel@skyhookwireless.com](mailto:nkadel@skyhookwireless.com)

From: George Miranda [[mailto:gmiranda@getchef.com](mailto:gmiranda@getchef.com)]  
Sent: Tuesday, February 24, 2015 11:53 PM  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] Re: How to add all the groups to a newly created user?

The users\_manage resource from the community “users” cookbook takes the name of a group you want to configure and only ensures that group (and any of its users) are on the system. If you want to ensure “vagrant”, “wheel”, etc are on your system you must use a users\_manage resource for all of the groups you want configured on the system. Then you will see that your “project” user is associated with the groups you expect.

A detailed look at how that works can be found on the Chef blog

> **[Managing Users and SSH Keys in a Hybrid World - Chef Blog](https://blog.chef.io/2014/07/10/managing-users-and-ssh-keys-in-a-hybrid-world/)**
>
> Managing users is one of the contrived (but applicable) examples we use in Chef Fundamentals training to help onboard new Chefs to the idea of writing data-driven cookbooks. Whenever I run a training class, I typically end that module by talking...

On Tue, Feb 24, 2015 at 8:41 PM, Anthony Kong \<[anthony.hw.kong@gmail.com](mailto:anthony.hw.kong@gmail.com)[mailto:anthony.hw.kong@gmail.com](mailto:anthony.hw.kong@gmail.com)\> wrote:  
Hi,

it is my user json file in the data bag

{

```
"id": "project",

"shell": "/bin/bash",

 "groups": ["vagrant", "wheel", "admin", "sensu", "chef", "adm", "cdrom", "sudo", "dip", "plugdev", "lpadamin"]

```

}

In my default.rb cookbook, I have these lines

include\_recipe “users”

users\_manage “admin” do

action [:create]

end

After the user is created, it looks like this:

$ id

uid=1000(project) gid=1000(project) groups=1000(project),2302(admin)

How can I get the user to be member of all the groups mentioned in the json file?

Cheers,

Tony
