Reputation: 1510
Given that the web application doesn't have su privileges, I'd like to execute a shell script that requires sudo. I'd also like to avoid having the user input the password. What are my options? This is basically what I'm trying to do.
@Override
protected void onSubmit() {
System.out.println("Submitted");
try {
Shell.updateIp("eth0", "192.168.217.129");
} catch (IOException e) {
e.printStackTrace();
}
}
public static void updateIp(String ethernetInterface, String ip) throws IOException {
ProcessBuilder builder = new ProcessBuilder("/home/keeboi/Desktop/iptool.sh", ethernetInterface, ip);
Process child = builder.start();
Network.readOutput(child);
child.destroy();
}
iptool.sh executes a runnable jar.
#!/bin/sh
sudo java -jar changeip.jar $1 $2
And I'm getting:
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
Again, I'd like to emphasize that the web app isn't given any su privileges and I'd like to avoid asking the user for password.
Edit:
I've already tried adding keeboi ALL = NOPASSWD: /home/keeboi/Desktop/iptool.sh
to my /etc/sudoers
but it still requires a password.
Update
Added keeboi ALL = NOPASSWD: /home/keeboi/Desktop/changeip.jar
too, no dice.
Upvotes: 1
Views: 3625
Reputation: 64593
just add NOPASSWD
in /etc/sudoers:
user ALL = NOPASSWD: /home/keeboi/Desktop/iptool.sh
That switches password check off.
Upvotes: 4