Howto: Linux creating user account under group

Q. How do I add a new user called foo under existing group bar?

A. You need to use useradd command, which create a new user or update default new user information. You need to pass -g option to useradd command. It specifies the group name or number of the user’s initial login group. The group name must exist. A group number must refer to an already existing group. The default group number is 1 or whatever is specified in /etc/default/useradd file.

Task: Make sure group sales exists

# grep 'sales' /etc/group

Task: Add a new user tom to group sales

# useradd -g sales tom
# passwd tom

You can add existing user jerry to group sales with usermod command:
# usermod -g sales jerry

You can add existing user jerry to secondary group purchase with usermod command:
# usermod -G purchase jerry

Please note that above commands works with Solaris UNIX, FreeBSD and UNIX like oses.


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Eagle Mar 31, 2008 @ 8:47

    Hi,
    How can i add an user who has root permissions.

    Regards
    Eagle

  • paramjeet singh Oct 26, 2009 @ 13:36

    can i add an user who has root permission if yes then, how is it.
    PARAMJEET SINGH

  • sreeram Jan 6, 2010 @ 12:22

    i installed oracle 10g on linux 5.4 but running time i am getting this problem
    Xlib: connection to “:0.0” refused by server Xlib: No protocol specified

  • sreeram Jan 6, 2010 @ 12:26

    i installed oracle 10g on linux 5.4 but running time i am getting this problem
    Xlib: connection to “:0.0″ refused by server Xlib: No protocol specified

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum