python 自定义ssh

import paramiko

class My_ssh:
    def __init__(self,ip,username,password):
        self.ip=ip
        self.username=username
        self.password =password
        self.ssh_client = paramiko.SSHClient()
        self.ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        self.ssh_client.connect(hostname=ip, username=username, password=password)

    def my_exec_command(self, cmd):
        return self.ssh_client.exec_command(cmd)


from amizeLib.ssh import My_ssh
my_ssh = My_ssh(ip='192.168.1.195', username='xx', password='xx')
my_ssh.my_exec_command(" killall Safari ")

stdin, stdout, stderr = client.exec_command(command)
stdout=stdout.readlines()
stderr=stderr.readlines()
原文地址:https://www.cnblogs.com/amize/p/13823134.html