paramiko模块学习笔记
SSHClient
基于用户名密码连接
import paramiko
# 创建SSH对象
ssh = paramiko.SSHClient()
# 允许连接不在know_hosts文件中的主机
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 连接服务器
ssh.connect(hostname='',port='',username='',password='')
# 执行命令
stdin,stdout,stderr = ssh.exec_command('whoami')
# 获取命令执行结果
result = stdout.read()
# 关闭连接
ssh.close()
基于公钥连接
import paramiko
# 设置私钥路径
private_key = paramiko.RSAKey.from_private_key_file('/home/mark/.ssh/id_rsa')
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='', port=22, username='', pkey=private_key)
stdin,stdout,stderr = ssh.exec_command('whoami')
result = stdout.read()
ssh.close()
SSHClient封装Transport
import paramiko
transport = paramiko.Transport(('127.0.0.1',22))
transport.connect(username='',password='')
ssh = paramiko.SSHClient()
ssh._transport = transport
stdin,stdout,stderr = ssh.exec_command('whoami')
print stdout.read().decode('utf-8')
transport.close()
SFTPClient
paramiko模块学习笔记的更多相关文章
- Python 日期时间处理模块学习笔记
来自:标点符的<Python 日期时间处理模块学习笔记> Python的时间处理模块在日常的使用中用的不是非常的多,但是使用的时候基本上都是要查资料,还是有些麻烦的,梳理下,便于以后方便的 ...
- 审计系统---paramiko模块学习
paramiko模块学习 [更多参考]http://www.cnblogs.com/wupeiqi/articles/4963027.html [paramiko的Demo实例]https://git ...
- python paramiko模块学习分享
python paramiko模块学习分享 paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.paramiko支持Linux, Sola ...
- Python 3之str类型、string模块学习笔记
Windows 10家庭中文版,Python 3.6.4, Python 3.7官文: Text Sequence Type — str string — Common string operatio ...
- Scikit-Learn模块学习笔记——数据集模块datasets
scikit-learn 的 datasets 模块包含测试数据相关函数,主要包括三类: datasets.load_*():获取小规模数据集.数据包含在 datasets 里 datasets.fe ...
- 【Python】logging模块学习笔记
因为做接口自动化测试遇到的一个代码逻辑上的问题,又不知道具体问题出在哪里,所以在模块化代码之前,先学习下python的日志模块logging. 入门1 入门2 日志级别大小关系为:CRITICAL & ...
- Python装饰器、metaclass、abc模块学习笔记
(博客原创作品,转载请注明出处!) 最近接触到了Python中的decorator,metaclass,abc Module,six.add_metaclass等内容,这里做一个简单的笔记. 主要资源 ...
- Python shutil 模块学习笔记
学于https://automatetheboringstuff.com shutil 名字来源于 shell utilities,有学习或了解过Linux的人应该都对 shell 不陌生,可以借此来 ...
- Python模块学习笔记
1.作用域 私有private:用'_x'或'__xx'表示,如,_a,__ab; 公有public: 如 a,b; 特殊变量,可被直接引用,如:__author__,__name__,命名变量时一般 ...
随机推荐
- ArchLinux简单介绍
一.Archlinux的由来 2002年由加拿大的Judd Vinet,Archlinux的创始人 怀着对Debian.Redhat的包管理器不满,于是创建了Archlinux!目前ArchLinux ...
- 继续聊WPF——自定义滚动条
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winf ...
- Python-Pandas简单操作
1.直接构建复杂嵌套索引 2. MultiIndex方式构建复杂的索引 多层索引操作 pandas堆叠处理
- Spring Cloud系列(三) 应用监控与管理Actuator
Spring Cloud系列(二) 应用监控与管理Actuator 前言:要想使用Spring Cloud ,Spring Boot 提供的spring-boot-starter-actuator模块 ...
- JUnit单元测试实践:测试工具类和方法(EmptyUtils)
以前的时候(读大学时),我认为写单元测试太费事了.现在,我改变看法了. 工作中,为了提高Web开发的质量和效率,近期又为了保证自己的工具类等一系列可复用组件的质量,我煞费苦心地开始认真学习和撰写单元测 ...
- BABEL转码解惑
众所周知,解决Nodejs异步问题的终极方案就是使用async/await方案,但是每次在项目中配置都会或多或少有些问题,每次都会被几个组件 babel-core babel-polyfill bab ...
- Spring Cloud-Bus(十二)
说明 用于分布式上所有微服务都连接到消息总线上面.进行统一的通知 Config动态刷新 configClient configClient通过/actuator/bus-refresh端点通知消息总线 ...
- ubuntu-kill命令-杀死进程
显示进程pid ps -A 杀进程的命令 kill -s 9 xxx(进程pid)
- CODEVS——T 1297 硬币
http://www.codevs.cn/problem/1297/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Descrip ...
- 修改oracle客户端的字符集
客户端字符集环境select * from nls_instance_parameters,其来源于v$parameter, 表示客户端的字符集的设置,可能是参数文件,环境变量或者是注册表 方法有 : ...