How to Run Sudo Command Without Password from Java Program

Execute a linux shell command with sudo using java, without entering the required password

assuming there is a sess.getStdin(), you should be able to pipe in a password to the sudo command.

How to execute sudo command with password with a given userid in linux server using Java program?

I have used the method as below to add the key associated with the sudo user I wished to execute in the given server.
And ensure that key location is given as input string. It worked!

jsch.addIdentity(key);

How to input password to sudo using java Runtime?

You could just drop sodu all together and create a shell script suid root and run that instead.

chmod +s myscript && chown root myscript && chgrp root myscript

whenever that script is called it will be run as root.

How to supply sudo with root password from Java?

Have you tried with -S ?

$echo mypassword | sudo -S vim /etc/resolv.conf

From man:

The -S (stdin) option causes sudo to read the password from the standard input 
instead of the terminal device. The password must be followed by a newline
character.


Related Topics



Leave a reply



Submit