How To: UNIX Add A User To A Group

last updated in Categories , , , ,

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


  • -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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


23 comment

  1. 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.

  2. 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?

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

    1. 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

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

  5. 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.


    Willaim Lee

  6. 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


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


    1. 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

  8. 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?


    1. 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 )

    2. 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

  9. 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

  10. 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.

Leave a Comment