Tux

...making Linux just a little more fun!

Privileged Port Access for User

Britto I [britto_can at yahoo.com]


Wed, 10 Sep 2008 08:20:31 -0700 (PDT)

Thanks Thomas and Joey.

The Operating system what i am using is Centos 5.2

We have our own java based software which is configured to use the port < 1024 for some testing.when i try to start running my process

I see the java exception which says ":: java.net.BindException: Permission denied"

As a root i could start and use without any issue

-- 
br


Top    Back


Jim Jackson [jj at franjam.org.uk]


Wed, 10 Sep 2008 19:30:59 +0100 (BST)

On Wed, 10 Sep 2008, Britto I wrote:

> Thanks Thomas and Joey.
>
> The Operating system what i am using is Centos 5.2
>
> We have our own java based software which is configured to use the port < 
> 1024 for some testing.when i try to start running my process
>
> I see the java exception which says ":: java.net.BindException: 
> Permission denied"
>
> As a root i could start and use without any issue

It is a common "security" feature to only allow root to use ports < 1024

There are a couple of solutions. Use an internet service launcher, like inetd or xinetd, to listen on the port and launch your application. I think xinetd can launch your application to run as a non-root user. However you'd have to alter you appl. to use stdin and stdout files instead of handling the sockets directly (actually this makes creating an itnernet application trivial - you don't need to understand sockets :-)

Alternatively make your application setuid root (see man chmod), so that when it is executed it starts as root, so it can listen on the priveleged port, then it can make a system call to stop being root and alter to a normal user - the C lib function is setuid.

I'm sure you could do a google code search for some example code.

cheers Jim


Top    Back