The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

remove 777 permissions on all root web directories? How?

Discussion in 'General Discussion' started by jols, Jun 25, 2007.

  1. jols

    jols Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,111
    Likes Received:
    2
    Trophy Points:
    38
    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.
     
  2. lostinspace

    lostinspace Well-Known Member

    Joined:
    Jul 19, 2003
    Messages:
    122
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    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 {} \;
     
  3. jols

    jols Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,111
    Likes Received:
    2
    Trophy Points:
    38
    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?
     
  4. verdon

    verdon Well-Known Member

    Joined:
    Nov 1, 2003
    Messages:
    836
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    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
     
  5. jols

    jols Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,111
    Likes Received:
    2
    Trophy Points:
    38
    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?
     
  6. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,381
    Likes Received:
    23
    Trophy Points:
    38
    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 {} \;
     
  7. jols

    jols Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,111
    Likes Received:
    2
    Trophy Points:
    38
    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.
     
  8. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    find /home/*/public_html -type d -perm 0777 -exec chmod 755 {} \;
     
  9. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,381
    Likes Received:
    23
    Trophy Points:
    38
    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.
     
Loading...

Share This Page