When you want to execute a program which has root privilege. Here is what you can do.

First program.c

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>                                                           

int main()
   setuid( 0 );
   system( "<program>" );

   return 0;

Then in the shell enter the following commands:

$ gcc -o program program.c
$ sudo chown root program
$ sudo u+s program

Then you can execute program to execute your program under root privilege!

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License