The content of this section:
- Paramiko
- Mysql
1.paramiko
Http://www.cnblogs.com/wupeiqi/articles/5095821.html
Paramiko is a module, socket, and SSH protocol that enables remote server operations with Python code using this module
Ansible the bottom is the module used
Function:
A. Use username password: command, file
B. Using the user name key: command, File
C. Executing the Create session
1. Connect based on user name password:
ImportParamiko#To create an SSH objectSSH =Paramiko. Sshclient ()#allow connections to hosts that are not in the Know_hosts fileSsh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())#connecting to a serverSsh.connect (hostname='c1.salt.com', Port=22, Username='Wupeiqi', password='123') #Execute Commandstdin, stdout, stderr = Ssh.exec_command ('DF')#Get command Resultsresult =Stdout.read ()#Close ConnectionSsh.close ()
Paramiko
b'anaconda-ks.cfg\ninstall.log\ninstall.log.syslog\npackage\n\xe5\x85\xac\xe5\x85\xb1\xe7\x9a\x84 \n\xe6\xa8\xa1\xe6\x9d\xbf\n\xe8\xa7\x86\xe9\xa2\x91\n\xe5\x9b\xbe\xe7\x89\x87\n\xe6\x96\x87\xe6\xa1\xa3\n\xe4 \xb8\x8b\xe8\xbd\xbd\n\xe9\x9f\xb3\xe4\xb9\x90\n\xe6\xa1\x8c\xe9\x9d\xa2\n'
Output
If you log in with a normal user
#-*-coding:utf-8-*-#blog:http://www.cnblogs.com/linux-chenyang/ImportParamiko#To create an SSH objectSSH =Paramiko. Sshclient ()#allow connections to hosts that are not in the Know_hosts fileSsh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())#connecting to a serverSsh.connect (hostname='10.236.62.37', Port=22, Username='Root', password='123456')#Execute Commandstdin, stdout, stderr = Ssh.exec_command ('sudo ls') Stdin.write ('123456') Stdin.flush ()#Get command Resultsresult =Stdout.read ()Print(str (result))#Close ConnectionSsh.close ()
Paramiko
2. Based on the user name secret key connection
ImportParamiko Private_key= Paramiko. Rsakey.from_private_key_file ('/home/auto/.ssh/id_rsa') #To create an SSH objectSSH =Paramiko. Sshclient ()#allow connections to hosts that are not in the Know_hosts fileSsh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())#connecting to a serverSsh.connect (hostname='c1.salt.com', Port=22, Username='Wupeiqi', key=Private_key)#Execute Commandstdin, stdout, stderr = Ssh.exec_command ('DF')#Get command Resultsresult =Stdout.read ()#Close ConnectionSsh.close ()
Paramiko
Python_oldboy_ automatic operation and Maintenance Road _paramiko,mysql (12)