LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-29-2011, 01:25 PM   #1
webjive
LQ Newbie
 
Registered: Nov 2011
Posts: 6

Rep: Reputation: Disabled
Question Quick Bash question for a hosting company


Hey guys/gals, first time here and after searching the forums, I didn't quite find the answer I was looking for.

My question is this... I have a small hosting company and we run primarily PHP scripts with Apache and phpSuExec. I have noticed that a lot of clients are FTP'ng files up and not setting the proper permissions (644 for most files and 755 for dirs) and I would like to run a nightly cron script to fix this automatically.

What I want the script to do is scan all /home/xxx/public_html dirs and run the following commands:

Code:
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
Thoughts?

Thanks!!!!!
 
Old 11-29-2011, 01:59 PM   #2
_bsd
Member
 
Registered: Jan 2010
Location: Velveeta, USA
Distribution: Xen, Gentoo,Ubuntu,openSUSE,Debian,pfSense
Posts: 98

Rep: Reputation: 9
Instead you can set the default umask for the ftp daemon

depending on the distro and which ftp daemon is being used.

Here's an example from one of our systems

cat /etc/ftpd.conf
umask real 072

or you can edit /etc/inetd.conf
ftp stream tcp nowait root /path2yourDeamon/ftpd ftpd -u 007

Read up on umasks and Unix permissioning to get the appropriate umask
 
1 members found this post helpful.
Old 11-29-2011, 02:07 PM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
All you really have to is something like this:
Code:
#!/bin/bash                                                                                                                   
#
#       scan for public directories, change mode of all
#       files and subdirectories
#
for DIR in $(find /home -type d -name 'public')
do
        cd $(DIR)
        find . -type d -exec chmod 755 {} \;
        find . -type f -exec chmod 644 {} \;
done
Hope this helps some.

[EDIT]
Or, duh!, do what @bsd suggest!

Cripes.
[/EDIT]

Last edited by tronayne; 11-29-2011 at 02:09 PM.
 
1 members found this post helpful.
Old 11-29-2011, 02:10 PM   #4
webjive
LQ Newbie
 
Registered: Nov 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Talking

@tronayne.. Thanks! I think I can take it from here. This along with the excellent suggestion on the FTP config, we should be able to lock things down tighter...
 
Old 11-29-2011, 02:35 PM   #5
webjive
LQ Newbie
 
Registered: Nov 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
@bsd, just checked our pro-ftp server config and our umask is at 133:022 so, that would put files at 644 and directories at 755. Our challenge is users FTP'ing files have their FTP apps to set permissions after upload because we're finding php files set to 755.. ouch..

Hence the need for the script...
 
Old 11-29-2011, 03:19 PM   #6
_bsd
Member
 
Registered: Jan 2010
Location: Velveeta, USA
Distribution: Xen, Gentoo,Ubuntu,openSUSE,Debian,pfSense
Posts: 98

Rep: Reputation: 9
Don't know about that, you can fix this in a script, but users explicitly changing perms after upload? Sounds fishy to me.

I have a shared hosting acct I can upload to but, I use scp, not ftp, ftp passes passwords in cleartext.
Sounds like you might want to educate your users as well as write a script.

User tronayne's commands will fix the perms if that's the route you have to take for now.
 
Old 11-29-2011, 03:23 PM   #7
webjive
LQ Newbie
 
Registered: Nov 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Not so much fishy as ignorant to the consequences.. I have one client in particular who has a noob doing FTP and I constantly find that file permissions are often incorrect after they upload changes which sometimes means they have the wrong file/dir permissions (on upload) set incorrectly.
 
Old 11-29-2011, 06:01 PM   #8
_bsd
Member
 
Registered: Jan 2010
Location: Velveeta, USA
Distribution: Xen, Gentoo,Ubuntu,openSUSE,Debian,pfSense
Posts: 98

Rep: Reputation: 9
Again, depending on the ftpd, certain commands can be removed.
Disallow chmod if possible
 
