1

I'm trying to set a small webserver for personal use. I have a fodler /srv/http/cgi-bin/ which I want to edit as user and not superuser. I tried to chmod it as mentioned here. Here is the result:

sudo chmod 755 /srv/http/cgi-bin/ -R
[yotam@myhost ~]$ echo "h" >> /srv/http/cgi-bin/h.py
bash: /srv/http/cgi-bin/h.py: Permission denied

Edit:
Here is some data due to the comments and answers:

[yotam@myhost ~]$ sudo chmod 760 -R /srv/http/cgi-bin 
Password: 
[yotam@myhost ~]$ echo "hh" >> /srv/http/cgi-bin/h.py
bash: /srv/http/cgi-bin/h.py: Permission denied
[yotam@myhost ~]$ ls -ld /srv/http/cgi-bin
drwxrw---- 2 root root 4096 May 20 15:54 /srv/http/cgi-bin

Also, the server is Ubuntu desktop running apache2. As far as I can tell, I didn't temper with any of the user settings so it all should be the default parameters

5
  • can you ls -l /srv/http/cgi-bin/h.py ?
    – zmo
    May 20, 2012 at 13:13
  • Try ls -ld /srv/http/cgi-bin and ls -l /srv/http/cgi-bin/h.py and paste the result. You probbaly have the -R flag in the wrong place. It needs to come first.
    – Matt K
    May 20, 2012 at 13:14
  • 1
    it mostly depends if it's gnu chmod or bsd chmod. if it's bsd chmod it's at the wrong place, but chmod should have failed with "chmod: -R: No such file or directory" whereas gnu chmod should have succeeded and 755 is rwxr-xr-x
    – zmo
    May 20, 2012 at 13:15
  • The easy answer is if I just tell you to do chmod 777, but that will be a very irresponsible answer. To answer your question properly, without risking the security of your server, you need to know a couple things about your existing server configuration. What is the user group of the web server (presumably Apache) process is running as? What is the user group of the user that the Apache process is running as? Should the web server be able to edit this file, e.g. on behalf of web user? And what is the user group of your current user? What is the owner and group of the file?
    – Lie Ryan
    May 20, 2012 at 13:45
  • Your understanding of what the permIssions mean seems out of whack. Your sudo chmod works fine; but it grants the owner (apparently root) write permission, not you. It's not clear how exactly to solve this; my suggestion would be to copy the file, edit the cooy, use sudo to replace the original with your edited version.
    – tripleee
    May 21, 2012 at 9:13

2 Answers 2

1

The mode string seems wrong. The mode string 755 means that

  • The owner of the file can read (4), write (2) and execute (1) - 4+2+1 = 7
  • Any member of the file's group can read (4) and execute (1) - 4+1 = 5
  • Anyone else can read (4) and execute (1) - 4+1 = 5

It looks like you want chmod -R 766 /src/http/cgi-bin, but this seems like a very unsafe permission setting...

2
  • 2
    indeed it's unsafe, it'd be better to play with groups or user (i.e. "chown yotam:www-data h.py" and "chmod 775 h.py" or the other way around, "adduser yotam www-data" and let the permission as is)
    – zmo
    May 20, 2012 at 13:17
  • Thank you for your answer. I tried this without improvement.
    – Yotam
    May 20, 2012 at 15:22
0

you can temporarily change the ownership to yourself , edit the file and change it back.

sudo chown -R yotam /srv/http/cgi-bin/ 

edit file (as user, not superuser as you required)

sudo chown -R root /srv/http/cgi-bin/
2
  • Sure I can do this. I don't want to. This is another thing to do. Further more, this should work. I could also create a link to a file in other folders...
    – Yotam
    May 21, 2012 at 7:01
  • changing ownership is safer than changing permissions, and many web servers do not follow symlinks.
    – pizza
    May 21, 2012 at 9:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .