Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change permissions to a socket?

I am trying to run a simple Python based web server given here.

And I get the following error message:

Traceback (most recent call last):
  File "webserver.py", line 63, in <module>
    main()
  File "webserver.py", line 55, in main
    server = HTTPServer(('', 80), MyHandler)
  File "/usr/lib/python2.5/SocketServer.py", line 330, in __init__
    self.server_bind()
  File "/usr/lib/python2.5/BaseHTTPServer.py", line 101, in server_bind
    SocketServer.TCPServer.server_bind(self)
  File "/usr/lib/python2.5/SocketServer.py", line 341, in server_bind
    self.socket.bind(self.server_address)
  File "<string>", line 1, in bind
socket.error: (13, 'Permission denied')

As far as I understand my firewall blocks access to a socket? Am I right? If it is the case, how can I change the permissions? Is it dangerous to change these permissions?

like image 524
Roman Avatar asked Feb 23 '10 22:02

Roman


2 Answers

If you want to bind to port numbers < 1024, you need to be root. It's not a firewall issue; it's enforced by the operating system. Here's a reference from w3.org, and a FAQ entry specific to Unix.

like image 140
Jim Lewis Avatar answered Sep 30 '22 02:09

Jim Lewis


If you want to run on a port under 1024, you'll need to be root. You can open the socket and drop root's permission for the rest of your program by switching to another user.

Most times it's easier to run a real webserver (say nginx) on port 80 and proxy the requests through to your program which you can run on a high numbered port (8080 for example). This way you don't need to worry about screwing something up during the time your process is running as root, as it never runs as root.

If it's just for testing, run the server on port 8080 and connect at http://localhost:8080/

like image 44
John La Rooy Avatar answered Sep 30 '22 03:09

John La Rooy