Tell me how in a python program, under certain actions, request a user password (sudo). For example, I want some files of my program to be stored in a folder in the home directory (home), for this you need to create a directory (for example / home / user / folder), how to make the system ask for a password at this moment and if it is correct created a folder? Xubuntu system 18.04. Python 2.7.

  • one
    Requested superuser password? Why, if it is a user directory? - mkkik
  • @mkkik it was just an example. The bottom line is that with certain actions, you need to request a sudo password and, if it is correct, transfer control back to the program and execute it further. - umd
  • one
    You can generally require the launch of the script on behalf of the superuser. Just at runtime, the user will receive PermissionError without sudo . It’s hard to say something if you don’t say exactly what actions you want to perform. - mkkik
  • I would love to say if this helps the cause. But I wanted to look at the overall implementation. I still do not know what kind of action. I need to understand how this is done at all. Somehow to check the file with a password in the system or, as you say, run the script on behalf of sudo? I do not understand the mechanism for checking the system password in third-party programs. I can write the code that will store the password (not system) somewhere on the server or in the file system, but this will be the password for this program and I want to interact with the OS. I hope clearly explained. I apologize for the abundance of text. - umd
  • Password checking is better to entrust the OS. Just form the system call with sudo . For example, os.system('sudo ...') or subprocess.run(['sudo', ....]) . - mkkik pm

0