python version: 2.7.5
#!/usr/bin/python
#by fuqiang
#2019-04-01
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.140.115',22,'root','skieer@12345678')
stdin,stdout,stder = ssh.exec_command('df -h')
print stdout.read()
ssh.close()
--------------------------------------------------------------------------------------
将输出结果输入到文本
#!/usr/bin/python
#by fuqiang
#2019-04-01
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.140.115',22,'root','skieer@12345678')
stdin,stdout,stder = ssh.exec_command('df -h')
f0 = stdout.read()
f = open('/home/py/1.txt','w+')
f.write(f0)
f.close()
ssh.close()