2011年5月4日 星期三

[Linux] setuid

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

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!