Search posts

Allowing process to bind to port lower than 1024 in Linux

In Linux by default process has no permission to bind themselves to any port lower than 1024 (unless you are the root user of course).
So if for example we want our node js application to listen on port 80, the default port for http, we will probably get the following exception:

This happen because the node as no permission to listen to port 80 or any port lower than 1024 for that matter.
We can easily fix this by giving the node the required permission:
we need to run the following command:

sudo setcap cap_net_bind_service=+ep /usr/bin/nodejs

This will allow node to bind to port 80.
Of course we can use this method for any executable file

sudo setcap cap_net_bind_service=+ep <executableFilePath>

And when the executable file run it will have the permission to bind to port lower than 1024.