Can I run a C program containing setuid () without sudo?

I am trying to execute C program from several users and trying to log in as another user in the program to access the file. But I get an error

setuid: operation not allowed

Can I do something that I don’t need to use sudo every time? For example, giving full access to the program to use setuid as he wants, without calling sudo every time?

+4
source share
2 answers

Depending on the system and your privileges in it, you can change the owner or group of the program to the one who has privileges for setuid, and then set the setuid or setgid mode in the executable file through chmod

chgrp wheel my-awesome-program
chmod g+s my-awesome-program

or

chown superduperuser my-awesome-program
chmod u+s my-awesome-program

, . - , . .

+4

setuid , chmod:

sudo chmod u+s executable
+2

Source: https://habr.com/ru/post/1669476/


All Articles