Tuesday, October 23, 2012

What is su doing?

su is a small *nix program that switches to another user and spawns a shell running as that user. What su is exactly doing is:

1. fork()
2. For the child process
    2.1 set_uid to the user given as an argument. If none, set_uid to root
    2.2 execv() a shell, whatever the default/specified shell it is
3. For the parent process
    3.1 wait for the child process

Notes:

  • set_uid will fail if su is not running as root
  • To make su run as root, the su binary must be owned by root and with the set_uid bit set

No comments:

Post a Comment