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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
02-10-2010, 01:16 PM
|
#1
|
Member
Registered: Jan 2008
Location: Pune
Distribution: RHEL,fedora
Posts: 253
Rep:
|
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
|
|
|
02-10-2010, 01:21 PM
|
#2
|
Senior Member
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833
Rep: 
|
Remove the group named ajit.
eg:
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.
|
|
|
02-10-2010, 01:24 PM
|
#3
|
Member
Registered: Jan 2008
Location: Pune
Distribution: RHEL,fedora
Posts: 253
Original Poster
Rep:
|
Quote:
Originally Posted by rweaver
Remove the group named ajit.
eg:
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?
|
|
|
02-10-2010, 01:29 PM
|
#4
|
Senior Member
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833
Rep: 
|
Quote:
Originally Posted by Ajit Gunge
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.
|
|
|
02-10-2010, 01:29 PM
|
#5
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Quote:
Originally Posted by Ajit Gunge
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.
|
02-10-2010, 02:04 PM
|
#6
|
Senior Member
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833
Rep: 
|
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 07:54 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|