# How to compile a program with setuid?

**URL:** https://discourse.cmake.org/t/how-to-compile-a-program-with-setuid/10983
**Category:** Code
**Tags:** os:linux
**Created:** [June 8, 2024, 5:36am UTC](https://discourse.cmake.org/t/how-to-compile-a-program-with-setuid/10983 "2024-06-08T05:36:28Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ogogon](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ogogon/32/2721_2.png) [@ogogon](https://discourse.cmake.org/u/ogogon)
#### Post date: [June 8, 2024, 5:36am UTC](https://discourse.cmake.org/t/how-to-compile-a-program-with-setuid/10983/1 "2024-06-08T05:36:28Z")

</div>

Colleagues, please tell me how to solve my problem - I want the program have set setuid after compilation.

Right now I’m using a very simple CMakeLists.txt:

```auto
set (HEADERS ...)
set (SOURCES ...)

add_executable myprog ${HEADERS} ${SOURCES})
target_link_libraries(...)

```

Thanks in advance for the advice,  
Ogogon.

---

<div class="post-metadata">

### Author: ![Oodini](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/db5fbb/32.png) [@Oodini](https://discourse.cmake.org/u/Oodini)
#### Post date: [June 13, 2024, 11:36am UTC](https://discourse.cmake.org/t/how-to-compile-a-program-with-setuid/10983/2 "2024-06-13T11:36:03Z")

</div>

I think it must be down at the installation step.  
See the parameter PERMISSIONS of the `install()` command.

---

<div class="post-metadata">

### Author: ![ogogon](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ogogon/32/2721_2.png) [@ogogon](https://discourse.cmake.org/u/ogogon)
#### Post date: [June 16, 2024, 11:53am UTC](https://discourse.cmake.org/t/how-to-compile-a-program-with-setuid/10983/3 "2024-06-16T11:53:05Z")

</div>

> [@Oodini](#):
>
> See the parameter PERMISSIONS of the `install()` command.

Thank you. I found this in the documentation and did it. Entered **PERMISSIONS SETUID**.  
But this only works when I say **make install**.

Is it possible to make setuid installed after **make**?

---

<div class="post-metadata">

### Author: ![Oodini](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/db5fbb/32.png) [@Oodini](https://discourse.cmake.org/u/Oodini)
#### Post date: [June 16, 2024, 7:07pm UTC](https://discourse.cmake.org/t/how-to-compile-a-program-with-setuid/10983/4 "2024-06-16T19:07:44Z")

</div>

I don’t think so, but I am still learning CMake, so maybe it is possible…

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [June 17, 2024, 7:53am UTC](https://discourse.cmake.org/t/how-to-compile-a-program-with-setuid/10983/5 "2024-06-17T07:53:24Z")

</div>

The question is rather if this is a good thing to do. As a normal user, you cannot set an executable as suid-root, only root user can do this. This might need a password during build and this will fail in a non-interactive shell or the prompt drowns in the output.
