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
Hibernate: Hbm2Ddl.Auto=Update in Production
Replace String With Another in Java
How to Change a Jfreechart'S Size
Failed to Load the Jni Shared Library (Jdk)
Deserialize a List≪T≫ Object With Gson
Find Where Java Class Is Loaded From
Java: How to Get a Class Literal from a Generic Type
Maximum Java Heap Size of a 32-Bit Jvm on a 64-Bit Os
Double Decimal Formatting in Java
How to Compare Two Double Values in Java
What's Java Hybrid - Applet + Application
Gson: How to Exclude Specific Fields from Serialization Without Annotations
How to Sort Map Values by Key in Java
Ssl Handshake Alert: Unrecognized_Name Error Since Upgrade to Java 1.7.0
How to Schedule a Periodic Task in Java