Need Java program to listen on ports < 1024 w/o being root - possible
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Need Java program to listen on ports < 1024 w/o being root - possible
I am in AP Computer Science 3 on the highschool level and am working on my final project which is a client server chat/poker program written in java. We are not allowed to set up webservers on the school compters, so I trying to use my home linux web server hosting the client applet and also running the poker server program. The poker server listens on port 9999 but it seems that my school blocks outgoing connections to 9999. I know that they do not block ports 80, 21, 22, and 23 (and I assume most ports less than 1024) because I have established connections to my server via telnet.
The problem is: if I am a regular user and I try to run the server on ports less than 1024 I get a java security exception when it tries to bind to the port.
Is there a way to run my server on ports less than 1024 without being root?
Don't apache and other servers do this somehow?
Thanks,
Brenan
PS I have tried setting the SUID bit for a script to run the server but that did not work, and if it did I think the server would still be running as root.
Binding to priviliged ports (as ports < 1024 are called) is an operation only permitted to the root user. What Apache (and like applications) do is actually start out as the root user, and then drop privileges to a normal user (the apache or nobody account, in most cases). I'm not a Java expert ... so I'm not sure if there's a way around this. Doing a google on Java setuid returned a few hits, so those might be where you want to look. Alternatively, you could do SSH port forwarding to try to get around this, or, if you trust your JVM, let the code run as root (to be avoided).
Well after performing a google search on java setuid (which returned this thread btw ) I stumbled on something called the java native interface or JNI.
Anyone who has had the same problem as me may want to try the following links:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.