Howto: Linux Add User To Group

by on March 14, 2006 · 110 comments· LAST UPDATED April 21, 2014

in , ,

How can I add a user to a group under Linux operating system using command line options? How to add an existing user into a group in Linux using command line options?

You can use the useradd or usermod commands to add a user to a group. The useradd command creates a new user or update default new user information. The usermod command modifies a user account and it is useful to add user to existing groups. There are two types of groups under Linux operating systems:

Tutorial details
DifficultyIntermediate (rss)
Root privilegesYes
Requirementsusermod/useradd
Estimated completion time5 minutes
  1. Primary user group.
  2. Secondary or supplementary user group.

All user account related information are stored in the following files:

  1. /etc/passwd - Contains one line for each user account.
  2. /etc/shadow - Contains the password information in encrypted formatfor the system's accounts and optional account aging information.
  3. /etc/group - Defines the groups on the system.
  4. /etc/default/useradd - This file contains a value for the default group, if none is specified by the useradd command.
  5. /etc/login.defs - This file defines the site-specific configuration for the shadow password suite stored in /etc/shadow file.

useradd Example - Add a new user to secondary group

You need to the useradd command to add new users to existing group (or create a new group and then add user). If group does not exist, create it. The syntax is as follows:
useradd -G {group-name} username
In this example, create a new user called vivek and add it to group called developers. First login as a root user (make sure group developers exists), enter:
# grep developers /etc/group
Output:

developers:x:1124:

If you do not see any output then you need to add group developers using the groupadd command:
# groupadd developers
Next, add a user called vivek to group developers:
# useradd -G developers vivek
Setup password for user vivek:
# passwd vivek
Ensure that user added properly to group developers:
# id vivekOutput:

uid=1122(vivek) gid=1125(vivek) groups=1125(vivek),1124(developers)

Please note that capital G (-G) option add user to a list of supplementary groups. Each group is separated from the next by a comma, with no intervening whitespace. For example, add user jerry to groups admins, ftp, www, and developers, enter:
# useradd -G admins,ftp,www,developers jerry

useradd example - Add a new user to primary group

To add a user tony to group developers use the following command:
# useradd -g developers tony
# id tony

Sample outputs:

uid=1123(tony) gid=1124(developers) groups=1124(developers)

Please note that small g (-g) option add user to initial login group (primary group). The group name must exist. A group number must refer to an already existing group.

usermod example - Add a existing user to existing group

Add existing user tony to ftp supplementary/secondary group with the usermod command using the -a option ~ i.e. add the user to the supplemental group(s). Use only with -G option:
# usermod -a -G ftp tony
In this example, change tony user's primary group to www, enter:
# usermod -g www tony

usermod command options summary

OptionPurpose
-a
--append
Add the user to the supplementary group(s). Use only with the -G option.
-g GROUP
--gid GROUP
Use this GROUP as the default group.
-G GRP1,GRP2
--groups GRP1,GRP2
Add the user to GRP1,GRP2 secondary group.

A note about security

If you add or delete user to existing group, you must change the owner of any crontab files or at jobs manually. You must make any changes involving NIS on the NIS server too.

A note about GUI tool

You will probably find the use of the GUI tool easy. KDE user can use KUser tool and the GNOME user can use users-admin tool called system-config-users:
# system-config-users
Sample outputs:

Fig.01: User Manager Tool in action (image credit Fedora project)

Fig.01: User Manager Tool in action (image credit Fedora project)

See also

For more information type the following command at the shell prompt:
$ man usermod
$ man useradd

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 110 comments… read them below or add one }

1 praj March 26, 2006 at 4:05 pm

How can i run the passwd command
non-interactively in linux . I want to change the password through a script file….How can i
invoke the passwd command thru a script file non-interactively.
If thats not possible then suggest
some alternative…

Reply

2 manoj May 6, 2011 at 2:18 pm

Multiple entries named ‘audio’ in /etc/group. Please fix this with pwck or grpck.
usermod: error adding new group entry

Reply

3 nixcraft March 26, 2006 at 8:02 pm

See shell script example here

