Server Fault is a question and answer site for system and network administrators. 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 have written a program in C++ which uses sockets to talk to a windows7 machine.

I have run the code as the root user and everything works fine. However I don't want to end up running the program as root, for security reasons.

First I made a new user to run the program in, but it wouldn't let the user start a new socket, so I added the user to the root group and tried again, but Redhat will not let me start a new socket as anything but the root user.

I have tried this with the firewall disabled just to rule it out, and still no luck.

So, do any of you have an idea as to what permissions/groups should I change/add?

I have looked around online and found that:

/usr/sbin/setsebool -P httpd_can_network_connect=1

Is suggested as a possible cure, but it doesn't seem to help me.

share|improve this question
Before we go crazy over selinux, what does your audit log say about the attempt? What does your program say (you did check return values, right?) – DerfK Aug 9 '11 at 15:44
up vote 1 down vote accepted

but Redhat will not let me start a new socket as anything but the root user.

Then you must have a very restrictive SELinux policy set up.

Are you sure it just won't let you create a listening socket using a port number of less than 1024?


If the port number is not below 1024, then it's the SELinux policy. You should be seeing entries logged in /var/log/messages saying it is being denied.

To allow...

 /usr/sbin/semanage port -a -t <SEType> -p tcp 51717

Where is the type being reported in the log or use http_port_t to add it into the http type. See this page for an example

share|improve this answer
Well I'm using port number 51717 so can't be that... – Andy Aug 9 '11 at 15:07

What port are you binding to?

Binding to TCP ports lower than 1024 is restricted to root.

You can drop root privilege after binding the socket in your program, or alternatively use a workaround like an iptables redirect or authbind; there's some good discussion of the many options in this question on Stack Overflow.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.