required:
python+pycrypto
1.安装pycrypto
726 cd /opt/ 727 wget http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.tar.gz 728 tar -zxvf pycrypto-2.6.tar.gz 729 cd pycrypto-2.6/ 730 python 731 python setup.py build && python setup.py install
runtest:
>>> import Crypto >>>
2.
pip install paramikoerror: command ‘gcc‘ failed with exit status 1yum install gcc libffi-devel python-devel openssl-devel
import paramiko import sys,os host=sys.argv[1] user=‘alex‘ password=‘‘ cmd=sys.argv[2] s=paramiko.SSHClient() #加载本机的host密码文件 s.load_system_host_host_keys() #Set policy to use when connecting to servers without a known host key #第一次连接输入yes or no s.set_missing_host_key_policy() s.connect(host,22,user,password,timeout=5) stdin.stdout,stders.exec_command(cmd) cmd_result=stout.read(),stderr.read() for line in cmd_result: print line s.close() #使用key连接远程 pkey_file=‘‘ key=paramiko.RSAKey.from_private_key_file(pkey_file) s.connect(host,port,username,pkey=key,timeout=5) stdin,stout,stderr=s.exec_command(cmd) s.close() #使用paramiko上传文件 hostnam=‘localhost‘ user=‘alex‘ password=‘‘ s=paramiko.SSHClient() s.load_system.host_keys() s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) t=paramiko.Transport((host,22)) t.connect(username=user,password=password) sftp=paramiko.SFTPClient.from_transport(t) sftp.get(‘sourcefie‘,‘‘) sftp.put(‘destfile‘,‘sourcefie‘) s.close
时间: 2024-10-29 19:05:31