paramiko-ssh-秘钥认证实例
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()

浙公网安备 33010602011771号