I have a java application that has a timer that executes a separate application that requires elevated privileges. I have been doing this:
String command = "gksudo /home/bob/sensor";
Process child = Runtime.getRuntime().exec(command);
The problem is that every time the timer kicks off, it requests the password, so I get it every two seconds. Is there a way to only request the password once and then stay elevated so that as long as the java application is running it won't ask again?
I tried using gconf-editor to change the apps/gksu/save-to-keyring option, but that didn't change anything, and I think it might be a nuclear option anyway.
I don't think this actually possible, because
gksudo
does not allow you to pass a password. Howeversu
andsudo
do allow this (see How to pass the password to su/sudo/ssh without overriding the TTY?).You can use
gksudo -p
to use a graphical auth-window and retrieve the password. Then the next time you don't need gksudo, since you don't want to ask for a password anyway.Might look something like this
I suspect security experts to hate me for suggesting this (storing a password), so use with care.