How can I change linux socket file permissions?

I have a program that creates a socket, and then I want to change the permissions of the socket file:

ret_val = chmod(filename, 0777); 

but it does not change, although ret_val will be 0. If I try to use the same thing in a regular file, it works.

Any ideas?

PS: I run the program as root, so it has all the necessary permissions.

+7
source share
1 answer

From man 7 unix :

In a Linux implementation, the sockets that are visible on the file system respect the permissions of the directory in which they are located. Their owner, groups and their permissions are subject to change. Creating a new socket will not work if the process does not have the right to write and search (execute) in the directory in which the socket is created. Connecting to a socket object requires read / write permission. This behavior is different from many BSD-derived systems that ignore permissions for UNIX domain Outlets. Portable programs should not rely on this feature for security.

So, if you want to manage socket permissions in order to be portable, you should instead manage the permissions of the directory containing the socket.

+18
source

All Articles