Shell script to become root
7,293
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:
$ rpm -qa | grep expect
for Redhat
$ dpkg -l expect
for Ubuntu
The following script will do your work:
#!/usr/bin/expect
spawn su -
expect "Password: "
send "password\r"
interact
Related videos on Youtube
Author by
Rahul Kumar Dubey
B-tech 3rd year student on MNNIT allahabad
Updated on September 18, 2022Comments
-
Rahul Kumar Dubey 4 months
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.
-
Admin about 10 yearsDoes it need to be a shell script? I don't see how that would be possible, but you could set it up so
sudo su
orsudo bash
works without a password -
Admin about 10 years@MichaelMrozek
sudo -i
is preferred. It requires permissions to runsudo bash
.
-
-
jordanm about 10 yearssetuid does not work on shell scripts unless you setuid the shell binary (not recommended).