run sudo commands from gnome-extentions

Viewed 372

I want to run a sudo command that prompts a GUI for the user to enter their password and get the password back for future use.

running this in a gnome-extention

GLib.spawn_command_line_sync('sudo echo e')

I get the following error

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
1 Answers

You should never be storing user passwords for later use or running privileged programs that spawn other programs, but instead prompting each time you need it.

To prompt for a privileged program, you can usually use pkexec in place of sudo. Additionally you should be spawning asynchronously with Gio.Subprocess whenever possible, as a synchronous subprocess will block the main thread of GNOME Shell.

Related