Reply

4 BackSeat August 14, 2006 at 3:41 pm

praj: see chpasswd(8)

Reply

5 BnK December 6, 2006 at 8:51 pm

thanks!

time saving tip for new admin. I can read man page but it is full of shit-load and no examples at all. keep it up good work!

Reply

6 Søren June 19, 2007 at 10:37 am

I find the easiest way to add a user to a group is using gpasswd like this:
gpasswd -a

Reply

7 Søren June 19, 2007 at 10:38 am

This editor bugs me :) The command should be:
gpasswd -a user group

Reply

8 Frogbert July 11, 2007 at 6:52 am

This is wrong, usermod -G ftp tony will take you out of all your existing groups. Not add a new one.

Reply

9 nixCraft July 12, 2007 at 6:13 pm

Yes I’m adding a existing user to existing group, but to keep user in other old group you need to use:

usermod -G oldgroup1, oldgroup2, ftp tony

Reply

10 vim July 14, 2007 at 2:41 am

Actually, it’s easier to go like this:

usermod -a -G ftp tony

The -a causes your old groups to be kept. At least in the newer versions. I was looking into this and found an old manpage where the -a function is not documented.

Since I don’t know when this feature was introduced, you should check for it on the man pages before using it.

Reply

11 nixCraft July 14, 2007 at 10:15 pm

vim,

-a seems to a new option. This FAQ has been updated to include -a.

Appreciate your post!

Reply

12 derry August 7, 2007 at 10:25 pm

I recommend that when you need to add people to an existing group to use

gpasswd -a USER GROUP

Reply

13 Steve Francia August 19, 2007 at 6:24 pm

Using:
usermod (pwdutils) 3.1.2

there is no -a option available, so that options is a fairly new one, it also appears to be nonstandard across *NIX.

Reply

14 rupa August 22, 2007 at 9:06 am

thanks for -a option, it saved my time on centos

Reply

15 emiat February 1, 2011 at 4:43 am

tnx a lot

Reply

16 ratna December 16, 2011 at 11:51 am

R u still in same Domain?

Regards
Ratna

Reply

17 suresh January 7, 2008 at 12:01 pm

why this command didnt work on sun solaris 10 ?
#useradd -u 100 -g other -d /export/home/newuser1 -m -s /bin/ksh -c “Regular User Account ” newuser1

Error :uid 100 already in use

Reply

18 soliver January 25, 2008 at 9:20 pm

Hello,

how can I give a usergroup root rights?
I would like to create a group “developer” but they need root access as well.

thanks,
Oliver

Reply

19 Ryan March 13, 2012 at 1:13 am

No one needs to assign root access to their own account. Not even you. Add them to the wheel group.

Reply

20 soliver January 25, 2008 at 9:23 pm

I also want to give another user root access.
That way you can do PermitRootLogin yes, which is more secure.

Reply

21 Nilesh January 26, 2008 at 3:09 pm

install sudo.

then edit /etc/sudoers (or other location)

and append the line-

%developer ALL=(ALL) NOPASSWD: ALL

This will give the users in group developer the root access but will need to type

sudo

The above setup will not demand root password

Reply

22 chris March 11, 2008 at 6:47 pm

Now that I foolishly ran:
usermod -G ftp chris

Is there anyway I get access back to all the groups I had before?

I am using Ubuntu so I don’t have a password for the root user.

Reply

23 nixCraft March 11, 2008 at 7:31 pm

See if you have backup in /etc/group- or restore it from your tape backup.

HTH

Reply

24 chris March 11, 2008 at 7:50 pm

no tape backup and unless the etc/group file is auto backedup I don’t have one of those either.

Reply

25 nixCraft March 12, 2008 at 5:28 am
26 LiLo April 30, 2008 at 8:34 am

Hi,

Is there a way to automatically create a MySQL database when creating the user?

(the new database would be named after the user and with the same login / password)

Reply

27 nixCraft April 30, 2008 at 12:48 pm

You need to write a shell script; there is no built in option to create mysql db.

Reply

28 LiLo April 30, 2008 at 2:04 pm

