Process p=Runtime.getRuntime().exec("sudo rm -rf /home/ftp");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
bw.write("qwerty");
bw.flush();
I have written this code but it is not working
There is no default password for sudo . The password that is being asked, is the same password that you set when you installed Ubuntu - the one you use to login. Save this answer.
String[] cmd = {"/bash/bin","-c"," echo password| sudo -S rm -rf /home/ftp"};
Process p = Runtime.getRuntime.exec(cmd);
Provide the input for the process using the pipe.
Starting the echo
with space it will remove it from bash history.
You can also later delete the history:
new File(System.getProperty("user.home"), ".bash_history").delete();
but be careful with it. There is a trick to remove just last entries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With