First be aware that such a setup would allow these users to pass ANY data (including KP, state secrets, stolen credit cards...) between each other. You're hosting an open relay between these users, and you might become legally liable for helping them should they decide to do something that your local government dislikes. At a bare minimum, you need to keep logs of their file activity, and review those logs.
Next, I'm going to STRONGLY recommend that you use chroot, as these are untrusted users. https://www.the-art-of-web.com/system/sftp-logging-chroot/ Does an excellent job of explaining how to do this, but my needs don't quite match that. My needs do roughly match what you are describing, however, so I think my solution can serve as a good starting point.
My strategy is to create a single chroot for all sftp users, and use file permissions to blind them to each other's homes. Specifically, my file structure looks like this:
With this setup, users in the sftp group are chrooted to /sftp_files/chroot_sftp. There is a single entry in a file in /etc/rsyslog.d/25-sftp.conf for the /sftp_files/chroot/dev/log file. Because /sftp_files/chroot_sftp/home has the unusual 710 permissions, users cannot list the directory, but they can access any file whose name they know, assuming that the permissions on that particular file allows it. Also, I create these sftp users with sftp as their only (and shared) group.
I also use public keys, so the regular /home/user1/.ssh/authorized_keys file exists. (I use /etc/skel with an empty file to have the file created with the appropriate permissions.) This could go in /sftp_files/authorized_keys/user1 instead, with authorized_keys as root.sftp 710, and user1 as user1.sftp 700. That breaks /etc/skel for the authorized_keys file, however.
I have NOT tested what follows.
For your shared directories, what I would do is add a few more items:
-
-
-
-
- /shared_dirs <- link to /shared_dirs, which inside the chroot will go to ...
-
-
- /shared_dirs 750 root.sftp <- here. Contents visible to all, however...
-
-
-
- /sd_1 770 root.sg1 <- only accessible to members of group sg1.
The link /shared_dirs is a convenience so that users don't have to remember the name of a directory that they cannot see. Alternatively, shared_dirs could also have 710 permissions, and you create a link for each shared directory that a users should be able to access.