0

I'm planning to build a simple GUI for smartctl using Python and TkInter on Linux. My problem is that I need to run GUI part as a simple user, but some smartctl commands require elevated permissions (root). I cannot run whole application as root due to potential problems of storing user configuration in user directory and saving logs with correct permissions. Of course user must enter his password (and have correct root permissions) to actually execute commands. In best case scenario user should enter his password only once during program execution, but I would not prefer to store it somewhere in plain text, even temporarily while program runs. What is correct and secure approach to run sudo commands using Python for GUI applications? Should I consider using other toolkit, like GTK or Qt for easier implementation and better desktop integration (native authentication dialog)?

joshas
  • 1,464
  • 1
  • 24
  • 41
  • Is this (gtksudo) what you are looking for ? https://stackoverflow.com/questions/4112737/how-to-gain-root-privileges-in-python-via-a-graphical-sudo – Maurice Meyer Jul 28 '22 at 15:00
  • @MauriceMeyer Looks like gksudo is deprecated, my distribution doesn't provide it by default nor in official repositories. – joshas Jul 28 '22 at 15:05
  • Good point, but I assume it must have been replaced with something else. – Maurice Meyer Jul 28 '22 at 15:08
  • Found out that `pkexec` replaced gksudo, and it works on my distribution. But I need to enter password each time I run sudo command, so it would be nice to know, if that could be improved and ask user password once during application session. – joshas Jul 28 '22 at 16:44

0 Answers0