How to run the compiler with root privileges under Linux?

  
                

Some compilers under the Linux system need root privileges to run if they use raw sockets, but they can't be elevated when the program is running. What should I do at this time? Here's how to run the compiler with root privileges without the need to add sudo or switch to the # prompt.

following steps:

1, complete with root privileges gcc;

2, chmod u + s "executable"

This At the same time, it can be run like Linux's own ping, without sudo or switching to the # prompt.

Of course, since the ping source on UNP uses setuid(getuid()) after creating the original socket, the principle of least privilege is maintained.

The above two steps are indispensable. Just follow the method described in this article, you can run your own compiled program with root privileges under Linux system.

Copyright © Windows knowledge All Rights Reserved