how to login to root in linux through sh file with example?
migrated from stackoverflow.com Oct 13 '10 at 8:00
This question came from our site for professional and enthusiast programmers.
closed as not a real question by wzzrd, jscott, Warner, Dennis Williamson, John Gardeniers Oct 14 '10 at 0:30
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.
Typically, you'd have a file with the following contents:
This will display a password prompt (unless you're already root) and once you have entered the root password you will be at a root shell, as if you had logged in as root initially.
I suppose you are asking for setuid shell scripts. That is, from a normal user shell, execute a shell script with root privileges. Setuid scripts don't work as expected because what is really exec'ed by the os is the shell program called with your script as the argument. Shell doesn't honor the setuid bit you have on your script. So this will not work as you wish:
that script is owned by root, has setuid bit set and it is supposed to print my effective user id as 0. it doesn't
what you need to do is to use a binary setuid wrapper for exec'ing the script
chown and setuid:
execute the shell script:
but you may want to use sudo instead because the security implications of the solution described above are... kinda big. for automating tasks which are supposed to run as root you can use a NOPASSWD config in sudoers file granted to a secured admin user.