4

I am trying to execute a C program from multiple users and trying to login as other user within the program to access a file. But I am getting error

setuid: Operation not permitted

Can I do something such I needn't to use sudo every time? Like, giving full access to the program to use setuid as it wants without calling sudo everytime?

tarun14110
  • 940
  • 5
  • 26
  • 57
  • This question belongs probably to SuperUser. You solve it by setting the SUID file attribute, like `sudo chmod u+s your_program` – flaviodesousa Feb 11 '17 at 19:38
  • You can also consider making a root-owned server spanning the program on demand under the correct user (or just ssh into that user for that matter). – eckes Feb 11 '17 at 19:41

2 Answers2

5

Depending on the system, and your privileges in it, you might be able to change the owner or group of the program to one that has privileges to setuid, and then set the setuid or setgid mode on the executable via chmod:

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

or

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

Please be aware that by doing so, you create a potential security hole. If someone can overwrite your program, they could use it to gain privileges. Do this with caution.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
aghast
  • 14,785
  • 3
  • 24
  • 56
2

You just need to use setuid on the program's executable itself using chmod:

sudo chmod u+s executable
ForceBru
  • 43,482
  • 10
  • 63
  • 98