Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I change the permissions of a linux socket file?

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

ret_val = chmod(filename, 0777);

, but it doesn't change, even though ret_val will be 0. If I try the same thing on a regular file, it works.

Any ideas?

P.S: I am running the program as root, so it has all the authority needed.

like image 326
Claudiu Avatar asked May 12 '11 11:05

Claudiu


People also ask

Who can change file permissions in Linux?

Only the current owner or superuser can use the chmod command to change file permissions on a file or directory. Change permissions in symbolic mode by using the chmod command.

How we can change the permission of files using chmod?

To change the file permissions using chmod, run chmod <permission> <directory or filename> , swapping in the desired file permissions and the directory or file. The owner can change file permissions for any user, group or others by adding - to remove or + to add certain permissions.


1 Answers

From man 7 unix:

In the Linux implementation, sockets which are visible in the file system honor the permissions of the directory they are in. Their owner, group and their permissions can be changed. Creation of a new socket will fail if the process does not have write and search (execute) permission on the directory the socket is created in. Connecting to the socket object requires read/write permission. This behavior differs from many BSD-derived systems which ignore permissions for UNIX domain sockets. Portable programs should not rely on this feature for security.

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

like image 69
Dietrich Epp Avatar answered Sep 27 '22 23:09

Dietrich Epp