Had a little issue today. Wrote a script to fix it. I don’t think the script is bullet-proof & may not always work on 100% of your users. But generally speaking, I feel like it’s pretty solid. The only issue I foresee is when people customize the home directory path to be different from the domain admin username, etc.
Anyway, here it is. Hopefully it helps someone in the future (if you accidentally change ownership on some of your users) causing them to no longer have access to their email boxes:
#!/bin/bash
echo First we are setting the ownership on the parent accounts (domains)
for username in grep /home/ /etc/passwd | grep -v /homes/ | awk -F: '{ print $1 }'
do
echo Resetting ownership for: $username
useraccount=grep ^\
echo $username`: /etc/passwd homedir=
echo $useraccount | awk -F: ‘{ print $6 }’`
echo Home dir is: $homedir
echo Changing ownership of home directory recursively
chown -R $username:$username $homedir
echo Done.
echo .
done
echo .
echo Now we are setting the ownership on the child accounts (email users)
for username in grep /home/ /etc/passwd | grep /homes/ | awk -F: '{ print $1 }'
do
echo Resetting ownership for: $username
useraccount=grep ^\
echo $username`: /etc/passwd homedir=
echo $useraccount | awk -F: ‘{ print $6 }’`
echo Home dir is: $homedir
echo Changing ownership of home directory recursively
chown -R $username $homedir
echo Done.
echo .
done
By the way. I tried using virtualmin’s built-in “Fix Permissions” in the “Validate Virtual Servers” section. But it doesn’t appear to traverse to the individual mailboxes of the users in the domains. It seems to just fix the permissions & ownership for the website-related directories.