Ubuntu – Create a new User with custom Home Directory and add to “www-data” group

Create the skel

# copy from existing skel
cp -r /etc/skel /etc/skel-for-web-users
cd /etc/skel-for-web-users
sudo mkdir configs logs web web/public_html
cd logs
touch error.log
touch access.log

# verify contents with
tree /etc/skel-for-web-users
# should output
/etc/skel-for-web-users
├── configs
├── logs
│   ├── access.log
│   └── error.log
└── web
    └── public_html

4 directories, 2 files

Create the user

useradd dummy-user -g www-data -k /etc/skel-for-web-users -m

# verify its home directory
tree /home/dummy-user

# ouputs:
/home/dummy-user
├── configs
├── logs
│   ├── access.log
│   └── error.log
└── web
    └── public_html

4 directories, 2 files

# verify permissions
ls /home/dummy-user/ -la

# ouputs:
drwxr-xr-x 5 dummy-user www-data 4096 Sep 13 12:52 .
drwxr-xr-x 4 root       root     4096 Sep 13 12:52 ..
drwxr-xr-x 2 dummy-user www-data 4096 Sep 13 12:48 configs
drwxr-xr-x 2 dummy-user www-data 4096 Sep 13 12:49 logs
drwxr-xr-x 3 dummy-user www-data 4096 Sep 13 12:48 web