OK, so for instance, with webmin which allows the creation of users from a text using useradd, it would not be possible to automatically add a database for each call of useradd without modifying webmin…

That’s not making my life any easier :)

Reply

29 toti May 2, 2008 at 4:19 am

Hi… newb here ;)
I have a quick question: in CentOS 5, when I type usermod -a -G ftp tony I always get the error “invalid numeric argument ‘ftp’ why is that?

Reply

30 toti May 2, 2008 at 4:20 am

sorry just read the disclaimer on “leave reply” disregard my question :|

Reply

31 RobM June 6, 2008 at 8:27 pm

If you modified your own user account while logged in with it, the changes will not have an effect until you next login.

If you don’t want to logout, you can replace your current BASH shell with a new one to achieve the same thing by running the follow:

su –preserve-environment –command “$(which $SHELL) –login -i” $(whoami)

This will switch-user to yourself, replacing your current shell with a new instance of itself. You will be prompted for your password.

If you don’t specify a command to run you’ll probably get an error to the effect of “cannot execute bash: file not found” because it won’t be on the environment. You could use –shell to point su at it, but your shell wouldn’t be a “login” shell and therefore won’t read your .bash_profile etc.

Reply

32 kishore June 19, 2008 at 9:58 am

Hi friends,

I want to say thanks for u.Because of this post i created the users myself without anyones help.

Thanks and Regards
Kishore

Reply

33 helpneeded June 26, 2008 at 11:30 am

why do we need to add new users in linux?

Reply

34 nixCraft June 26, 2008 at 1:31 pm

Linux is multiuser operating system. User can maintain their privacy and security.

Reply

35 HAMEED June 27, 2008 at 9:18 am

WHAT IS THE COMMAND TO CHECK THE EXISTING GROUPS IN THE SYSTEM AND ALSO COMMAND TO CHECK THE USERS ???

Reply

36 itsadok July 5, 2008 at 6:16 am

There are simpler commands (at least on Ubuntu):

adduser user group
will add an existing user to an existing group

deluser user group
will remove a user from a specified group

Reply

37 David Brown July 6, 2008 at 9:04 pm

In the past when I’ve upgraded to the latest edition of Ubuntu I’ve added any existing users by entering the user name, real name, password etc. into the Users and Groups dialogue boxes and all worked fine.

However with upgrading to Hardy when I do the same an error flags up saying “Home Directory Already Exists – Please enter a different home directory path” and I’ve been unable to re-instate the users.

Can anyone tell me how to add these users

Reply

38 JuLian henDra July 8, 2008 at 4:06 am

How do I listed all existing users and group by command line in Ubuntu, thanks

Reply

39 vishwas July 8, 2008 at 5:45 am

how to add two groups in a group
for eg: group1 and group2 these group should be added to another group called group3

Reply

40 functionsys August 21, 2008 at 5:16 am

whyyyyyyyyy how i can fix it

FunctionSys@FunctionSys-PC ~/mysql
$ groupadd
bash: groupadd: command not found

FunctionSys@FunctionSys-PC ~/mysql
$ /usr/sbin/groupadd
bash: /usr/sbin/groupadd: No such file or directory

FunctionSys@FunctionSys-PC ~/mysql
$ useradd -G {mysql} mysql
bash: useradd: command not found

FunctionSys@FunctionSys-PC ~/mysql
$

Reply

41 Suresh September 22, 2008 at 10:06 am

Hi Vivek,

your tutorial is really nice to follow.

I have a scenario, where i need to create a super user and subuser(1,2,3) for accessing ftp in our webserver it is linux with redhat on it. so that super user can access all the subuser folders, and subusers can access only their folders respectively.

I haven’t created any of the groups, so i would like to know from scratch like defining users and creating permissions.

since I am new to this linux environment, it would be great if you could post commands like the one above for the scenario i explained.

Many Thanks.
Suresh

Reply

42 eve October 22, 2008 at 1:38 pm

i have 2 group. Group A and Group B.
I have a existing user in Group A.
Now i want to add this existing user to Group B too.
What should i do?

