1

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
karim samir
  • 99
  • 1
  • 5

1 Answers1

1

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.

andy.holmes
  • 3,383
  • 17
  • 28
  • Can I use something like GLib.spawn_command_line_sync('sudo echo e') or does that have any draw backs ? – karim samir Mar 23 '21 at 15:00
  • 1
    `sudo` will not work; there's no where for the user to enter the password. `pkexec` is the appropriate program for a GUI environement. – andy.holmes Mar 25 '21 at 00:04