简体   繁体   English

我可以在没有sudo的情况下运行包含setuid()的C程序吗?

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

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. 我试图从多个用户执行一个C程序,并尝试以程序中的其他用户身份登录以访问文件。 But I am getting error 但我收到了错误

setuid: Operation not permitted setuid:不允许操作

Can I do something such I needn't to use sudo every time? 我可以做一些我不需要每次都使用sudo的东西吗? Like, giving full access to the program to use setuid as it wants without calling sudo everytime? 比如,在没有每次调用sudo的情况下完全访问程序以使用setuid

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 : 根据系统及其中的权限,您可以将程序的所有者或组更改为具有setuid权限的程序,然后通过chmod在可执行文件上设置setuidsetgid模式:

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. 谨慎行事。

你只需要使用chmod在程序的可执行文件上使用setuid

sudo chmod u+s executable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM