# -*- coding:utf-8 -*- import paramiko private_key = paramiko.RSAKey.from_private_key_file('id_rsa.txt') #这是私钥、Linux服务器端需要有公钥 anthorized_keys ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname='192.168.199.11', port=22, username='root',pkey=private_key) stdin,stdout,stderr = ssh.exec_command('ls /tmp') res,err = stdout.read(),stderr.read() result = res if res else err print(result.decode()) ssh.close()