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:
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)