远程重启Linux服务器

import paramiko
# pip install paramiko

def reboot(ip, port, username, passwd, timeout=10):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(ip, 22, username, passwd)
    stdin,stdout,stderr = ssh.exec_command('sudo -S reboot')
    stdin.write("nasadmin\n")
    stdin.flush()
    # stdin,stdout,stderr = ssh.exec_command('ls')
    # print(stdout.readlines())
    # print(stderr.readlines())
    ssh.close()

if __name__ == '__main__':
    reboot('10.62.227.55', 22, 'root','changeme')

你可能感兴趣的:(远程重启Linux服务器)