处理文件和Web服务器中的不同用户

I have a debian environment with php-fpm running behind nginx as user www-data. I upload files as an other user (user1) account via sftp.

Now I have a problem with permission conflicts, because some files have www-data as owner and some have user1 as owner and I'm wondering how to solve this.

Should I

  • create an own php-fpm pool for this user or
  • is it possible that users from www-data can access user1 files and vice versa or
  • is it possible to automatically change the user of the uploaded files to www-data

This can be achieved by sharing same group between those 2 different users. Nginx can be running under a certain user and a group, the directory permissions can spread permissions within that group.

There are many variations. The easiest one is to put user1 into www-data group (assuming www-data user has its own www-data group):

useradd -g www-data user1   # make www-data group default for this user
id user1                    # you will see this user has a different default group

Keep in mind php and nginx don't need to be configured differently, leave them setup via www-data user.

UPDATE:

Setuid can provide same functionality without worrying much of groups for user1. See more details here: https://en.m.wikipedia.org/wiki/Setgid