There are two commands that are important here: chmod and chown, see also this bash script:
chown
sets the file/folder ownership
chmod
set the folder/file rights
www-data
is the default Apache webserver user.
The script itself would have to be adapted for Kirby 3 folder names.