LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 05:18 PM   #1
tramni1980
Member
 
Registered: Jul 2006
Location: Köln, Germany
Distribution: Slackware64-14.2 & -current, DragonFly BSD, OpenBSD
Posts: 819

Rep: Reputation: 55
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, 05: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,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
usermod -G somegroup someuser accomplishes what you want... (see man usermod).
 
Old 05-08-2008, 05:35 PM   #3
gsl
Member
 
Registered: Jun 2007
Location: Australia
Distribution: Slackware
Posts: 76

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

Rep: Reputation: 73
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, 05:36 PM   #5
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,443

Rep: Reputation: 73
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, 07:28 PM   #6
rworkman
Slackware Contributor
 
Registered: Oct 2004
Location: Tuscaloosa, Alabama (USA)
Distribution: Slackware
Posts: 2,559

Rep: Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351
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



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 04:40 PM
how to add existing files to existing imported kdevelop project?? santana Programming 1 05-22-2007 09:53 AM
Adding new group to existing user ALF Linux - Software 7 05-08-2006 09:35 PM
how to add an existing user to a new group? xpucto Linux - Newbie 8 04-19-2006 08:31 AM
add root user to the existing group ashley75 Linux - General 4 09-25-2003 09:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:03 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration