Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use su in a script
#2
Quote:Use SU from within the script without having to enter a password

Then you've to provide a password in your script or in an additional file.
This is a big security issue.

Quote:editing sudoers from a script to make the installation of the scripts easier?
For the user it's easier, but the user needs root access to edit the soduers file.
So, Python needs root access to edit /etc/sudoers.

The Best way is to let the user edit his sudoers if he wants to.
Then just run all your commands which requires root with sudo.

import subprocess


def sudo(command):
    return subprocess.run(["sudo"] + command, capture_output=True, encoding="utf8")
The user has to enter his password only once. Then it's cached with an expiration time.
If he is not in sudoers, he is not allowed to gain root rights.

You can argue with security.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
How to use su in a script - by edlentz - Nov-12-2020, 02:56 PM
RE: How to use su in a script - by DeaD_EyE - Nov-12-2020, 03:28 PM
RE: How to use su in a script - by edlentz - Nov-13-2020, 08:14 PM
RE: How to use su in a script - by DeaD_EyE - Nov-14-2020, 08:29 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020