paramiko

import paramiko
ssh=paramiko.SSHClient()
know_host=paramiko.AutoAddPolicy()
ssh.set_missing_host_key_policy(know_host)
ssh.connect(
    hostname="10.10.21.82",
    port=22,
    username="root",
    password="123"
)
shell=ssh.invoke_shell()
shell.settimeout(1)
command=input(">>>")+"
"
shell.sent(command)
while True:
    try:
        recv=shell.recv(51.2).decode()
        if recv:
            print(recv)
        else:
            continue
    except:
        command=input(">>>")+"
"
        shell.sent(command)
ssh.close()
原文地址:https://www.cnblogs.com/wutanghua/p/11105135.html