Solved

Groups, Usermod

Posted on 2001-07-26
4
360 Views
Last Modified: 2010-04-21
Using solaris

everytime I

usermod -G group1,group2,group3 username

on command line it adds these groups to the
user but does not keep the other groups for the user.

Question: how do u use usermod utility to add groups
to a user nin addition to the groups they are a member
of.

Do not answer: edit and save file. I want to know how u do it with the usermod utility.

thanks in advance.
0
Comment
Question by:zipdog44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Expert Comment

by:tdaoud
ID: 6325943
Using the usermod utility you must always specify all groups you want for a user to be member of.  Once you ommit a group it means you want the user removed from that group.

So using usermod, it is hard to add a user to a group while keeping all others without mentioning their names with -G.

Tarik
0
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 50 total points
ID: 6326852
#!/usr/bin/ksh -
logname="$1"; shift
newgroups="$*"
oldgroups="$(groups "$logname")"
print -r -- "$newgroups $oldgroups" |
sed '
s/^[ ]*//
s/[ ]*$//
s/ [ ]*/,/g
'| read allgroups
usermod -G "$allgroups" "$logname"
0
 
LVL 6

Expert Comment

by:bira
ID: 6327287
Hi
Just add a group in the last line:

    x() {
     if [ $# -ge 2 ]
     then
             for i in "$@"
             do
                     spam="$spam \"$i\""
             done
             eval chuser $spam
     fi
     }
   x groups='group1,group2,group3' username



Regards
0
 
LVL 3

Expert Comment

by:gcauthon
ID: 6328005
usermod -G `groups <username> |sed 's/ /,/g'`,group1,group2,group3 <username>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question