Dheeraj Joshi
Dheeraj Joshi

Reputation: 3147

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?

Upvotes: 1

Views: 2302

Answers (3)

Christian Alvarado
Christian Alvarado

Reputation: 21

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/

Upvotes: 1

Dheeraj Joshi
Dheeraj Joshi

Reputation: 3147

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.

Upvotes: 2

Ed Heal
Ed Heal

Reputation: 59987

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.

Upvotes: 4

Related Questions