≡ Menu

How To: UNIX Add A User To A Group

Q. How do I add a user to a group under Sun Solaris UNIX operating system from a shell prompt or command line?

A.. You can useadd command to administer a new user login on the UNIX system. Solaris UNIX / HP-UX UNIX uses /etc/passwd, /etc/shadow and /etc/group files to store user information.

Following information is compatible with the Solaris, AIX and HP-UX UNIX operating systems.

Add A New User To A Group

Add a new user called vivek to a group called vsftp, enter:
# useradd -G vsftp -d /data/home/v/vivek -m vivek
# passwd vivek

Where,

  • -G vsftp : Add vivek to secondary group called vsftp. This group must exists on the system.
  • -d /data/home/v/vivek : Path to the vivek's home directory
  • -m : Create the new user's home directory if it does not already exist.
  • vivek : Username / login nane

UNIX Add Existing User To A Secondary Group

Use usermod command to modify a user's login definition on the system including group membership. For, example add user vivek to sales group, enter:
# usermod -G sales vivek
Add user tom to sales but also keep his existing membership of ftpusers, enter:
# usermod -G ftpusers,sales tom

UNIX Add Existing User To A Primary Group

Add jerry to sales primary group and change its existing group membership:
# usermod -g sales jerry
For more information read following man pages:
$ man usermod
$ man useradd
$ man passwd

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

{ 23 comments… add one }

  • Mihir G joshi June 18, 2008, 12:37 pm

    Hello Vivek,

    I don’t want my private files to be displayed in the output of find command????

  • Mihir G joshi June 18, 2008, 12:39 pm

    How do i hide my confidential files to be isolated from find output??

    I am using RHEL 5

    Mihir G joshi

  • Jonathan Dade January 10, 2009, 10:03 am

    Find is a command that is used to list all files that it “finds”. If you don’t want other people to find them when using find make sure they do not have root access or access to the directory in which the files are stored.

    Usually on a multi-user system you would store your files in your home directory. The only users that have access to this directory are yourself, root and in general anyone who is a member of the group named after your username. Be aware that if you create users the hard way (by editting /etc/passwd /etc/shadow /etc/groups) and you create users with the same uid / gid then these will also be able to access because they are the “same” user.

    Of course as a RHEL 5 owner you can indeed ask this sort of question of RedHat’s support teams.

    I hope this helps.

  • esha June 25, 2009, 6:32 pm

    Hi,
    Can someone help. Is it possible to add # infront of user loginname without vi to the password file. I have more than 50 users loginame to hide. Any command?
    Thanks

  • esha June 25, 2009, 7:00 pm

    Vivek,
    Example: i have account named esha and i want to add #esha without manually vi to password file.
    Any possible way?

    • nixCraft June 25, 2009, 8:50 pm

      You wanna lock user account? If so use passwd itself:
      passwd -l username
      To unlock
      passwd -u username

    • krishna December 22, 2011, 9:17 am

      no its cannot possiable ok
      u have to create via useradd command
      note: while creating the user , system will automatically created related configuration file ok

  • esha July 7, 2009, 2:51 pm

    Thanks Vivek. Another one:
    What is the SUN command to get directory full path for example for shortcut: $QERP_TOP.

  • william lee August 3, 2009, 12:46 am

    hi
    i have a problem…
    Can I change the properties of the group?
    What I mean is let say i have one admin group , it can edit and install the SW in the system, and at the same time, I have a user group , it can just use the SW but can’t install it. AS long as i add a account to the group, it automatically can have those priveledge according to the group properties.

    Thanks

    Willaim Lee

  • Samuel October 15, 2009, 1:58 pm

    Hi vivek , first sorry about my english (I’mfrom Brazil) .

    My problem is : add an existing user to a group without removing its existing group.
    For example:
    HP > /usr/sam/lbin/grpusrs -m -l ‘,user’ group
    Linux > /usr/sbin/groupmod -A user group
    AIX > chgrpmem -m + user group

    When I use this one “/usr/local/bin/usermod -G group user” , it removes any other existing group.

    Tks for your attention

    Samuel

  • Lyenna Amchurek October 29, 2009, 3:05 am

    Hi,
    I’m new to HPUX.
    Let say I have existing id called Sysadmin which is a normal user. How do I upgrade this id to become root equivalent, and have all the permissions like root.

    Tq

    • krishna December 22, 2011, 8:47 am

      we cannot change the same id
      but chenahe the id for chmod command
      it root loogin u have to change the permissions for perticular user
      using of chown command

  • Samuel November 17, 2009, 12:55 pm

    Lyenna

    By editing /etc/passwd and changing the ID (second field) to zero.

    Bye

    • krishna December 22, 2011, 8:48 am

      using of chmod command only
      do n;t chage the in vi mode ok

  • Asit Pal July 19, 2010, 9:34 am

    drwxr-xr-x 2 asit ae 1024 Jul 8 16:03 00000010

    How will I change the name user “asit” to “amit” and group “ae” to “pp” ?
    Any unix command?

    Thanks
    Asit

    • anon January 3, 2011, 6:42 pm

      sed ‘s/asit/amit/g’ /etc/passwd > /etc/passwd.tmp
      sed ‘s/ae/pp/g’ /etc/passwd.tmp > /etc/passwd
      pwck ( to check for password file errors )

    • srikanth kumbam February 25, 2011, 5:03 am

      This answer to asit pal, If you want to change your user name from asit to amit, you should execute the follwing command
      usermod -l amit asit
      for group its almost same groupmod -n pp ae

  • wasim October 21, 2011, 6:55 am

    Hi I am new to HP Unix please help in L1 and L2 commands and please let me any test server is there online where is can practice

    • krishna December 22, 2011, 8:49 am

      no
      and u have to search the google only

  • Alec March 15, 2012, 4:33 pm

    To append a group to the user’s list of supplemental groups, include the ‘-a’ flag.

    For example, to add user ‘popeye’ who is already in the ‘sailor’ group …

    # groups popeye
    popeye : popeye sailor

    … to the ‘forearm’ group as well, you can do this:

    # usermod -a -G forearm popeye

    This way it appends him, and does not overwrite the other groups he is a part of:

    # groups popeye
    popeye : popeye sailor forearm

    This saves you the hassle of having to write out all the other groups he needs to be a part of just to add him to another one.

  • basis May 30, 2013, 2:50 am

    thank you for sharing

    I like your post.

  • Jordan May 19, 2015, 1:27 pm

    Thanks assholes, for tricking me into removing myself from the sudoers group!

Leave a Comment