I have a HostGator dedicated server running CentOS. I have a folder on one user's account where I want all users to be able to have read access, so we keep it chmod'd to 755. HG has a script that runs and changes these permissions. I had them disable that script, but they also changed an attribute so that the folder was append only, making it impossible to delete a file. They gave me the command to toggle that attribute, but I don't want to have to open a shell every time I want to delete a file from FTP. Is there another way of making it so that I can use that directory like normal, but prevent the permission from being changed?

EDIT: After a little back and forth, HG and I have come up with this cronjob that isn't quite right yet. I have an open ticket with them, but sometimes this awesome community is faster.

if [[ "stat -c "\%a" /home/user/folder" != "755" ]]; then echo -e "Perm Changed\n" $(stat /home/user/folder) "\n" | mail -s "cron" addy@email.com; chmod 755 /home/user/folder; fi

The conditional statement isn't correct and I suspect the quotation marks are out of place but I don't know enough of this syntax to be sure. Can anyone spot the error here? It is supposed to check the permission of the folder. If they are not 755, then send an email and change the permissions. What I get is as if the condition is alway true.

  • 3
    The real solution is not to run this script. Since you have a dedicated server, you should be able to control what runs on it. Aug 8 '12 at 1:29
  • Yeah, "should be".
    – TecBrat
    Aug 8 '12 at 1:30
  • It's not the end of the world if it changes, but it's a pain when it does. The last HG admin set the perms of the "perms" script to 000, so hopefully that's enough. I'll chattr -a that dir and see what happens.
    – TecBrat
    Aug 8 '12 at 1:32
  • Run ls -Z on the directory and post the output. This will give you permissions, ownership, and SELinux details. You may be able to set something up using SELinux to do what you're thinking. Also, you could change the user ownership to your user, create a group to put the other users in, and change the group ownership to that group. Then modify the permissions for the group accordingly. Scripts that run as root, though, will still have full access unless set under a restricted SELinux property or chmodding it to 000 like they've already done, which won't allow it to run. Aug 8 '12 at 6:18

Make a cron job that checks the permissions and corrects it. Have it run once per minute.

For diagnostics and a work around in one, use this cron that checks for the desired permissions. If they are not found, it sends an email with the results of stat and then corrects the permissions.

if [[ $(stat -c "\%a" /home/user/folder) != "755" ]]; then echo -e "Perm Changed\n" $(stat /home/user/folder) "\n" | mail -s "Permission Cron" addy@email.com; chmod 755 /home/user/folder; fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.