Old 11-29-2011, 08:09 PM   #9
webjive
LQ Newbie
 
Registered: Nov 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
@bsd.. Thx.. I'll look into proftp and see if I can dis-allow ch-modding above certain levels.
 
Old 11-30-2011, 09:04 PM   #10
d3vrandom
Member
 
Registered: Jun 2006
Location: Karachi, Pakistan
Distribution: OpenSUSE, CentOS, Debian
Posts: 59

Rep: Reputation: 9
If you do this you are going to break A LOT OF your user's websites. Most popular content management systems like wordpress, drupal and even vbulletin used on this very site require 777 permissions on certain files and folders. And yes there are millions of websites out there that use these CMS and work just fine. So you are wrong to think that writeable permissions are the cause of your security holes. You need to look into things like php suexec if you want greater security. Again, if you change permissions en masse you will be inundated with support tickets!
 
Old 12-01-2011, 04:23 AM   #11
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Rep: Reputation: 78
I agree that it's *very* bad to go changing file permissions -- what if someone has set up a log file writable by apache? Lots of CMSes require write permission on a directory or file here and there. And, on the other hand, they may want to exclude access from certain files for privacy reasons.
 
Old 12-01-2011, 07:49 AM   #12
webjive
LQ Newbie
 
Registered: Nov 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
It's not a very bad idea. We have a closed hosting environment (no general hosting) and the server is specifically tuned for Joomla so, apache log files are not being written to the users /home/public_html. Its a standard cPanel environment with quite a bit of extra security software installed.

So, for those needing to FTP files, 644 and 755 for files/dirs is all they need.

Setting all the file and dir permissions on all /home/xxx/public_html accounts is the right thing to do because some of my clients did accidentally set their index.php file to 755 and some robo hacks caught that and pushed up a hack that overwrote just that one file. That's how they got in.

Last edited by webjive; 12-01-2011 at 08:53 AM.
 
Old 12-01-2011, 06:44 PM   #13
d3vrandom
Member
 
Registered: Jun 2006
Location: Karachi, Pakistan
Distribution: OpenSUSE, CentOS, Debian
Posts: 59

Rep: Reputation: 9
Quote:
Originally Posted by webjive View Post
It's not a very bad idea. We have a closed hosting environment (no general hosting) and the server is specifically tuned for Joomla so, apache log files are not being written to the users /home/public_html. Its a standard cPanel environment with quite a bit of extra security software installed.

So, for those needing to FTP files, 644 and 755 for files/dirs is all they need.

Setting all the file and dir permissions on all /home/xxx/public_html accounts is the right thing to do because some of my clients did accidentally set their index.php file to 755 and some robo hacks caught that and pushed up a hack that overwrote just that one file. That's how they got in.
Try uploading something using joomla. Add an image to a page or something. Then you'll see how you screwed up

BTW I can tell you right now what your problem is and it isn't' permissions. It's most likely because you are using an outdated version of joomla. Joomla, like most popular open source CMS, gets targeted by bots a lot so you have to keep it up to date.

Last edited by d3vrandom; 12-01-2011 at 06:46 PM.
 
Old 12-01-2011, 06:47 PM   #14
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Rep: Reputation: 78
Quote:
Originally Posted by d3vrandom View Post
Try uploading something using joomla. Add an image to a page or something. Then you'll see how you screwed up
Unless I'm mistaken, suExec will cause apache to run as whatever user owns the website rather than as www-data or apache or nobody or whatever apache usually runs as. This should generally permit a Joomla install to write whatever it needs to.

I still think changing a user's file permissions is a bad idea though.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need help in setup a web hosting company.... harsath24330 Linux - Server 8 08-18-2011 04:43 AM
Starting a Web Hosting Company sbabcock23 Linux - Newbie 4 01-16-2008 08:54 AM
A quick bash question Ander Linux - Newbie 6 05-05-2006 02:13 AM
Quick bash question neocytrix Programming 8 07-30-2004 10:23 PM
really quick bash question fibbi Linux - Software 3 06-15-2004 10:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration