简体   繁体   中英

Binding a port < 1024 for non root user in Java

I have a Java application which is running as non root mode.

My App will create a TFTP server (using apache commons tftp). TFTP server is bind to port 69(Default TFTP port). When running the app from IDE everything works fine since the IDE running as root. But if the app is run from other user i get the error

java.net.BindException: Permission denied

It is clear that for non root user i can not open the port. Is there a workaround for this issue?

For binding on Linux of ports less that 1024 you need to application to run a root. There is no way around this. If you need to do this you have you run as root. sudo might be the command to look into.

BTW - Running your IDE as root is not a very good idea.

To resolve this issue. You can use setuid() and setfid() system calls. So that you can temporarily elevate the permissions and then drop the permission back to user permissions.

In my Case, this problem happened in Solaris 11 OS. I added privileges to user to use the ports under 1024.

https://technicalsanctuary.wordpress.com/2014/06/03/allowing-a-user-to-use-ports-under-1024-on-solaris-11/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM