Linux – Which permission is needed to open a TCP server socket on Linux

debianlinuxpermissionssocket

I want to start a websocket server, but can't connect to it from other machines. Only when I start the websocket server with root permissions it works. So this seems to be an permission Problem.

Which permissions does my user need to open a socket?

Best Answer

Usually, root access is needed to open ports under 1024, which covers most of the well known services such as web (80), ssh (22), ftp (21) etc.

Some daemons can be configured to listen on other ports above port 1024 which might let you use them with non-root permissions, but it varies on a product by product basis.

There are other work arounds as well, such as using CAP_NET_BIND_SERVICE, this is described in more detail in this answer, of which the summary is,

The short answer is that you do:

setcap 'cap_net_bind_service=+ep' /path/to/program

And then anytime program is executed thereafter it will have the CAP_NET_BIND_SERVICE capability. setcap is in the debian package libcap2-bin.