Thanks You.

Reply

43 Aksuli October 31, 2008 at 9:43 pm

Ive managed to add account.

richard@richard-desktop:~$ sudo useradd -G admin,dialout,cdrom,floppy,audio,dip,video,plugdev,fuse,lpadmin aksu
richard@richard-desktop:~$ sudo passwd aksu
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
richard@richard-desktop:~$ id aksu
uid=1001(aksu) gid=1001(aksu) groups=1001(aksu),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),107(fuse),109(lpadmin),115(admin)

Now I have a problem, when I connect the server says:

Could not chdir to home directory /home/aksu: No such file or directory

How can I manage that to work out right. ATM I can’t use TAB for filling in file/folder names etc.. PLZ help me out :)

Reply

44 vishwas November 3, 2008 at 4:00 am

Aksuli type this command it will help u

1) richard@richard-desktop:~$ sudo useradd -G admin,dialout,cdrom,floppy,audio,dip,video,plugdev,fuse,lpadmin aksu -d /home/aksu

2) mkdir /home/aksu

Reply

45 kenny November 14, 2008 at 7:01 pm

i type in useradd command but i get the response command not found.what is the problem

Reply

46 Pratik Patel November 15, 2008 at 5:10 am

Please tell me how can i add multiple users to one group at a single shot.

Reply

47 Ryan November 20, 2008 at 11:59 pm

To add a user to multiple groups – ‘man useradd’

-G, –groups GROUP1[,GROUP2,...[,GROUPN]]]
A list of supplementary groups which the user is also a member of.
Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option.
The default is for the user to belong only to the initial group.

Reply

48 junaid January 21, 2009 at 9:10 am

thanks a alot buddy for help……. keep it up

Suggestions::
plz insert search tool with in website…….

GOD bless YOU

Reply

49 hyacinth February 4, 2009 at 3:01 am

How to delete and add a group..
please help me..

Thanks

Reply

50 dunno February 13, 2009 at 9:41 pm

complete noob with linux here…

what are the actual groups that you can add users to?

i know there’s the ‘users’ group for standard users… but what else is there? can i add a user as a sysadmin with full control over the system? or is that the same as logging in as root?

i also understand it’s apperently a “bad idea” to login as root into KDE… but why?

sorry, like i said, complete noob. just installed yesterday.

oh, and also, even though i realize this isn’t the right place to ask this, i have no idea where else to ask and i’ve been seraching for this for hours… how do you mount a new hard drive? there’s plenty of info telling how to mount a cdrom or a floppy drive, or even a usb thumb drive, but NOWHERE does anything or anyone say how to mount a simple hard drive…. is it not possible to add an additional hard drive? i can’t believe that that would be impossible, so there’s got to be a way.

Reply

51 wasim March 9, 2009 at 12:14 pm

to add user in multiple group

usermod -G group1,group2 username

Reply

52 Patrick March 29, 2009 at 6:04 pm

i have 3 sites. MainSite TestSite and FileSite. Main and Test need to be apart of the FileSite group to be able to read/write/delete files.

usermod -a -G MainSite,TestSite FileSite
is that right?

Reply

53 Aheebwa Edgar May 19, 2009 at 6:16 pm

pliz thanx so much for your ideas but my question was how to add one user to the linux group.am waiting right now.
God bless you

Reply

54 Aheebwa Edgar May 19, 2009 at 6:46 pm

i need just a command to add user to a group.thank you

Reply

55 Snap June 5, 2009 at 2:44 am

If I have a user that is only used to run scripts (started by fetchmail), but I do not actually ever log in as such user in the console. I have added that user to a group to get access to a folder, but it does not seem to work.. if it was a normal user, I would simply log out and log in again to activate my membership in this group.. but since I never log in with this user, how can I make sure that it is actually a member of the group?

Reply

56 balu phani July 29, 2009 at 6:18 am

hi
i want to create a user say “testusr” and i don’t want to get home directory for him and his individual group (generally he will belong to his group “testusr” group i don’t want it) but i have already have a common group say “cmngrp” so he should belong to it only.
i think my point is clear
create “testusr” without home directory and without his own group but belongs to “cmngrp”.

Reply

57 balu phani July 29, 2009 at 7:29 am

i got it
useradd -Ng -M

Reply

58 wasim July 29, 2009 at 11:38 am

you can check existing group by this command

cat /etc/group | cut -d “:” -f1

Reply

59 yogesh kolte October 28, 2009 at 8:29 am

it was very helpful to usermod command to modified changes the user

Reply

60 Vlad the Impaler November 8, 2009 at 9:26 am

To check groups and who is in the group, the easiest is cat /etc/group. Smile!

Reply

61 karim November 21, 2009 at 9:18 am

Hi ,

Say i have a group called music.

I want every new user henceforth created to automatically have the music group as their secondary group on top of the primary group that will be added by the system.

Is this possible?

Thanks

Reply

62 Al B.. January 15, 2010 at 8:56 pm

son of monkeys uncle there is no usermod “-a” option is SUSE Ent 10

Reply

63 esraa March 24, 2010 at 7:47 pm

thanks

Reply

64 esraa March 28, 2010 at 7:31 pm

i wante cleared code in shell script programming to add user and add groupe
thanks

Reply

65 zerc May 5, 2010 at 2:15 pm

Hi,

Thank you for this tutorial !

Reply

66 Arvind May 19, 2010 at 5:37 am

Thank you for this tutorial !

Reply

67 umer ahmed June 5, 2010 at 5:39 pm

good tutorial
thanks
:)

Reply

68 Andey June 5, 2010 at 10:16 pm

i’ve probably used this page like 50 times because i’m still to lazy to learn usermod

Reply

69 Brian Maskell June 9, 2010 at 7:11 pm
70 nixCraft June 10, 2010 at 6:05 am

Thanks for the heads up!

Reply

71 uzer July 4, 2010 at 7:51 pm

Hey, I’m getting
[user@localhost ~]$ sudo su
[sudo] password for user:
user is not in the sudoers file. This incident will be reported.

Reply

72 shane williamson July 7, 2010 at 2:03 am

Okay these commands DO NOT WORK!!!!!!!!!!!!!!

Reply

73 indir July 9, 2010 at 6:25 am

thanks, its works for me :)

Reply

74 selven September 15, 2010 at 7:44 pm

seriously, this is so gay! in my days to add a user to a group, we just had to add it in /etc/group! i don’t understand why there should be a “tool” to complicate it!

Reply

75 nic September 16, 2010 at 2:49 pm

I like to use a “for” loop for this. For exampled

for i in group1 group2 group3 ...; do adduser $i; done

Reply

76 Tom O'Connell October 7, 2010 at 3:22 pm

I am using Mint 9 and have no knowledge of either command line or archive manager.
Can you steer me to the easiest tutorial.

Thanks,

Reply

77 dx November 4, 2010 at 10:06 am

how many users can be in a group? i want to add 500 users to group mailusers. wont that be slowing down my mailserver?

regards

Reply

78 syed December 9, 2010 at 7:53 pm

i have need in one account and multiple sign

Reply

79 NURUL HUDA January 9, 2011 at 4:04 pm

I have lost my all inbox mails unexpectedly.Is it possible to retrive again?please help me.

Reply

80 emiat February 1, 2011 at 4:52 am

what is the 1st step on how to add group in active directory 2003? And 1st step of how to add group in active directory?

emiat.

Reply

81 Rodislav Moldovan April 3, 2011 at 10:01 pm

#works in Debian 6
Add user to a new group, by keeping old groups
usermod -a -G AdditionalGroup User

-a append
-G group name

Reply

82 Rashid May 12, 2011 at 10:50 am

thanks for sharing useful and knowledgeable topic

Reply

83 Extra June 27, 2011 at 8:02 am

Oh yeah man! This is the best site i ever meet, on helping users to quick find the answer to concrete Question! Thank you so much for the FAQ archive! wish you the best thinks.
this is the primary site, that i search for responses to Linux Q’s.

Reply

84 Laxman Rana September 20, 2011 at 4:37 am

