LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-10-2010, 01:16 PM   #1
Ajit Gunge
Member
 
Registered: Jan 2008
Location: Pune
Distribution: RHEL,fedora
Posts: 253
Blog Entries: 1

Rep: Reputation: 21
Question on bash shell


HI All,
I am trying to learn shell scripting from a book and all I am doing is following few instruction from the book.

Now this is what I am doing.
I am trying to add a user using the useradd command so I run the following
at command prompt
root@S8500C_9>useradd ajit.
The first time when I add this user I was successful.Later I deleted this suer using the userdel -r ajit command.Now when again I am trying to add this user it gives me following error.
useradd: group ajit exists - if you want to add this user to that group, use -g.
Now when I try using the -g option with the useradd command it gives we all the set off options avaiable to use along with the useradd command but doesnt create the ajit use
Can anyone tell me how can I create the same user after deleting it.

Thanks,
Ajit
 
Old 02-10-2010, 01:21 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Remove the group named ajit.

eg:
Code:
groupdel ajit
Then run the add again. The other option is...

Code:
useradd -g ajit ajit
It tells you what the problem is-- "useradd: group ajit exists", remove the group or tinker with the options of your useradd. -g requires a group to be specified... ajit in this case. When in doubt look up the option for the program by typing: man programname (eg: man useradd) and check that you're using each option correctly.

Last edited by rweaver; 02-10-2010 at 01:24 PM.
 
Old 02-10-2010, 01:24 PM   #3
Ajit Gunge
Member
 
Registered: Jan 2008
Location: Pune
Distribution: RHEL,fedora
Posts: 253

Original Poster
Blog Entries: 1

Rep: Reputation: 21
Quote:
Originally Posted by rweaver View Post
Remove the group named ajit.

eg:
Code:
groupdel ajit
Then run the add again, it's telling you what the problem is-- "useradd: group ajit exists", remove the group or tinker with the options of your useradd

Code:
useradd ajit -g ajit
Thanks rweaver.Now what if I have to add some other user to a group named ajit?
 
Old 02-10-2010, 01:29 PM   #4
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by Ajit Gunge View Post
Thanks rweaver.Now what if I have to add some other user to a group named ajit?
Code:
useradd -g ajit otheruser
you can also just add the person to the ajit group in /etc/group.
 
Old 02-10-2010, 01:29 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by Ajit Gunge View Post
Thanks rweaver.Now what if I have to add some other user to a group named ajit?
Here's a nice quirk of BASH---you don't add users to groups---you add groups to users. e.g.:

usermod -a -G group1,group2,group3,etc username

The -a flag (append) tells it to keep the existing groups and add the new ones
 
1 members found this post helpful.
Old 02-10-2010, 02:04 PM   #6
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
The only reason I don't typically suggest people use usermod is because its default behavior is destructive. If a new user has setup say 20 people in a specific group and forgets the -a it will replace the group with just the user(s) being added. It's not really an issue if you have good backups (although a bit annoying with tape backups), but the most common problem I see in any operating system is a lack of backups.
 
  


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
A question about shell (bash shell) thomas2004ch Linux - Newbie 4 08-27-2009 02:09 AM
bash shell script question shurjo Programming 7 01-12-2009 04:26 AM
shell (bash) scripting question(s) boxerboy Programming 5 11-08-2005 03:51 PM
BASH question(or shell in general) jrmann1999 Linux - Software 4 05-11-2005 05:16 PM
Bash shell scripting question. Itsu Linux - General 3 04-30-2005 03:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:23 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