import paramiko
private_key = paramiko.RSAKey.from_private_key_file('id_rsa.txt')
#创建ssh对象
ssh =paramiko.SSHClient()
#允许连接不在know_host文件中的主机
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)
#连接服务器
ssh.connect(hostname='192.168.50.135',port=22,username='fuyuteng',pkey=private_key)
#执行命令
stdin ,stdout ,stderr =ssh.exec_command('df -Th')
#命令结果
res,err =stdout.read(),stderr.read()
result=res if res else err
print(result.decode())
ssh.close()
转载于:https://www.cnblogs.com/fuyuteng/p/9180864.html
文档更新时间: 2020-04-18 02:38 作者:月影鹏鹏