Home > other >  How will the python Linux commands with permission?
How will the python Linux commands with permission?

Time:09-20

Recently to Python to implement some shell command calls, in order to cooperate to do a UI, the final packaging generated APP, intuitive easy to use, but in dealing with the root file, unable to perform, such as several times to remove the system/Library directory of one type of file, how to realize don't every time permissions, only when running for the first time give password authorization will perform follow-up multiple administrator privileges command?

Is not authorized to perform a single command, must be authorized by the APP to be executed for the first time after the command can execute multiple administrator privileges, like we usually installed APP,

Beginning and end of the great god, and have some ways to achieve this?

CodePudding user response:

1 save password, execute every time sodu

2 call first so root, and then execute root command

3 perform SSH login as root, as root in SSH calls

CodePudding user response:

reference 1st floor tianfang response:
1 store passwords, execute every time sodu

2 call first so root, and then execute root command

3 perform SSH login as root, as root in SSH call
eldest brother, this method is complicated for Python, did not understand what I mean,

CodePudding user response:

Save the password. Then:

1 each execution sodu

2 call first so root, and then execute root command

3 perform SSH login as root, as root in SSH calls

CodePudding user response:

With permission of the Linux command is what?
Your APP running in where?
"Executive APP authorization" Linux on how make? What operation

CodePudding user response:

 #! The/usr/bin/python 
# - * - coding: utf-8 - * -

The import of OS, sys
The import getpass


Def the password (s) :
Password=getpass. Getpass (" both Please input the administrator 's password: ")
Return the password

Def command (CMD) :
Text=OS. Popen (" echo % s | sudo -s % s "% (password (), CMD)), read ()
Return the text

Print (command (' rm - rf ~/Documents/10.11/Pythoner/sysman/123. Sh '))
Print (command (' rm - rf ~/Documents/10.11/Pythoner/sysman/1234. Sh '))
Print (command (' rm - rf ~/Documents/10.11/Pythoner/sysman/12345. Sh '))
Print (command (' rm - rf ~/Documents/10.11/Pythoner/sysman/12346. Sh '))


Look at the code, is now processing to only the last step, how to implement only enter a password , can perform the back of the countless command to remove operations,
~/Documents/10.11/Pythoner/sysman/123 *. Sh into their own directory file location,

CodePudding user response:

The password is preserved

CodePudding user response:

How to save and several references? Can modify the hair out on the above code?

CodePudding user response:


Or use SSH to give you an example,

https://www.cnblogs.com/wangshuo1/p/6265360.html


With your root login this machine (localhost or 127.0.0.1), it is for the root user is in operation, the password is using the SSH connection, save after multiple connection

CodePudding user response:

Repect, I know, the key is behind me to packaged into application, send another to run, so must be separate can run automatically, without the remote,

CodePudding user response:

refer to the eighth floor tianfang response:
or use SSH to give you an example,

https://www.cnblogs.com/wangshuo1/p/6265360.html


With your root login this machine (localhost or 127.0.0.1), it is for the root user is in operation, the password is using the SSH connection, save after multiple connection

Don't have to see such a complex example, you estimate is not expressed clearly, core idea saying waste their should is lost password first, then use a variable to store passwords, use variables to store passwords behind sudo permissions command

CodePudding user response:

Nearly a year, rare and person to reply, the main code in the above, you can modify it for me?
Only enter a password, and then the subsequent delete all no longer enter the password, the key is the follow-up interactions, can be automatically input!
  • Related