# Adding user to a group without SAM

**URL:** <https://community.unix.com/t/adding-user-to-a-group-without-sam/174401>\
**Category:** HP-UX\
**Created:** [August 14, 2007, 2:27pm UTC](https://community.unix.com/t/adding-user-to-a-group-without-sam/174401 "2007-08-14T14:27:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paqman](https://community.unix.com/letter_avatar/paqman/32/5_5575768a8748004e209b776fc1b2916d.png) [@paqman](https://community.unix.com/u/paqman)\
**Post date:** [August 14, 2007, 2:27pm UTC](https://community.unix.com/t/adding-user-to-a-group-without-sam/174401/1 "2007-08-14T14:27:55Z")

</div>

How can I add a user to a specific group without using SAM? I know I can user modprpw -G, but that will overwrite any groups the user is in with the ones I specify.

I need to assume that I do not know what groups the user is already in, so I can't put them in the modprpw command. I just need to add this user to a few groups without changing the ones they are already in.

FYI, i'm talking about secondary groups, not their primary group. And I'm scripting this, so I can't just go into /etc/group and edit it manually.

Thanks!

---

<div class="post-metadata">

**Author:** ![Perderabo](https://community.unix.com/user_avatar/community.unix.com/perderabo/32/27_2.png) [@Perderabo](https://community.unix.com/u/Perderabo)\
**Post date:** [August 14, 2007, 11:30pm UTC](https://community.unix.com/t/adding-user-to-a-group-without-sam/174401/2 "2007-08-14T23:30:35Z")

</div>

If you have modprpw your box must be in trusted mode so you need to use modprpw. You can obtain the list of groups a user in currently in via groups or grget commands. Then check to see if you need to add the user at all. He might already be in the group in question. If not, construct a new list of groups by adding yours to any pre-existing groups.

---

<div class="post-metadata">

**Author:** ![blowtorch](https://community.unix.com/user_avatar/community.unix.com/blowtorch/32/136_2.png) [@blowtorch](https://community.unix.com/u/blowtorch)\
**Post date:** [August 15, 2007, 7:05am UTC](https://community.unix.com/t/adding-user-to-a-group-without-sam/174401/3 "2007-08-15T07:05:32Z")

</div>

To get a list of groups that the user belongs to, you can use "id -a". Parse the output of that command to get the list of groups that the user belongs to. Then give the entire list to modprpw or whatever you are using.
