Ubuntu Linux: Add a User To Group

How do I add a user to group under Ubuntu Linux operating system using command line options?

You need to use the following commands:

Tutorial details
Difficulty Intermediate (rss)
Root privileges Yes
Requirements useradd / usermod
Time 5 minutes
[a] useradd command – Create a new user or update default new user information or add a new user to secondary group. [b] usermod command – Modifies the system account and make changes to existing user accounts.

First, login as the root user

You must login as the root user. You can switch to the root user by typing ‘su –‘ and entering the root password, when prompted. However, sudo command is recommend under Ubuntu Linux for switching to root user:

su -

OR

sudo -s

OR

sudo useradd ...

Ubuntu Linux: add a new user to secondary group

Use the following syntax:

useradd -G Group-name Username
passwd Username

Create a group called foo and add user tom to a secondary group called foo:
$ sudo groupadd foo
$ sudo useradd -G foo tom

OR
# groupadd foo
# useradd -G foo tom

Verify new settings:

id tom
groups tom

Finally, set the password for tom user, enter:
$ sudo passwd tom
OR
# passwd tom
You can add user tom to multiple groups – foo, bar, and ftp, enter:
# useradd -G foo,bar,ftp tom

Ubuntu Linux: add a new user to primary group

To add a user called tom to a group called www use the following command:

useradd -g www tom
id tom
groups tom

Ubuntu Linux: add a existing user to existing group

To add an existing user jerry to ftp supplementary/secondary group with usermod command using -a option ~ i.e. add the user to the supplemental group(s). Use only with -G option:

usermod -a -G ftp jerry
id jerry

To change existing jerry’s primary group to www, enter:

usermod -g www jerry

For more information and options read the following man pages:
man 8 useradd man 8 usemod

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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 jobs killall kill pidof pstree pwdx time
Searchinggrep 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
11 comments… add one
  • macsim Jun 12, 2012 @ 9:33

    For debian based system you can use adduser

    #adduser tom group

  • Jorge Sep 16, 2012 @ 2:57

    Hi,
    I want to create many users with same permission at Amazon EC2.
    How can i do it?

  • Kiara Oct 11, 2012 @ 8:20

    im unable to login tothe new users created using “useradd” command.please help.

  • khan Nov 18, 2012 @ 15:03

    # useradd -G foo,bar,ftp top

    should be
    # useradd -G foo,bar,ftp tom
    ^
    I

  • vikas Jan 10, 2013 @ 20:24

    Hi Kiara,
    You have to specify a password for the new user.

    $passwd username hit on enter then try

  • Jonathan Jun 10, 2013 @ 20:13

    Mis-spelled jerry in line:

    usermod -g www jeryy

    should be:

    usermod -g www jerry

  • Nicolas Lussier Sep 11, 2013 @ 1:58

    It dos not work for me on debian Jessie. I can add the group but eaven if I added the group to the user the user cant acces to the folder …
    usermod -a -G Group-name Username

    permission on the folder are drwxrwsr-x and the user cant add annithing to this !!! So it fail It as been over 2h I’m playing with this with no succes !!!
    more If I look for which group the user have I get withdifferent result:
    in the Username shell the commande “groups” give me
    Username
    and the comande “groupes name1” give me
    Username Group-name

    Anny help will be welcom

    • Helper Oct 5, 2015 @ 13:57

      I think you need to log out and log in again to gain the privileges that you have set via chmod.

      • Patrick May 16, 2016 @ 23:06

        Yup, logging out worked for me. (Actually I had to reset the VM anyway)

  • Josiah Luscher Mar 27, 2014 @ 16:07

    I don’t think this works; at least not any more. You have to use:
    “usermod -a -G group username”

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.