linux add user to group

15
Tutorial details Difficulty Intermediate (rss ) Root privileges Yes Requirements usermod/useradd Estimated completion time 5 minutes ≡ Menu Tutorials BASH Shell Troubleshooting Nginx Networking MySQL Google Cloud Platform Amazon Cloud Computing Rackspace Cloud Computing Linux CentOS Debian / Ubuntu Ubuntu Linux Suse RedHat and Friends Slackware Linux UNIX AIX Mac OS X FreeBSD FreeBSD Jails (VPS) Openbsd Solaris See all tutorial topics Contact us Linux Scripting Guide RSS/FEED Shop nixCraft Linux and Unix tutorials for new and seasoned sysadmin. Howto: Linux Add User To Group by Vivek Gite on March 14, 2006 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: 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

Upload: pablo

Post on 13-Sep-2015

43 views

Category:

Documents


3 download

DESCRIPTION

Como añadir usuarios de linux en grupos

TRANSCRIPT

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 1/15

    Tutorial details

    Difficulty Intermediate (rss)

    Root privileges Yes

    Requirements usermod/useradd

    Estimated completion time5 minutes

    Menu

    Tutorials

    BASH ShellTroubleshooting

    NginxNetworking

    MySQL

    Google Cloud PlatformAmazon Cloud Computing

    Rackspace Cloud ComputingLinux

    CentOSDebian / Ubuntu

    Ubuntu Linux

    SuseRedHat and FriendsSlackware Linux

    UNIX

    AIXMac OS X

    FreeBSDFreeBSD Jails (VPS)

    OpenbsdSolaris

    See all tutorial topics

    Contact usLinux Scripting GuideRSS/FEEDShop

    nixCraftLinux and Unix tutorials for new and seasoned sysadmin.

    Howto: Linux Add User To Group

    by Vivek Gite on March 14, 2006

    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:

    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 asfollows:

    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

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 2/15

    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. Forexample, 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

    Option Purpose

    -a

    --appendAdd the user to the supplementary group(s). Use only with the -G option.

    -g GROUP

    --gid GROUPUse this GROUP as the default group.

    -G GRP1,GRP2

    --groups GRP1,GRP2Add 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 NISserver 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)

    See also

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

    $ man useradd

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 3/15

    Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

    { 121 comments add one }

    praj March 26, 2006, 4:05 pm

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

    some alternative

    Reply Linkmanoj May 6, 2011, 2:18 pm

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

    Reply Linknixcraft March 26, 2006, 8:02 pm

    See shell script example here

    Reply LinkBackSeat August 14, 2006, 3:41 pm

    praj: see chpasswd(8)

    Reply LinkBnK December 6, 2006, 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 LinkSren June 19, 2007, 10:37 am

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

    Reply Link

    Sren June 19, 2007, 10:38 am

    This editor bugs me :) The command should be:

    gpasswd -a user group

    Reply LinkFrogbert July 11, 2007, 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 LinknixCraft July 12, 2007, 6:13 pm

    Yes Im 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 Linklefty.crupps October 15, 2014, 5:39 pm

    Youre suggesting wed need to know each group first? Perhaps telling us that above would be good, also including the command to find the currentoldgroup1 oldgroup1 stuff:groups lefty

    Also, whats the difference between useradd and adduser?Whats the differences between distros?The article could use some reorganization as well to make the concept flow better, but the article has good info, just not laid out super-clearly. IMHO.

    Reply Linkvim July 14, 2007, 2:41 am

    Actually, its 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 dont know when this feature was introduced, you should check for it on the man pages before using it.

    Reply Link

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 4/15

    nixCraft July 14, 2007, 10:15 pm

    vim,

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

    Appreciate your post!

    Reply LinkThemba March 16, 2015, 8:06 am

    The -a option is not working on ubuntu 14.04

    Reply Linkderry August 7, 2007, 10:25 pm

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

    gpasswd -a USER GROUP

    Reply LinkSteve Francia August 19, 2007, 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 Linkrupa August 22, 2007, 9:06 am

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

    Reply Linkemiat February 1, 2011, 4:43 am

    tnx a lot

    Reply Linkratna December 16, 2011, 11:51 am

    R u still in same Domain?

    RegardsRatna

    Reply Linksuresh January 7, 2008, 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 Linksoliver January 25, 2008, 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 Link

    Ryan March 13, 2012, 1:13 am

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

    Reply Link

    soliver January 25, 2008, 9:23 pm

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

    Reply LinkNilesh January 26, 2008, 3:09 pm

    install sudo.

    then edit /etc/sudoers (or other location)

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 5/15

    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 Linkchris March 11, 2008, 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 dont have a password for the root user.

    Reply LinknixCraft March 11, 2008, 7:31 pm

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

    HTH

    Reply Link

    chris March 11, 2008, 7:50 pm

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

    Reply Link

    nixCraft March 12, 2008, 5:28 am

    May be this will help

    Reply Link

    LiLo April 30, 2008, 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 LinknixCraft April 30, 2008, 12:48 pm

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

    Reply Link

    LiLo April 30, 2008, 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 eachcall of useradd without modifying webmin

    Thats not making my life any easier :)

    Reply Linktoti May 2, 2008, 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 Linktoti May 2, 2008, 4:20 am

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

    Reply LinkRobM June 6, 2008, 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 dont 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 dont specify a command to run youll probably get an error to the effect of cannot execute bash: file not found because it wont be on the environment.

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 6/15

    You could use shell to point su at it, but your shell wouldnt be a login shell and therefore wont read your .bash_profile etc.

    Reply Linkkishore June 19, 2008, 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 RegardsKishore

    Reply Linkhelpneeded June 26, 2008, 11:30 am

    why do we need to add new users in linux?

    Reply LinknixCraft June 26, 2008, 1:31 pm

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

    Reply LinkHAMEED June 27, 2008, 9:18 am

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

    Reply Linkitsadok July 5, 2008, 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 Link

    David Brown July 6, 2008, 9:04 pm

    In the past when Ive upgraded to the latest edition of Ubuntu Ive 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

    Ive been unable to re-instate the users.

    Can anyone tell me how to add these users

    Reply Link

    JuLian henDra July 8, 2008, 4:06 am

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

    Reply Link

    vishwas July 8, 2008, 5:45 am

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

    Reply Linkfunctionsys August 21, 2008, 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/groupaddbash: /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 Link

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 7/15

    Suresh September 22, 2008, 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 canaccess all the subuser folders, and subusers can access only their folders respectively.

    I havent 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 Linkeve October 22, 2008, 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 LinkAksuli October 31, 2008, 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 cant use TAB for filling in file/folder names etc.. PLZ help me out :)

    Reply Link

    vishwas November 3, 2008, 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 Linkkenny November 14, 2008, 7:01 pm

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

    Reply LinkPratik Patel November 15, 2008, 5:10 am

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

    Reply LinkRyan November 20, 2008, 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 Link

    junaid January 21, 2009, 9:10 am

    thanks a alot buddy for help. keep it up

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 8/15

    Suggestions::

    plz insert search tool with in website.

    GOD bless YOU

    Reply Link

    hyacinth February 4, 2009, 3:01 am

    How to delete and add a group..

    please help me..

    Thanks

    Reply Link

    dunno February 13, 2009, 9:41 pm

    complete noob with linux here

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

    i know theres 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 its 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 isnt the right place to ask this, i have no idea where else to ask and ive been seraching for this for hours how do you

    mount a new hard drive? theres 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 cant believe that that would be impossible, so theres got to be a way.

    Reply Linkwasim March 9, 2009, 12:14 pm

    to add user in multiple group

    usermod -G group1,group2 username

    Reply Link

    Patrick March 29, 2009, 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 LinkAheebwa Edgar May 19, 2009, 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 Link

    Aheebwa Edgar May 19, 2009, 6:46 pm

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

    Reply Link

    Snap June 5, 2009, 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.. butsince I never log in with this user, how can I make sure that it is actually a member of the group?

    Reply Linkbalu phani July 29, 2009, 6:18 am

    hi

    i want to create a user say testusr and i dont want to get home directory for him and his individual group (generally he will belong to his group testusr group i

    dont 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 Linkbalu phani July 29, 2009, 7:29 am

    i got ituseradd -Ng -M

    Reply Link

    wasim July 29, 2009, 11:38 am

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 9/15

    you can check existing group by this command

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

    Reply Linkyogesh kolte October 28, 2009, 8:29 am

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

    Reply Link

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

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

    Reply Link

    karim November 21, 2009, 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 Link

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

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

    Reply Link

    esraa March 24, 2010, 7:47 pm

    thanks

    Reply Link

    esraa March 28, 2010, 7:31 pm

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

    thanks

    Reply Link

    zerc May 5, 2010, 2:15 pm

    Hi,

    Thank you for this tutorial !

    Reply Link

    Arvind May 19, 2010, 5:37 am

    Thank you for this tutorial !

    Reply Link

    umer ahmed June 5, 2010, 5:39 pm

    good tutorial

    thanks:)

    Reply Link

    Andey June 5, 2010, 10:16 pm

    ive probably used this page like 50 times because im still to lazy to learn usermod

    Reply Link

    Brian Maskell June 9, 2010, 7:11 pm

    This page (http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/) has a reference to the group file /etc/group, the target of the link being:

    http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/It should be:

    http://www.cyberciti.biz/faq/understanding-etcgroup-file/

    Reply Link

    nixCraft June 10, 2010, 6:05 am

    Thanks for the heads up!

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 10/15

    Reply Linkuzer July 4, 2010, 7:51 pm

    Hey, Im getting[user@localhost ~]$ sudo su

    [sudo] password for user:user is not in the sudoers file. This incident will be reported.

    Reply Link

    shane williamson July 7, 2010, 2:03 am

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

    Reply Link

    indir July 9, 2010, 6:25 am

    thanks, its works for me :)

    Reply Linkselven September 15, 2010, 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 dont understand why there should be a tool to complicate it!

    Reply Linknic September 16, 2010, 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 LinkTom O'Connell October 7, 2010, 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 Linkdx November 4, 2010, 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 Linksyed December 9, 2010, 7:53 pm

    i have need in one account and multiple sign

    Reply LinkNURUL HUDA January 9, 2011, 4:04 pm

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

    Reply Linkemiat February 1, 2011, 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 Link

    Rodislav Moldovan April 3, 2011, 10:01 pm

    #works in Debian 6Add user to a new group, by keeping old groups

    usermod -a -G AdditionalGroup User

    -a append

    -G group name

    Reply Link

    Rashid May 12, 2011, 10:50 am

    thanks for sharing useful and knowledgeable topic

    Reply Link

    Extra June 27, 2011, 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

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 11/15

    the best thinks.

    this is the primary site, that i search for responses to Linux Qs.

    Reply LinkLaxman Rana September 20, 2011, 4:37 am

    thanks this tutorial to learn about user add with groups modificationnicely this iz working on my pc in linux

    Reply Link

    Neth Kong October 8, 2011, 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 Link

    da_fatfinger October 20, 2011, 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 im 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 usermodworks. Since you are THE top google hit for linux add user to group, you would save a lot of people some serious pain.

    Reply Link

    Vivek November 9, 2011, 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 Linkvlad the impaler December 8, 2011, 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 Link

    miquel January 12, 2012, 8:11 am

    Nice explanation

    Reply Link

    diptesh maity February 22, 2012, 3:02 pm

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

    Reply Link

    Subrat N January 10, 2013, 6:03 pm

    You should know the root password.

    $su -c useradd u_name

    or through sudo

    Reply Link

    marc March 26, 2012, 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 Link

    remove this April 10, 2012, 3:28 pm

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

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 12/15

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

    Reply Link

    nitiratna nikalje April 25, 2012, 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 Link

    Jeremy June 11, 2012, 5:03 pm

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

    Reply Link

    dhani September 18, 2012, 8:21 am

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

    Reply Link

    Bijay Manandhar September 20, 2012, 6:24 am

    really nice tutorial ..

    thanx millions..

    Reply LinkValerio October 15, 2012, 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.confUnknown 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 groupIgnoring 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 LinkSequoia December 18, 2012, 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 Im 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 Link

    Subrat N January 10, 2013, 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 Link

    Luis Mompo Handen January 22, 2013, 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.

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 13/15

    #!/bin/bashFILE=/root/test.csvcat $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 | chpasswddone

    Reply Link

    Landis January 27, 2013, 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 lunaruid=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 Link

    Vaibhav Gupta January 31, 2013, 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/ptsmount 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 youre still having issues try unplugging the device and reconnecting it.

    I am stuck can u please help.

    Reply Link

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

    # usermod -a -G ftp tony

    what did the -a switch do?

    Regards

    Reply Link

    prashanth July 12, 2013, 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 Link

    George Huebschman July 16, 2013, 5:49 pm

    Thanks,

    A very clear thorough answer to the question!

    When you have a choice, spend your money where youd prefer to work if you had NO choice.

    Reply Link

    bb November 7, 2013, 1:52 pm

    adduser not useradd

    Reply Link

    Jose December 31, 2013, 10:24 pm

    Excellent bro !, Im using fedora and this is very usefull for HTTPD directories !

    Reply Link

    Golandaj S February 5, 2014, 6:45 am

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 14/15

    adduser account

    Reply LinkGolandaj Saddam February 5, 2014, 6:47 am

    groupadd

    Reply LinkNaveen Sharma April 25, 2014, 12:45 pm

    I got this question lately in an interview.

    One User ID can belong to maximum how many secondary groups.?

    Is there a definite no?

    Reply Link

    JET April 25, 2014, 11:45 pm

    The format of this post took out an important part of the commands. PLEASE DISREGARD ABOVE. Here is an ammended post:

    A simple man usermod will provide the options available. The -A option does not remove any groups, it only adds. For adding a user to a group, MY preferred

    method is:

    usermod username -A group

    If you wish to add user to a list of groups, you may use a comma as delimiter, as in:

    usermod username -A group1,group2,group3

    The -G option is not preferred in my opinion, it is used to specify all groups to which the user will belong to, and has the ability to REMOVE a user from unspecifiedgroups. As many have pointed out, the ability to remove a user from groups can have nasty results if not carefully used.

    So, just use the -A option to add your existing users to existing groups, and you should be all set. Good luck!

    Reply LinkExtra December 18, 2014, 10:51 am

    Good point Jet! Thank You!

    Reply Linkraja May 19, 2014, 2:45 am

    i am create the create to the roup bdba an user add but he was not add to the usermod command.

    usermod -u 1000 -g dba -d |d01|oracle

    Reply Link

    lliseil January 1, 2015, 5:26 pm

    # Posts original command (does not work):

    useradd -G GROUP USERuseradd: user 'USER' already exists

    # Working command:

    gpasswd -a USER GROUPAdding user USER to group GROUP

    # Help:

    gpasswd -hUsage: gpasswd [option] GROUPOptions: -a, --add USER add USER to GROUP -d, --delete USER remove USER from GROUP[/code]

    Arch linux here.

    Reply Link

    pandiyan January 3, 2015, 12:10 pm

    thanks friends..

    Reply Link

    Craig R Morton January 13, 2015, 3:33 pm

    Excellent, thank you.

    Reply Link

    Harry Hinson likes erica February 23, 2015, 12:00 pm

    complete noob with linux here

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

  • 24/6/2015 Howto: Linux Add User To Group

    http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/ 15/15

    i know theres 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 its 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 isnt the right place to ask this, i have no idea where else to ask and ive been seraching for this for hours how do you

    mount a new hard drive? theres plenty of info telling how to mount a cdrom or a floppy drive, or even a usb thumb drive, but NOWHERE does anything or anyonesay how to mount a simple hard drive. is it not possible to add an additional hard drive? i cant believe that that would be impossible, so theres got to be a way.

    Reply Link

    harry hindson February 24, 2015, 2:25 pm

    I promise I do fancy her no joke

    Reply Link

    Leave a Comment

    Name *

    Email *

    Website

    Comment

    Submit

    Next post: Howto Compiling C program and creating executable file under Linux / UNIX / *BSD

    Previous post: Linux Start Oracle As a Service

    To search, type and hit enter

    Featured Articles:

    30 Cool Open Source Software I Discovered in 2013

    30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X

    Top 30 Nmap Command Examples For Sys/Network Admins

    25 PHP Security Best Practices For Sys Admins20 Linux System Monitoring Tools Every SysAdmin Should Know

    20 Linux Server Hardening Security Tips

    Linux: 20 Iptables Examples For New SysAdmins

    Top 20 OpenSSH Server Best Security Practices

    Top 20 Nginx WebServer Best Security Practices20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors

    15 Greatest Open Source Terminal Applications Of 2012

    My 10 UNIX Command Line Mistakes

    Top 10 Open Source Web-Based Project Management Software

    Top 5 Email Client For Linux, Mac OS X, and Windows UsersThe Novice Guide To Buying A Linux Laptop

    2000-2015 nixCraft. All rights reserved. Privacy Policy - Terms of Service - Questions or Comments

    The content is copyrighted to nixCraft and may not be reproduced on other websites.