I've got a user named foo. I'd like foo to have all the same group memberships that I do. I thought I was close, with this:

sudo usermod -a -G $(id -Gn | tr " " ",") node4

The id piped to tr is working fine, producing output like abc,def,ghi,jkl etc. The docs that I've found say that the way to add a user to multiple groups is usermod -a -G ftp,admins,othergroup <username>.

When I run id for the new user after running sudo usermod, the user is only a member of one group, but the id -Gn for me returns about 10 groups.

Is the sudo command what is goofing me up here?

edit: it seems like the issue here is that the groups are not actually in /etc/group, they are somehow populated from Active Directory.

  • 2
    if node4 is your new user's name, there is no reason your one-liner shouldn't work under normal conditions. If it is not working, you need to specify what you are getting as an error or less than desired outcome.
    – MelBurslan
    Jan 26, 2016 at 18:11
  • you can accomplish that with usermod
    – unixmiah
    Jan 26, 2016 at 19:03
  • @MelBurslan updated my post
    – jcollum
    Jan 26, 2016 at 19:04
  • while logged into your own account, run this Groups=$(id -Gn | tr " " ","); echo ${Groups}. do you see all the groups separated by comma signs ?
    – MelBurslan
    Jan 26, 2016 at 19:24
  • yes; when i run sudo usermod -a -G abc,xyz node4 then I check with sudo id node4 I do not see the groups added to the user; this seems odd
    – jcollum
    Jan 26, 2016 at 19:27

1 Answer 1


What you have works on my system.

    user:~$ groups test;
    test : test
    user:~$ groups
    user adm cdrom sudo dip www-data plugdev lpadmin sambashare davfs2 wireshark
    user:~$ sudo usermod -a -G $(id -Gn | tr " " ",") test
    user:~$ groups test
    test : test adm cdrom sudo dip www-data plugdev lpadmin user sambashare davfs2 wireshark
  • well crap; there must be something about this system that is goofy; waiting on support ticket
    – jcollum
    Jan 26, 2016 at 22:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .