LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Question on bash shell (https://www.linuxquestions.org/questions/linux-newbie-8/question-on-bash-shell-788286/)

Ajit Gunge 02-10-2010 01:16 PM

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

rweaver 02-10-2010 01:21 PM

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.

Ajit Gunge 02-10-2010 01:24 PM

Quote:

Originally Posted by rweaver (Post 3859390)
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?

rweaver 02-10-2010 01:29 PM

Quote:

Originally Posted by Ajit Gunge (Post 3859393)
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.

pixellany 02-10-2010 01:29 PM

Quote:

Originally Posted by Ajit Gunge (Post 3859393)
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

rweaver 02-10-2010 02:04 PM

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.


All times are GMT -5. The time now is 12:26 AM.