LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 05-08-2008, 06:18 PM   #1
tramni1980
Member
 
Registered: Jul 2006
Location: Tübingen, Germany
Distribution: Slackware64-13.37
Posts: 737

Rep: Reputation: 37
add an existing user to an existing group?


Hello!
I am writing a SlackBuild script and in the doinst.sh file I need to create a user "someuser" and a group "somegroup" and then add that user to that group.
So far I figured out how to check if the user already exists:

if cat /etc/passwd | cut -f 1 -d : | grep -q someuser; then echo "there is someuser"; fi

whether the group exists:

if cat /etc/group | cut -f 1 -d : | grep -q someuser; then echo "there is somegroup"; fi

and whether the user someuser is a member of the group somegroup:

if groups someuser | grep -q somegroup; then echo "is a member";else echo "is not a member"; fi

The question is in case both the user and the group exist, but the user is not a member of the group, how do I add that user to that group. In short how do I add an existing user to an existing group?

Googling has suggested doing it by:

usermod -aG somegroup someuser

Unfortunately the usermod command on Slackware 12.0 does not support the -a option. I need the latter because I do not want to lose the other groups that someuser is a member of. Is there some other simple way of doing that?

Any suggestions will be appreciated.

Regards,
Martin

PS Let me know if the usermod command in Slackware 12.1 supports the -a option.
 
Old 05-08-2008, 06:32 PM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,108

Rep: Reputation: 807Reputation: 807Reputation: 807Reputation: 807Reputation: 807Reputation: 807Reputation: 807
usermod -G somegroup someuser accomplishes what you want... (see man usermod).
 
Old 05-08-2008, 06:35 PM   #3
gsl
LQ Newbie
 
Registered: Jun 2007
Location: Melbourne, Australia
Distribution: Slackware
Posts: 24

Rep: Reputation: 5
I believe "gpasswd -a" is what you need.
 
Old 05-08-2008, 06:35 PM   #4
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,441

Rep: Reputation: 70
I remembered seeing this in a thread I'm posted in recently and sure enough, doing a simple LQ search for "usermod" helped me find the thread.
http://www.linuxquestions.org/questi...1/#post3129078

Summary: try gpasswd -a username groupname
 
1 members found this post helpful.
Old 05-08-2008, 06:36 PM   #5
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,441

Rep: Reputation: 70
Quote:
Originally Posted by tronayne View Post
usermod -G somegroup someuser accomplishes what you want... (see man usermod).
No it does not. Please read the thread I linked to above.
 
Old 05-08-2008, 08:28 PM   #6
rworkman
Slackware Contributor
 
Registered: Oct 2004
Location: Tuscaloosa, Alabama (USA)
Distribution: Slackware
Posts: 1,922

Rep: Reputation: Disabled
If you're writing this build script for SlackBuilds.org submission, don't bother to add the automatic group addition and such, as we'll just remove it. That needs to be documented in the README for the administrator to do.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add new files to existing ones SentralOrigin Linux - General 3 04-13-2008 05:40 PM
how to add existing files to existing imported kdevelop project?? santana Programming 1 05-22-2007 10:53 AM
Adding new group to existing user ALF Linux - Software 7 05-08-2006 10:35 PM
how to add an existing user to a new group? xpucto Linux - Newbie 8 04-19-2006 09:31 AM
add root user to the existing group ashley75 Linux - General 4 09-25-2003 10:40 PM


All times are GMT -5. The time now is 09:12 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration