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
Solved

Groups, Usermod

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

792 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