什么pexpect、pxshll在paramiko面前都是浮云,重要的是paramiko支持windows。
小试牛刀
import paramiko paramiko.util.log_to_file('ssh.log') # sets up logging username = 'root' password = '123456' command = 'ls -l' client = paramiko.SSHClient() #client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(hostname='192.168.3.100',port=22, username=username, password=password,pkey=None,key_filename=None,timeout=None,allow_agent=False,look_for_keys=False,compress=False) stdin, stdout, stderr = client.exec_command(command) print stdout.read()
client.close()
输出结果:
C:\Python27\python.exe E:/python/dabao/study/02.py total 44 -rw-------. 1 root root 1106 Jul 11 05:26 anaconda-ks.cfg -rw-r--r--. 1 root root 23089 Jul 11 05:26 install.log -rw-r--r--. 1 root root 6240 Jul 11 05:24 install.log.syslog drwxr-xr-x. 2 root root 4096 Jul 17 03:24 scripts Exception in thread Thread-1 (most likely raised during interpreter shutdown): Process finished with exit code 0
真心是我想要。
下面介绍下他的安装方法:
安装相关支撑库:
安装pycrypto:http://www.voidspace.org.uk/python/modules.shtml#pycrypto
由于我的客户端是windows,我下载的.exe文件,直接运行安装
安装paramiko,https://pypi.python.org/pypi/paramiko/1.7.7.1
cmd切换到对应目录执行:python setup.py install
导入模块证明安装成功。