# Secondary user groups

**URL:** <https://www.ruby-forum.com/t/secondary-user-groups/107607>\
**Category:** Ruby\
**Created:** [June 23, 2007, 11:30pm UTC](https://www.ruby-forum.com/t/secondary-user-groups/107607 "2007-06-23T23:30:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gga](https://www.ruby-forum.com/u/gga)\
**Post date:** [June 23, 2007, 11:30pm UTC](https://www.ruby-forum.com/t/secondary-user-groups/107607/1 "2007-06-23T23:30:53Z")

</div>

require ‘etc’  
Etc.getpwnam(user)

or, using Daniel B.'s std-admin library\_

require ‘sys/admin’  
Sys::Admin.get\_user(user)

allows me to get a struct with the user’s primary group.

However, I need to obtain the list of ALL groups that a user belongs  
to (primary and secondary).  
Other than doing the unportable:

groups = `groups #{user}`.split

is there a method in the ruby std library to get the secondary groups?

---

<div class="post-metadata">

**Author:** ![gga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gga](https://www.ruby-forum.com/u/gga)\
**Post date:** [June 23, 2007, 11:55pm UTC](https://www.ruby-forum.com/t/secondary-user-groups/107607/2 "2007-06-23T23:55:56Z")

</div>

On Jun 23, 6:27 pm, gga [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> However, I need to obtain the list of ALL groups that a user belongs  
> to (primary and secondary).  
> Other than doing the unportable:
> 
> groups = `groups #{user}`.split
> 
> is there a method in the ruby std library to get the secondary groups?

Never mind. Found how to do it.

---

<div class="post-metadata">

**Author:** ![gga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gga](https://www.ruby-forum.com/u/gga)\
**Post date:** [June 24, 2007, 1:42am UTC](https://www.ruby-forum.com/t/secondary-user-groups/107607/3 "2007-06-24T01:42:05Z")

</div>

On 6/23/07, gga [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > However, I need to obtain the list of ALL groups that a user belongs  
> > to (primary and secondary).  
> > Other than doing the unportable:
> > 
> > groups = `groups #{user}`.split
> > 
> > is there a method in the ruby std library to get the secondary groups?
> 
> Never mind. Found how to do it.

Well how did you do it? 😉

---

<div class="post-metadata">

**Author:** ![gga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gga](https://www.ruby-forum.com/u/gga)\
**Post date:** [June 25, 2007, 4:42am UTC](https://www.ruby-forum.com/t/secondary-user-groups/107607/4 "2007-06-25T04:42:30Z")

</div>

Gregory B. wrote:

> > Never mind. Found how to do it.
> 
> Well how did you do it? 😉

Here’s one way you could do it with sys-admin:

groups = []  
Admin.groups{ |g|  
groups \<\< g.name if g.members.include?(‘you’)  
}

Regards,

Dan
