远程连接服务器paramiko模块

#!/bin/env python

import paramiko

#设置日志记录
paramiko.util.log_to_file('/tmp/test')

#建立连接
ssh=paramiko.SSHClient()

#缺失host_knows时的处理方法
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

#连接远程客户机器
ssh.connect('10.1.6.190',port=22,username='root',password='password',compress=True)

#获取远程命令执行结果
stdin, stdout, stderr = ssh.exec_command('hostname;uptime')
print stdout.read()

#输出执行结果
ssh.close()``
posted @ 2020-08-26 21:23  名字很长容易被惦记  阅读(153)  评论(0编辑  收藏  举报