Ubuntu Linux Add a User To Group www-data ( Apache Group )

How do I add a user to the Apache group called www-data under Ubuntu or Debian Linux server operating systems using the command line option?

You need to use the useradd command to add a user to the group called www-data under Ubuntu or Debian Linux system. This page shows how to add a user to an existing group named www-data.

ADVERTISEMENTS

Ubuntu Linux add a user to group command

The procedure is as follows:

  1. Open the terminal application.
  2. Login to Ubuntu server using ssh.
  3. Add a new user named foo to www-data group by running useradd -g www-data foo command.
  4. Add an existing user bar to Apache’s www-data group on Ubuntu using usermod -a -G www-data bar command.
  5. Verify new modification on Linux by using the id command.

Let us see all commands in details.

How to see a list of www-data members

To see list of all members of a group named www-data, run the following grep command on /etc/group file:
grep ^www-data /etc/group
Sample outputs:

www-data:x:33:

How do I add an existing user named vivek to group Apache group www-data?

Simply run the following command to add an existing user to an existing group:
sudo adduser {USER-NAME-HERE} {GROUP-NAME-HERE}
sudo adduser vivek www-data

Verify it with the help of id command:
id vivek
Ubuntu Linux Add a User To Group www-data Apache Group command

Add a new user to the www-data group

In this example, add a new user called vivek to the www-data group, enter:

sudo useradd -g www-data vivek
 
### set the password for vivek user ###
sudo passwd vivek

To verify new settings, enter:

id vivek
groups vivek

The group name www-data is the user’s initial login group i.e. vivek has been added to www-data primary group only.

www-data supplementary groups membership

To add a new user called vivek to supplementary groups called www-data and ftp, enter:

sudo groupadd vivek
sudo useradd -g vivek -G www-data,ftp vivek
sudo passwd vivek

To verify new settings, enter:

id vivek
groups vivek

Add a existing user to www-data group

Type the following command to add an existing user called vgite to the www-data group, enter:

sudo usermod -a -G www-data  vgite
id vgite
groups vgite

Above command will add the user vgite to the supplementary group called www-data. Use -a option only with the -G option.

Conclusion

You learned how to add a user to group www-data on Ubuntu Linux using command-line option. For more information see useradd, and usermod man pages online here or by typing the following man command:
man usermod
man useradd

🐧 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

ADVERTISEMENTS
7 comments… add one
  • msound Jun 23, 2014 @ 14:46

    When adding an existing user to www-data group, you might have to logout and login for the new group privileges to take effect.

    • Melroy Apr 26, 2015 @ 20:18

      Thats a good tip >< Is there no command for that?

    • samizdam Oct 2, 2015 @ 13:28

      Yes… I’m spent some time with chmod / chown manipulation, before understand it =)

  • baljit kumar Oct 9, 2014 @ 11:19

    it’s working i try

  • Barry Docherty May 24, 2016 @ 3:44

    Rubbish… complete and utter rubbish.
    to add a user to www-data group with Ubuntu at least that is:

    sudo adduser ‘NameOfUserYouWantAdded’ www-data

    and done!

  • fagner Jul 19, 2016 @ 19:42

    not exist “ftp” group

    • AndreaEM Sep 14, 2016 @ 7:12

      Maybe It’s cause you don’t have/don’t need an ftp group (eg. you don’t have an ftp service installed or misconfigured)

Leave a Reply

Your email address will not be published.

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