thanks this tutorial to learn about user add with group’s modification…
nicely this iz working on my pc in linux……………

Reply

85 Neth Kong October 8, 2011 at 4:16 pm

Hi all, I would like to write a script in Linux to manage User and Group….
*** they are able to add, delete, modify,,,,,,

Would you please help me?

Reply

86 da_fatfinger October 20, 2011 at 10:48 pm

I made the mistake of not including -a in usermod as well, now im locked of doing anything useful in ubuntu. Granted i’m a linux newbie, so hard lessons like this are bound to happen, but you would save many headaches with just a small, clear explanation at the top about how flags (especially -a) are vital to how usermod works. Since you are THE top google hit for “linux add user to group”, you would save a lot of people some serious pain.

Reply

87 Vivek November 9, 2011 at 2:04 pm

Any idea howto add existing group into another existing group ?

Ex: test1 – group has 5 users
test2 – group has 3 users

i want to add test1 group to be part of test2, instead of adding the users.

Reply

88 vlad the impaler December 8, 2011 at 12:43 pm

Can you please emboss, move to top, highlight, make it red and blink FFS !!!
99 % of the people want an user added to an existing group, not moved.
Only on Linux, add is a special type of move (sarcasm).

Please, for this tutorial of yours, that comes up on google, this is what we want:
usermod -a -G ftp tony
not this:
usermod -G ftp tony

Maybe with time we will learn Linux and face this issues more bravely, but most of us that come here have rather trivial experience with Linux, we want to learn.. but we want to learn how to add an user to a group (of course existing, is the natural way) no how to damage our systems.

Call me stupid, but it is the 2nd time I revisit this issue, being forced to again reinstall my linux box because of damaging my sudoers list.

Please, put a big red or whatever flashy warning on top of the article, notifying people about the sudeoers bite.

Reply

89 miquel January 12, 2012 at 8:11 am

Nice explanation

Reply

90 diptesh maity February 22, 2012 at 3:02 pm

how to create user under user in linux?? not from superuser.

Reply

91 Subrat N January 10, 2013 at 6:03 pm

You should know the root password.

$su – -c “useradd u_name”

or through sudo

Reply

92 marc March 26, 2012 at 8:22 am

I knew that useradd could add a user to the system but I did not know that it would for a group as well. Thanks for this how-to then.

Reply

93 remove this April 10, 2012 at 3:28 pm

This post is wrong and it’s the top search result on google. You should edit or remove it.

The correct way to add a user to a group is “usermod -aG groupname username”.

Reply

94 nitiratna nikalje April 25, 2012 at 1:19 pm

its mind blowing solution for adding user to any group .we can add multiple existing users to an existing group by this method # gpasswd -M niti,gauri,lina,nidhi masti =added user niti ,gauri ,lina and nidhi to group “masti”

Reply

95 Jeremy June 11, 2012 at 5:03 pm

Thanks, this is helpful for people like myself; just starting out with RHEL.

Reply

96 dhani September 18, 2012 at 8:21 am

Thank you, this really solve my problems in samba share.

Reply

97 Bijay Manandhar September 20, 2012 at 6:24 am

really nice tutorial ..

thanx millions..

Reply

98 Valerio October 15, 2012 at 6:41 pm

Hi… I tryed your hint, but I have got some erros below:
root@ibeji:/etc# testparm
Load smb config files from /etc/samba/smb.conf
Unknown parameter encountered: “client code page”
Ignoring unknown parameter “client code page”
Unknown parameter encountered: “character set”
Ignoring unknown parameter “character set”
Unknown parameter encountered: “domain admin group”
Ignoring unknown parameter “domain admin group”
Unknown parameter encountered: “domain admin users”
Ignoring unknown parameter “domain admin users”
Processing section “[netlogon]”
Processing section “[home]”
Processing section “[publico]”
Processing section “[contabil]”
Processing section “[suporte]”
Processing section “[tmp]”
Loaded services file OK.
Server role: ROLE_DOMAIN_PDC
Press enter to see a dump of your service definitions

Reply

99 Sequoia December 18, 2012 at 5:05 pm

You should really change this article to either
a) use the -a switch in the first example or
b) add a BIG RED WARNING that the command you give will REMOVE THE USER FROM ALL CURRENT GROUPS

This comes up #1 on google for “linux add user to group” and I suspect I’m not the only one who completely screwed up their user by running the command you have listed here to “add a user to a group”

Perhaps the article should be titled “How to remove a user from all groups and add them to a new group”

Reply

100 Subrat N January 10, 2013 at 5:52 pm

Hi Geeks,

How can I add multiple users into a group at a time without removing the old users belongs to that particular group.
I have tried the following command

#gpasswd -M user1,user2,user3 group_name

But, the thing is that, after adding these users, the previous users belongs to this group being removed.
I want the previous users to be exist.
Please, help……..
Thanks in advance …..

Reply

101 Luis Mompo Handen January 22, 2013 at 1:35 pm

I built a bash script to add multiple users from a csv-file to an existing group without creating a home dir. The passwords in csv-file are clear text.

#!/bin/bash
FILE=/root/test.csv
cat $FILE | while read line; do
   USER=$(echo $line | awk -F\; '{print $1}')
   PASS_TMP=$(echo $line | awk -F\; '{print $2}' | sed 's/\ //g')
   useradd -M -G cvs_usr $USER
   echo $USER:$PASS_TMP | chpasswd
done

Reply

102 Landis January 27, 2013 at 7:30 pm

In SuSE linux, there is No -a (this article states that the ‘-a’ retains existing groups and ‘adds’ new group ‘-G’), but in openSuSE 12.2 at least, there is no ‘-a’ option to usermod, it keeps existing groups, by default i guess…
# usermod -G GroupName UserName
eg,
# id lunar
uid=1002(lunar) gid=100(users) groups=100(users)
# usermod -G sshd lunar
# id lunar
uid=1002(lunar) gid=100(users) groups=100(users),102(sshd)
Landis.

Reply

103 Vaibhav Gupta January 31, 2013 at 3:09 pm

Hi ,
I have built a x86 rootfs using buildroot with both ifuse , imobiledevice ,usbmuxd . i did chroot ( directory :/var/prj_ca/) to the generated filesystem and mounted the following
mount –bind /dev /var/prj_ca/dev
mount –bind /dev/pts /var/prj_ca/dev/pts
mount –bind /dev/fuse /var/prj_ca/dev/fuse
mount –bind /proc /var/prj_ca/proc
mount –bind /sys /var/prj_ca/sys
mount –bind /media /var/prj_ca/media
when i run .
lsusb -v | grep -i iSerial i am getting the IPOD serial id but .
ifuse is failing with following error.
ifuse /tmp/apple_inc._ipod_b067d003ed1b22a9fffa47e3654a00e6386a6c9a/
usbmuxd_get_device_list: error opening socket!
No device found, is it connected?
If it is make sure that your user has permissions to access the raw usb device.
If you’re still having issues try unplugging the device and reconnecting it.

I am stuck can u please help.

Reply

104 Muhammad Usman Majeed April 22, 2013 at 7:46 am

# usermod -a -G ftp tony

what did the ‘-a’ switch do?

Regards

Reply

105 prashanth July 12, 2013 at 12:35 pm

is there any way to add multiple users to a existing group with disturbing or deleting existing users in that group

Reply

106 George Huebschman July 16, 2013 at 5:49 pm

Thanks,
A very clear thorough answer to the question!

“When you have a choice, spend your money where you’d prefer to work if you had NO choice.”

Reply

107 bb November 7, 2013 at 1:52 pm

adduser not useradd

Reply

108 Jose December 31, 2013 at 10:24 pm

Excellent bro !, I’m using fedora and this is very usefull for HTTPD directories !

Reply

109 Golandaj S February 5, 2014 at 6:45 am

adduser account

Reply

110 Golandaj Saddam February 5, 2014 at 6:47 am

groupadd

Reply

Leave a Comment

Tagged as: ,

Previous Faq:

Next Faq: