python3.6版本
目的:远程ssh执行 /home/linxinfa/hello.sh
模块:paramiko
import paramiko
import os
def sshclient_execmd(hostname, port, username, password, execmd):
s = paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname=hostname, port=port, username=username, password=password)
stdin, stdout, stderr = s.exec_command (execmd)
line = stdout.readlines()
print(stderr.read())
s.close()
return line
if '__main__' == __name__:
hostname = 'www.linxinfa.com'
port = 8888
username = 'linxinfa'
password = 'gor3b2'
line=sshclient_execmd(hostname,port,username,password,"sh /home/linxinfa/hello.sh")
print(line)