Solved

File permissions - cgi etc

Posted on 1998-09-03
9
617 Views
Last Modified: 2013-12-16
As a complete Unix newbie who's just been given the keys to a virtual server, I'm confused by file permissions for cgi scripts.  Having set up my cgi-bin directory and uploaded some scripts, I can't work out which chmod setting to give them.  And how do I prevent access to the directory while still permitting the right level of access to the scripts?  Can I just password protect the directory using the .htaccess file, or will that prevent access to the script functions?  I've been given several conflicting opinions on this, so I need an answer that is guaranteed to work (ideally one that someone can show me is working on their own server).
0
Comment
Question by:Polemic
9 Comments
 
LVL 4

Expert Comment

by:jlms
ID: 1812156
For scripts that have to run you can give permissions like this:
711  read, write an execute for the owner and execute for th rest of the world.

511 read for the owner of the script an execute for the rest of the world.

111 execute for everybody, no read or write permission.

Now, to block access to the directory (understanding access like the possibility to modify things in the directory) youc can change the permissions of the cgi-bin directory to:

755 that is owner can modify, but the rest of the world can change to the diretory but cannot modify anything inside the dircetory.

You can use these numeric values for chown or the equivalent letter codes.


0
 

Author Comment

by:Polemic
ID: 1812157
jlms:

Okay, so which permission, specifically, should I use for:

- form to mail
- polling
- www board
- html chat
- visitor logging

and similar scripts?  Is making them only executable for the rest of the world (711) okay?  What if the script in some way needs to  create or update files?  I was told they'd then have to be 777.

755 seems to be the general consensus for the directory, but I'm getting conflicting advice for the scripts themselves.

You'll have to excuse my ignorance here, but we may as well be speaking a foreign language, and I need a sure-fire guaranteed-to-work answer where I can install a script not have to guess the correct chmod.



0
 

Author Comment

by:Polemic
ID: 1812158
I've rejected jlms' answer because I need a definitive response.  I'm not equipped to choose between three or four options because I don't have sufficient understanding of the likely effects.  What I need is someone to tell me either "install them and chmod them xxx" or alternatively a list of "if... then..." answers which will allow me to easily choose which chmod setting to use on a particular script.  jlms, you're welcome to re-submit your answer in this form, but having not heard from you for a few days I felt it only fair to let others have a go at answering.
0
 
LVL 1

Expert Comment

by:TSchock
ID: 1812159
Permissions
"How do I stop people who are not in my group from reading a directory?"
Type chmod o-r directory while you are in the directory above it.
"How do I stop people who are not in my group from writing to a directory?"
Type chmod g-w directory while you are in the directory above it.

How do I run my own CGI programs?
Put your CGI programs in the cgi-bin directory you will create in any directory. Make sure you upload them in ASCII mode.
Change permissions to 755 for the script (chmod 755 script-name)
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Polemic
ID: 1812160
Sorry, but this isn't the comprehensive answer I'm looking for.  What is my "group"?? As I said I have no real knowledge of this topic at all, and need a kind of if... then... or something else to which I can refer.

I have the directory, and I have its permission set to 755.  What should I do with the scripts in it?  Do different cgi scripts need different permissions?  If so, how do I determine what permission to set and exactly what is that permission, in the format "chmod XXX" please?

And is it necessary, having set permission on the directory to 755, to restrict access to it via .htaccess, or will that prevent the scripts inside it from being executed?

0
 
LVL 1

Expert Comment

by:turnkey
ID: 1812161
Polemic:

What web server are you using (e.g. Apache, NCSA, etc.)?

Where are your htdocs run from (e.g. /var/www/domain/htdocs)?

Where are your cgi's run from (e.g. /var/www/domain/cgi-bin)?

Once I get an answer, I will post the exact syntax for you to type in order to protect your server, the cgi's, etc., etc.

Regards,
turnkey
0
 

Author Comment

by:Polemic
ID: 1812162
turnkey:

I'm told it's an Apache server.  That's all the info I was able to get from the manual - if you need more, tell me what commands to enter to get the server to list the version etc etc.

Now, paths:
ht docs: usr/local/etc/httpd/htdocs/polemic
cgi's: usr/local/etc/httpd/htdocs/polemic/cgi-bin
perl: /usr/bin/perl

I finally got some scripts running, but only by deleting the .htaccess file from the cgi-bin directory.  Keeping it there was giving me "500 Server Error" messages.

And I'm still getting conflicting advice from the various scripts readme's as to the right chmod - most seem to say 755, with the odd data.txt file and suchlike to 777, but others say different.

Hope that's what you wanted to know, turnkey.  If not, I'll do my best to track down other relevant info if you give me some idea how to get it.

Thanks, Polemic

0
 
LVL 1

Accepted Solution

by:
turnkey earned 150 total points
ID: 1812163
Polemic:

Great, the Apache webserver is the most widely used on unix operating systems.  The Apache webserver is usually run as user "nobody" and group "nobody" (this is the default and is configured by the httpd.conf file located in /usr/local/etc/httpd directory).  Below is a step-by-step outline on configuring your directories, files, cgi's, etc. to get everything working properly.  You do not need to password protect the cgi-bin directory (with .htaccess and .htpasswd directives) because Apache forbids browsing access within the directory by default.

Enter the commands into your system EXACTLY as I have listed below (without the # prompts, of course) and hit <RETURN> after each command.  You need enter these commands as the root user.  

Alright...Here we go:

1).  Change to the polemic directory by typing the following:
     #cd /usr/local/etc/httpd/htdocs/polemic

2).  Change permissions on the sub-directories by typing:
     #chmod 755 *

3).  Change permissions on the "." and ".." dirs by typing:
     #chmod 755 .
     #chmod 755 ..

4).  Change to the cgi-bin directory by typing:
     #cd cgi-bin

5).  Change permissions on the files in the cgi-bin by typing:
     #chmod 755 *

6).  Change group/owner of your cgi scripts to nobody/nobody.
     Doing this ensures that the Apache web server (which, as
     mentioned above, runs as user "nobody" and is a member if
     the group "nobody") is the only user that is actually given
     full access to the cgi scripts.  You should substitute
     "my.cgi" with the actual name of your cgi script file.
     Repeat the commands for each additional cgi script that you
     have currently or after you install any new scripts
     (e.g. mailform.cgi, polling.cgi, chat.cgi)
     #chown nobody:nobody my.cgi
     #chmod 755 my.cgi

7).  Just to be sure, let's verify that your htdocs files are
     also set to the correct permissions.  Type:
     #cd /usr/local/etc/httpd/htdocs/polemic/htdocs
     #chmod 755 .
     #chmod 755 ..
     #chmod 666 *

8).  O.K., that's everything.  Basically, what we've done is ensured that the cgi's can only be manipulated by the user nobody.  The scripts will interact with other binaries as written without problem.  You should now re-start the Apache web server so that the changes in permissions are seen by Apache.

If you have any questions or problems, please let me know ASAP.

Regards,
turnkey
0
 

Author Comment

by:Polemic
ID: 1812164
Thanks turnkey.  The only problem I'll have with this is that I doubt very much that they'll restart the server for me because other sites are on it as well and they're always telling me that I mustn't do anything to interrupt their service.  But that's not your fault - it's a comprehensive easily understandable answer that even I can understand!  Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now