I recently have been working on remote linux machine and had permission issues due to the setup and it not seeing me as in the group locally. (sshfs mount)

Here is what I came up with.

#!/bin/bash
# set group and default username
sudo chown -R username:group /var/www/vhosts
# group sticky bit so files retain group permissions
sudo find /var/www/vhosts -type d -exec chmod g+s {} \;
# read / write for group and owner, read for other
chmod -R 0664 /var/www/vhosts
# set all the directories to be accessible
# directories need to be executable
sudo find /var/www/vhosts -type d -exec chmod 775 {} +
# set all executable php and bash files to be executable by group and user
sudo grep -R '#!/' * | awk -F ":" "{print \$1}" | xargs chmod 0774

I also had to mimic the groupid on my local machine and add my user to that group.

2 Spice ups

Not sure if I understand your problem, but what I find weird is that you first add sgid to directories:

sudo find /var/www/vhosts -type d -exec chmod g+s {} \;

and then remove it with next command:

chmod -R 0664 /var/www/vhosts

If you use ‘0664’, ‘0’ in it will remove sgid. Instead, add a sgid bit in fourth command’s permission set with ‘2775’.
Another issue: why aren’t you using sudo in 3rd command? It seems indispensable here.
And last one: I guess sudoing grep in last command won’t do a thing, because final

xargs chmod 0774

in a pipe is not prefixed with sudo, and that’s where you most likely need privileges.

1 Spice up