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:
- your script run other script sudo:
subprocess.check_call(['sudo', '/we/run/as/root']);
- 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) - 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
Post a Comment