remove 777 permissions on all root web directories? How?

jols

Well-Known Member
Mar 13, 2004
1,107
3
168
Is there a script that I can run (safely) on the server which will change permissions from 777 to 775 on all directories that are directly in vsite accounts' root web area?

I am completely burned out with warning people that their directories have not been permissioned securly.

Thanks very much for any response.
 

lostinspace

Well-Known Member
Jul 19, 2003
122
1
168
Colorado Springs, CO
Might not be exactly what you want but:

Just cd to the directory in question (cd /home/user/www)

then...

CHMOD all directories:
Code:
find . -type d -exec chmod 755 {} \;
CHMOD all files:
Code:
find . -type f -exec chmod 644 {} \;
 

jols

Well-Known Member
Mar 13, 2004
1,107
3
168
Thanks for that. It helps a little. I was hoping for some kind of cPanel /scripts/ script to just run through all the accounts and do this to only directories that are in the web root, and had been permissioned to 777. But I'm probably wishing for too much here.

I suppose to make up some kind of shell script that only acts on directories that are 777, I would need some kind of IF / THEN test, i.e. IF directory (name) is 777, then chmod 755.

Anyone have any advice about setting up a basic directory permissions, 777 detection script?
 

verdon

Well-Known Member
Nov 1, 2003
945
16
168
Northern Ontario, Canada
cPanel Access Level
Root Administrator
I'm not sure how handy you are with perl scripts, but I've used the following example to craft a number of small scripts to loop through user dirs and find/fix things, and I'm not that skilled with perl ;)

The following script is meant to go through your user dirs and create a 404 file if none exists. I find it a good reference point...

http://www.cplicensing.net/scripts.php?file=fix404errors
 

jols

Well-Known Member
Mar 13, 2004
1,107
3
168
Great! Thanks!

Yes, that's a really good reference for getting the basic thing going that I need to so. The only thing missing for my particular project is some sort of a permissioin detection routine, e.g. IF the directory is 777, THEN do the chmod 755 thing.

Anyone have any clues about setting up this needed routine?
 

sparek-3

Well-Known Member
Aug 10, 2002
2,150
265
388
cPanel Access Level
Root Administrator
You should be able to use something like

find <path> -type d -perm 0777 -exec chmod 755 {} \;

Where <path> is the path that you want to search.

For example to search through the entire /home directory for this setup, you can use:

find /home -type d -perm 0777 -exec chmod 755 {} \;

or for a specific user

find /home/user -type d -perm 0777 -exec chmod 755 {} \;
 

jols

Well-Known Member
Mar 13, 2004
1,107
3
168
Hey, thanks. I have not used the Find command much as you could no doubt tell. If Find recurrses into the /home directories, up (down?) through the hirarchy, then this may not help much if we were just aiming at the directories that are "directly" in the root web, i.e. and not all the sub-directories thereafter.
 

Spiral

BANNED
Jun 24, 2005
2,018
8
193
Hey, thanks. I have not used the Find command much as you could no doubt tell. If Find recurrses into the /home directories, up (down?) through the hirarchy, then this may not help much if we were just aiming at the directories that are "directly" in the root web, i.e. and not all the sub-directories thereafter.
find /home/*/public_html -type d -perm 0777 -exec chmod 755 {} \;
 

sparek-3

Well-Known Member
Aug 10, 2002
2,150
265
388
cPanel Access Level
Root Administrator
Use the -mindepth and -maxdepth arguments

For example to just find directories that are 0777 in the public_html folders for all users in /home:

find /home/*/public_html -maxdepth 1 -type d -perm 0777 -exec chmod 755 {} \;

It takes a little while to get used to the find parameters and arguments. I'm not that good at the command. But once you figure out how to use it, it can become a very valuable tool for administration purposes.