Results 1 to 25 of 25
  1. #1
    Join Date
    May 2009
    Posts
    35

    Question How to chmod 777 recursively for files underneath a folder?

    Hello,

    I like to ask what should I do if I like to chmod 777 recursively for files underneath a folder.

    Thank you!

  2. Thread Summary Permission issues can be tricky on Linux, especially when you want to change the permissions for all files inside a folder as WHT member x264-BB is hoping to do. By default, the "chmod" (Wikipedia) command in Linux only changes permissions for the folder you specify -- not every file inside.

    The right way to go about doing this is to recursively (-R) run the chmod command. For example:

    PHP Code:
    chmod -R 777 /home/admin/domains/domain_name/public_html/folder
    However, several members have also brought up a security concern with 777 permissions on files and folders as that essentially grants open-ended access to those files for all users on the server. Whether that's a real problem depends largely on how your server environment looks like, but generally speaking, 777 permissions can be risky.

    tim2718281 suggests a few workarounds for 777 permissions that won't compromise your server security:

    1) either to have the script run by a user in the group that owns the files, and have the files writable by group. (So chmod 775 rather than 777).

    2) or have the script run as the user that owns the files (see SUID in Linux). This was actually a brilliant idea by the inventors of Unix; an executable file with the SUID set (chmod +4) runs as the owner of the file, rather than the user who executes it.

    Contributors: Orien

  3. #2
    Join Date
    Nov 2003
    Location
    Kherson, Ukraine
    Posts
    267
    Code:
    # chmod --help
    Usage: chmod [OPTION]... MODE[,MODE]... FILE...
      or:  chmod [OPTION]... OCTAL-MODE FILE...
      or:  chmod [OPTION]... --reference=RFILE FILE...
    Change the mode of each FILE to MODE.
    
      -c, --changes           like verbose but report only when a change is made
          --no-preserve-root  do not treat `/' specially (the default)
          --preserve-root     fail to operate recursively on `/'
      -f, --silent, --quiet   suppress most error messages
      -v, --verbose           output a diagnostic for every file processed
          --reference=RFILE   use RFILE's mode instead of MODE values
      -R, --recursive         change files and directories recursively
          --help     display this help and exit
          --version  output version information and exit
    Private remote administrator of Linux servers - www.petrov.ks.ua
    Quality hosting - Host-Web-Site.com

  4. #3
    Join Date
    May 2009
    Posts
    35
    Sorry, I'm really new at this.

    For example, this folder:

    /home/admin/domains/domain_name/public_html/folder/


    What should I type in SSH as root?

    Thanks...

  5. #4
    Join Date
    Dec 2005
    Location
    Berkshire, UK
    Posts
    3,077
    I wont give you the answer because running 777 permissions on all files in a directory is completely insecure.

    Why do you need to give everything read, write and execute permissions to all users?
    System Administrator (RHCE, LFCS, cPPC::Tech)
    PCSmart Group.

  6. #5
    Join Date
    May 2009
    Posts
    35
    I have a script on ftp that allows to change md5 harsh to files but the only way to have the files writable. Is there anyway that I can do it without making the it as insecure as what you mentioned? Maybe another chmod command? thanks....

  7. #6
    Join Date
    Apr 2003
    Location
    San Jose, CA.
    Posts
    1,622
    If you don't even know how to use the chmod command...
    having root access is your first problem. You're a child playing with a loaded firearm.

    Most people reply back saying, 'oh this is just a dev box... and the content doesn't matter'.

    Well then a) figure out how to administrate a machine before you play around online, or b) have someone do the administration for you who can alternatively explain why what you are trying to do is possibly a dumb idea.

  8. #7
    Join Date
    Aug 2002
    Location
    Milton Keynes
    Posts
    352
    Quote Originally Posted by Lightwave View Post
    having root access is your first problem. You're a child playing with a loaded firearm.
    Ahaha, I couldn't have put it better myself!

  9. #8
    Join Date
    May 2009
    Posts
    35
    Anyone can enlighten me other than sarcasm?

    I know how to access root, & I'm learning... somewhere before u knew everything u were a baby too, come on... give me some serious help... thanks!!!

  10. #9
    Join Date
    May 2009
    Posts
    35
    To make things more clear, this is what I need to do:

    1) I have files uploaded to my server into a folder occasionally
    2) They need to be writable
    3) So, my script can add 1kb to each file to change their md5 harsh
    4) Then I re-upload via FTP to another server that need those files with their md5 harsh changed

    Currently Situation
    Each time I upload the needed files to the server, I must access FTP to chmod them to writable before I can utilize the script.
    Now, I'm seeking for professional help from professional people inside here and hoping to find out how professional the answers can be rather than professional sarcasms.
    Anyone who can offer me help here will be deeply appreciated and at least the true professional. Thank you.
    Last edited by x264-BB; 04-10-2010 at 10:06 PM.

  11. #10
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    197
    giving public accessible folder 777 permission insecure, but if you need to know read this

    http://www.unixref.com/guides/chmodGuide.html
    Affordable Linux Server Managament Solution
    To order : http://www.linuxnetworkcare.com
    Contact :[ AIM : xerophytev] [MSN : support@linuxnetworkcare.com][ Phone : 647-722-5303 ][skype:ksutha5]

  12. #11
    Join Date
    May 2009
    Posts
    35
    xerophyte, i totally understand that. thanks!

    But it is an hassle to have files to be chomd writable before I run my script. After having those files made writable, re-uploaded to another server, they will be deleted via the md5 changer script.

    So, I'm looking for a solution which I can skip the steps of connecting to FTP, select the files, chmod them all to 777 then finally run my script, so that each time new files uploaded are being made writable automatically then I run the script to have their md5 harsh changed then re-uploaded to another server that needs them. This way, it improves my productivity.

    Thanks!

  13. #12
    Join Date
    Apr 2003
    Location
    San Jose, CA.
    Posts
    1,622
    What's sad is you think it's sarcasm.
    At some point you'll probably get hacked, all your files deleted...
    and maybe then you'll get the idea that you don't know what you're doing.

    You're not looking for a professional answer from a professional.
    You're looking for the lazy free answer that suits your needs.

    Your question amounts to, "How do I do something stupid?"
    Professionals are telling you simply, "You don't".

    To go back to my earlier analogy, you're asking "How do I load this gun?"
    People are telling you, "If you don't know how to load a gun, you shouldn't be handling one."

    I'm sorry that's not the answer you're looking for.

  14. #13
    Join Date
    Jun 2004
    Location
    Oregon
    Posts
    1,273
    i don't think it's possible to automatically chmod unless you run a chmod command via cron.
    if you run DA+php i would suggest you run them as fastcgi so you don't need to chmod files to make them writable.

  15. #14
    Join Date
    Oct 2009
    Location
    India
    Posts
    123
    hi. giving 777 permissions in public directory is not advised..
    but if you want for some reason
    PHP Code:
    chmod -R 777  /home/admin/domains/domain_name/public_html/folder
    and to learn more about chmod
    type man chmod in terminal

    again giving 777 permissions to files in public directory is not a good idea.
    What happens to cloud when it rains ?

  16. #15
    Join Date
    Mar 2009
    Posts
    2,218
    Quote Originally Posted by x264-BB View Post
    To make things more clear, this is what I need to do:

    1) I have files uploaded to my server into a folder occasionally
    2) They need to be writable
    3) So, my script can add 1kb to each file to change their md5 harsh
    4) Then I re-upload via FTP to another server that need those files with their md5 harsh changed

    Currently Situation
    Each time I upload the needed files to the server, I must access FTP to chmod them to writable before I can utilize the script.
    Now, I'm seeking for professional help from professional people inside here and hoping to find out how professional the answers can be rather than professional sarcasms.
    Anyone who can offer me help here will be deeply appreciated and at least the true professional. Thank you.
    The -R option on chmod changes files and directories recursively, so that's the answer to your question. See "man chmod".

    However, the normal way achieve what you to achieve is:

    1) either to have the script run by a user in the group that owns the files, and have the files writable by group. (So chmod 775 rather than 777).

    2) or have the script run as the user that owns the files (see SUID in Linux). This was actually a brilliant idea by the inventors of Unix; an executable file with the SUID set (chmod +4) runs as the owner of the file, rather than the user who executes it.

    It's worth spending the time to learn about both of these methods. They make it possible to do all just about everything automatically and securely, without a human signing in and executing commands.

    However, some Linux distributions disable SUID for shell scripts, so to use this method from a shell script may take a bit more work. Here's a link with more on this

    http://www.tuxation.com/setuid-on-shell-scripts.html
    Last edited by tim2718281; 04-11-2010 at 03:51 AM.

  17. #16
    Join Date
    May 2009
    Posts
    35
    tim2718281, thanks for the great reply! brilliant.... u r a real pro!!!

  18. #17
    Join Date
    Feb 2005
    Location
    United Kingdom
    Posts
    2,898
    Quote Originally Posted by x264-BB View Post
    I have a script on ftp that allows to change md5 harsh to files but the only way to have the files writable. Is there anyway that I can do it without making the it as insecure as what you mentioned? Maybe another chmod command? thanks....
    another way to do your task, it's temporary set the chmod using your script at the end of script task change chmod back.
    UK Professional Web Development & Web Hosting/VPS solutions at web-project.co.uk
    VPS Price Match Guarantee on: All our range of DDOS protected XEN HVM VPS
    == Contact us for any online solution development or managed / unmanaged vps hosting ==

  19. #18
    Join Date
    Feb 2008
    Location
    Jakarta
    Posts
    153
    It doesn't have to be 777 - Probably, depend on your server config.

    Quote Originally Posted by x264-BB View Post
    1) I have files uploaded to my server into a folder occasionally
    I assume you upload the script using http? perhaps via php script?, first, investigate who is the owner of the file after you upload, then you can decide what is the minimum ownership for your script to do the thing it need to do later.

    Quote Originally Posted by x264-BB View Post
    2) They need to be writable
    3) So, my script can add 1kb to each file to change their md5 harsh
    Investigate who need the write access, for example if your script (ex. php) run as an Apache Module, then the user runs the httpd process need write access.

    Quote Originally Posted by x264-BB View Post
    4) Then I re-upload via FTP to another server that need those files with their md5 harsh changed
    Not sure what you mean by this .

    I am fully agree with the previous comment saying don't use 777 , it is better to encourage your self for a different config which doesn't required a 777 permission just to write something from an internal script.
    Magnet Hosting | Layanan Hosting dan Server Indonesia
    http://www.magnet-id.com Indonesian Data Center, Peering with IIX and openIXP

  20. #19

    ugh

    I can't resist the urge to be a bit of a troll here and say that this guy needs to take it easy on the poor bloke asking a question. One "you don't know what you're doing" reply is enough. A computer is NOT a loaded gun, and as long as its circuits are properly shielded in a case, it poses very little physical danger. I feel like UNIX/Linux elitists like Lightwave are lording their superior knowledge over the otherwise bright-eyed newbies with nerdy diatribes like that, and the hypothetical trauma of potentially getting hacked because of using chmod -R irresponsibly will NOT put a bleedin' hole in your body. So, one warning is enough. If he heeds it great, if he doesn't, he does so at his own risk, but that is exactly how you learn.

    Quote Originally Posted by Lightwave View Post
    What's sad is you think it's sarcasm.
    At some point you'll probably get hacked, all your files deleted...
    and maybe then you'll get the idea that you don't know what you're doing.

    You're not looking for a professional answer from a professional.
    You're looking for the lazy free answer that suits your needs.

    Your question amounts to, "How do I do something stupid?"
    Professionals are telling you simply, "You don't".

    To go back to my earlier analogy, you're asking "How do I load this gun?"
    People are telling you, "If you don't know how to load a gun, you shouldn't be handling one."

    I'm sorry that's not the answer you're looking for.

  21. #20
    Join Date
    Mar 2003
    Location
    Jaipur, India
    Posts
    632
    Hi,

    sometimes, you need to apply 644 to all files and 755 to all directories, then i think you should use these commands :-

    #find . -type d -exec chmod 775 {} \;
    For all directories

    #find . -type f -exec chmod 644 {} \;
    For all files
    ZNetLive
    Web Hosting for Designers & Developers

  22. #21
    Join Date
    Mar 2009
    Location
    Chicago, IL
    Posts
    219
    Please stop now.

    Quit executing random commands that people on this forum are giving you. At no point in this thread have I seen enough information offered, nor the right questions asked for any of these suggestions to be appropriate.

    1. 777 Permissions are a horrible hack, but in some environments, necessary (find a new environment).
    2. Your script that modifies them, we'll need to know what user this is running as. Is it a PHP script running as nobody or as your user? Is it another sort of script running as your user?
    3. When you connect via FTP, are you using the username for your hosting account?

    The "right" want to handle this is to have the user that modifies these files be the same user that uploads them. That negates the need for 777 permissions in the first place and is the 'right' way to handle this.

    Anyway, if you could answer those questions, that'd let us help you out better. And please quit running commands from random people on the internet.

  23. #22

    Angry wow

    Quote Originally Posted by PCS-Chris View Post
    I wont give you the answer because running 777 permissions on all files in a directory is completely insecure.

    Why do you need to give everything read, write and execute permissions to all users?
    I don't know how I stumbled onto this forum. But I joined it to simply make this comment.

    PCS-Chris, Lightwave, and drspliff you are all PUTZs. You can not simply answer a question but rather you prefer to show your arrogance and illiteracy by assuming you have any idea what his application or use of the command would be? Your statements are simply not true and your false sense of competency and accomplishment are hilarious.

    xerophyte, Vamsii and tim2718281 handled the response as it should be. The correct answers with explanation and a word of caution.

    x264-BB the more you learn about Unix and the other varieties the more you will get drawn in and hopefully help others. Be sure not to develop the arrogant, know it all attitude of these three knuckleheads. I have been a system admin with Unix in all it's varieties for over 20 years an am published on the subject. I would never assume to know everything let alone assume I can save the world by not answering someones question. Specially assuming I have a clue to their application of the knowledge. Good luck.

  24. #23
    Join Date
    Mar 2005
    Location
    Ten1/0/2
    Posts
    2,509
    What I find weird is that someone with their first post does a drive-by on a 2 1/2 year old long-forgotten thread...

    Even weirder is that yet another first poster does the same.
    CPanel Shared and Reseller Hosting, OpenVZ VPS Hosting. West Coast (LA) Servers and Nodes
    Running Linux since 1.0.8 Kernel!
    Providing Internet Services since 1995 and Hosting Since 2004

  25. #24
    Join Date
    Sep 2012
    Location
    Sydney, Australia
    Posts
    7

    Wrote a recursive chmod script

    So I went trawling the web for an elegant and simple solution to this and decided to write a little script for this myself.

    It basically does the recursive chmod but also provides a bit of flexibility for command line options (sets directory and/or file permissions, or exclude both it automatically resets everything to 755-644). It also checks for a few error scenarios.

    Check it out:
    http://bigfloppydonkeydisk.blogspot....-files-or.html

    Hope it helps!

  26. #25

    Simple Question

    Wow, I am amazed at the rudness and negative comments toward this man that just asked a simple question. He was not asking your personal opinion on sevrer security, he just wanted to know how to do something. I got to this forum because I was looking for the same answer but instead I get a bunch of useless lame negative comments.

  27. Newsletters

    Subscribe Now & Get The WHT Quick Start Guide!

Similar Threads

  1. /tmp folder 777 ... use as sessions folder... secure?
    By marikas in forum Hosting Security and Technology
    Replies: 3
    Last Post: 08-14-2007, 05:27 AM
  2. is it safe to chmod your public_html folder to 777?
    By strato in forum Web Hosting Lounge
    Replies: 18
    Last Post: 10-21-2006, 06:13 PM
  3. PHP files altered, chmod 777 .htaccess
    By NetHosted-Andrew in forum Hosting Security and Technology
    Replies: 2
    Last Post: 01-23-2006, 02:37 PM
  4. Pleas help need to run .cgi files in a /777/ folder with cpanel???
    By DWHS in forum Hosting Security and Technology
    Replies: 5
    Last Post: 03-18-2003, 06:32 PM
  5. chmod 777
    By banihani in forum Hosting Security and Technology
    Replies: 5
    Last Post: 09-05-2001, 07:27 PM

Related Posts from theWHIR.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •