Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to learn Linux better but currently only have very limited experience - so please excuse my ignorance in this matter.

I am trying to start rails on port 80, and as another user by using

sudo -u [user_name] bundle exec rails s --port=80 -e production

but this is failing with

eventmachine.rb:572:in 'start_tcp_server': no acceptor (RuntimeError)

Running sudo netstat -anltp|grep :80 shows that port 80 is not open\listening.

I have tried the following, with limited success:

sudo bundle exec rails s --port=80 -e production works in starting the server on port 80, but not as the user I want,

sudo -u [user_name] bundle exec rails s -e production works in starting the server as the correct user, but not on the desired port.

I have temporarily set the user to be in the Administrators group as I have read that its required for ports < 1024, but that hasn't seemed to help either.

What else can I try?

share|improve this question
    
To get around this limitation, I have just set the iptables to redirect port 80 to port 3000, and am starting the rails server using the default port. – fatty Jun 25 '12 at 7:10
up vote 1 down vote accepted

You can start services on ports <1024 with root user. The group (administrator in your case) has nothing to do with it.

There are a few things you can do though. For example:

  • User iptables to redirect the ports (configurable with root rights).
  • If the program allows it or you have access to the code: start as root, bind(), then drop privileges.
  • There is a utility called authbind that is meant for such cases, but I personally have never used it, so I cannot comment on how well it works.
  • Use setcap to add privilege to your program.
share|improve this answer
    
The ultimate option would be to edit the kernel source code to remove the limit in the first place. See @Quandary's answer here: How can I run a server on Linux on port 80 as a normal user?: http://serverfault.com/questions/112795/how-can-i-run-a-server-on-linux-on-port‌​-80-as-a-normal-user/660121#660121 – XP1 Jul 14 at 8:52

You must log in to answer this question.

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