What you are asking for sounds doable, combining the
-A option of
sudo and the program
Basically, if you use the option
-A, instead of reading the password from stdin,
sudo reads the password from an external program that you can specify with the
SUDO_ASKPASS environment variable.
This external program could be
gnome-keyring-query, a command line tool for storing/getting passwords from
gnome-keyring. Here is the help of
gnome-keyring-query <mode> <name>
mode - either 'get' or 'set' (without quotes)
name - a name to identify the key
If mode is 'get', then the password is dumped to stdout.
If mode is 'set', then the password is read from stdin.
Here is how you can proceed (I just tried, it works).
- Install gnome-keyring-query (You will have to compile it if it is not packaged by your distro -> upstream url)
- Save your sudo password in the gnome-keyring
- You should be able to retrieve the password from the keyring with something like:
gnome-keyring-query get sudo
- Save this command as a script (for example in /usr/bin/sudo_askpass) and make sure it is executable with chmod
sudo -A instead of sudo.
That being said, be aware that if you save your password in the keyring and leave this keyring open, anyone can read your sudo password very easily, either using this gnome-keyring-query tool, or just simply by launching seahorse. So be very careful.