Solved

Groups, Usermod

Posted on 2001-07-26
4
337 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
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now