?
Solved

Groups, Usermod

Posted on 2001-07-26
4
Medium Priority
?
371 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 200 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 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