I know that using the sudo
and ssh
tools it is possible to use GUI to ask for a password in a script by setting, respectively, the SUDO_ASKPASS
and SSH_ASKPASS
variables in which we specify a graphical tool to ask a password.
But what if I am using any other tool which may ask for a password, for example ksu
which does not seem to support any of the above-mentioned modes? (I searched on internet and I did not find anything like KSU_ASKPASS
and ksu
does not seem to have any option to support this).
I think I have found the solution at the end...
Suppose, for example, that you want to list the contents of the
/root/
folder and in order to do this you need a root access and you can only use theksu
tool (nosudo
/su
/ssh
).First, you ask the password using a graphical tool like
zenity
and you store it in a local variable.After that, you can run
ls /root/
viaksu
by using the following command.Explanation:
By using
echo
combined with|
you are piping the password toksu
, since it asks for a password via the standard input.After reading the password from the standard input,
ksu
executes thels
command specified using the-e
option, passing/root/
as an argument via the-a
option.