gksu doesn't has an option like sudo has to pass the password to it in the following way:

echo 'password' | sudo -S command

Anyway I wonder which is the simplest way to pass my password to gksu. What I found until now is:

parallel -j 2 -- "gksu command" "( sleep 1; xdotool type 'password';  xdotool key 'Return' )"

But this doesn't look so good for me (parallel and xdotool must to be installed, there is some time spent until the password is passed, the window which asking password is not avoided).

So, is there a better way?

Note: I'm not interested to edit the sudoers file or in explanations like "don't do this, it's not safety!".

  • 3
    Why are you uninterested in using sudoers? That is the most sensible solution here of which I am aware. – HalosGhost Aug 29 '14 at 18:15
  • 1
    Why are you using gksu if you want to pass the password from a script ? – Leiaz Aug 29 '14 at 18:17
  • @HalosGhost I like to keep sudoers file as it is. Thanks. – Radu Rădeanu Aug 29 '14 at 18:25
  • 1
    That doesn't answer the question. "Why?" – HalosGhost Aug 29 '14 at 18:25
  • @Leiaz Why not? I'm aware about pkexec, but then the question will be the same for pkexec. – Radu Rădeanu Aug 29 '14 at 18:29

Both gksu and gksudo pass your password to sudo. Try running them in a terminal with the --debug option:

gksu --debug gedit

You'll notice that they run sudo with the -H option (as well as -u and -p for username/password and -S option to avoid a terminal).

Therefore, you really just need to use sudo -H instead of gksu or gksudo.

  • This is a good proof. I can agree with it for now, thanks. – Radu Rădeanu Aug 29 '14 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.