代码:
import paramiko import time host = 'xxx' username = 'xxx' password = 'xxx' port = 22 command = 'uname -a \n' ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname=host,username=username, password=password, port=port, look_for_keys=False, allow_agent=False) stdin, stdout, stderr = ssh.exec_command(command) output = stdout.readlines() print(' '.join(map(str, output)))