Hi, I am writing a program on a python under ubuntu, the essence is this:

When we run the program, we can watch everything that is there. When we want to change something, we press the "Unblock" button, the system dialog pops up asking for the root password, after which the program performs some administrative actions in the system. How can I do this unlocking on the fly? The option is to request a password with a self-made dialogue and then through the shell stupidly through sudo, you need to do the necessary, but I want more originality.

    2 answers 2

    If the GUI, then there is gksudo. If your console program is sudo. In any case, the password should not pass through your program.

    • thanks, plus karma is not enough - dron247
    • Thanks, comrades added :) - sercxjo 2:46

    As an option, use ssh-askpass :

    $ SUDO_ASKPASS=/usr/bin/x11-ssh-askpass sudo -A /path/to/script 

    UPD. By the way, the dialog box is extremely easy to implement. You can do something like this. askpass.py :

     #!/usr/bin/python # coding=utf-8 import sys from PyQt4 import QtGui from PyQt4.QtCore import QString from PyQt4.QtGui import QLineEdit, QInputDialog if __name__ == '__main__': import sys app = QtGui.QApplication(sys.argv) password, result = QInputDialog().getText(None, QString(u'Пароль'), QString(u'Введите свой пароль: '), QLineEdit.Password) if result: print(password) app.exit() 

    And then call:

     $ SUDO_ASKPASS=/path/to/askpass.py sudo -A /path/to/script