how to be a super user to run linux commands in python script? -


i have execute few commands in linux need super user before execute command. has done via python script scenario should execute following command in order

>> su 

this prompts password

after entering password have execute bluez commands

>> hciconfig hci0 >> hcitool lescan >> hcitool lecc <address> 

i need in python please tell me how super user , give password via python later execute above commands in order? meaning,i want automate whole process execute commands without manual intervention.

good security practice says should minimize time @ elevated privilege. 1 way put commands run root in different file , cause file run root. have several options:

  1. your script run other script sudo:
    subprocess.check_call(['sudo', '/we/run/as/root']);
  2. you make script 'setuid-root' , run it, no sudo needed:
    subprocess.check_call(['/we/run/as/root']);
    (however, on many systems not work because setuid-root disabled on scripts)
  3. like #2 use small c-program setuid-root , runs script:
    subprocess.check_call(['/the/c/program']); c-program is:
    int main(void) { return system("/we/run/as/root"); }

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -