How can we write a shell script to become root? That is I donot want to input the password at prompt it should be within the script itself. I was trying to make but failed to do so.Is it possible, if Yes please Explain.
|
You can write a script using expect tool. In Redhat, expect package comes by default. But in Ubuntu you need to install it separately. You can check this by using commands:
The following script will do your work:
|
|||
|
|
|
The simplest way is to make a suid copy of the shell:
Then, running However, I would be remiss if I didn't give you this advice: don't do that. It's unwise to make it so easy for malware to escalate its privileges to root. Instead, just install |
|||
|
|
|
You can set the SUID sticky bit:
That will cause the software to run as the owner of the file. So of course, you'll have to change ownership to root:
(assuming you are found in the sudoers file, and you've installed sudo) |
|||
|
sudo suorsudo bashworks without a password – Michael Mrozek♦ Oct 19 '12 at 17:36sudo -iis preferred. It requires permissions to runsudo bash. – jordanm Oct 19 '12 at 19:16