day9---paramiko ssh ftp
安装 paramiko模块
win下:
进入到\Python35\Scripts>
执行:pip install paramiko
Linux:
先升级下pip :
pip3.5 install --upgrade pip
然后安装paramiko
pip3.5 install paramiko
Downloading paramiko-2.0.2-py2.py3-none-any.whl Downloading cryptography-1.5.tar.gz Downloading pyasn1-0.1.9-py2.py3-none-any.whl Downloading idna-2.1-py2.py3-none-any.whl Downloading six-1.10.0-py2.py3-none-any.whl Downloading cffi-1.8.3.tar.gz Downloading pycparser-2.14.tar.gz Downloading cffi-1.8.3-cp35-cp35m-manylinux1_x86_64.whl
>>> import paramiko
>>>
代表成功
paramiko实现ssh、scp
SSHClient 用于连接远程服务器并执行基本命令
#!/usr/bin/env python
#-*- coding:utf-8 -*-
# Author:DCC import paramiko # 创建SSH对象
ssh = paramiko.SSHClient()
# 允许连接不在know_hosts文件中的主机
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 连接服务器
ssh.connect(hostname='192.168.193.128', port=22, username='root', password='123dc.')
# 执行命令
stdin, stdout, stderr = ssh.exec_command('df')
# 获取命令结果
#result = stdout.read()
res,err = stdout.read(),stderr.read()
#print(result.decode())
print(res.decode())
print(err.decode())
# 关闭连接
ssh.close() #执行结果
C:\Users\congcong.du\AppData\Local\Programs\Python\Python35\python.exe C:/Users/congcong.du/PycharmProjects/test/day9/paramiko_test/ssh_test.py
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
8649736 8152208 51476 100% /
tmpfs 502068 0 502068 0% /dev/shm
/dev/sda1 487652 128958 333094 28% /boot
SFTPClient 用于连接远程服务器并执行上传下载
#!/usr/bin/env python
#-*- coding:utf-8 -*-
# Author:DCC import paramiko transport = paramiko.Transport(('localhost', 22))
transport.connect(username='root', password='123dc.') sftp = paramiko.SFTPClient.from_transport(transport)
# 将location.py 上传至服务器 /tmp/test.py
sftp.put('/tmp/location.py', '/tmp/test.py')
# 将remove_path 下载到本地 local_path
sftp.get('remove_path', 'local_path')
transport.close()
基于公钥密钥连接
服务器无密码验证
&&&&&&&&&&&&&&
#ssh-keygen -t rsa
连着三个回车
#ssh-copy-id -i root@119.40.36.231
输入密码,回车。
哦了。
&&&&&&&&&&&&&&
基于公钥链接
import paramiko
private_key = paramiko.RSAKey.from_private_key_file('/home/auto/.ssh/id_rsa')
# 创建SSH对象
ssh = paramiko.SSHClient()
# 允许连接不在know_hosts文件中的主机
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 连接服务器
ssh.connect(hostname='c1.salt.com', port=22, username='wupeiqi', key=private_key)
# 执行命令
stdin, stdout, stderr = ssh.exec_command('df')
# 获取命令结果
result = stdout.read()
# 关闭连接
ssh.close()
基于公钥ftp
import paramiko
private_key = paramiko.RSAKey.from_private_key_file('/home/auto/.ssh/id_rsa')
transport = paramiko.Transport(('hostname', 22))
transport.connect(username='wupeiqi', pkey=private_key )
sftp = paramiko.SFTPClient.from_transport(transport)
# 将location.py 上传至服务器 /tmp/test.py
sftp.put('/tmp/location.py', '/tmp/test.py')
# 将remove_path 下载到本地 local_path
sftp.get('remove_path', 'local_path')
transport.close()
day9---paramiko ssh ftp的更多相关文章
- paramiko SSH 模块简单应用。
目的:需要ssh链接到Linux主机,执行telnet 命令,抓回显匹配制定内容. ssh --->执行telnet到本地端口--->执行类似 ls 的命令.匹配命令执行后的特定回显字段. ...
- Python 模块功能paramiko SSH 远程执行及远程下载
模块 paramiko paramiko是一个用于做远程控制的模块,使用该模块可以对远程服务器进行命令或文件操作,值得一说的是,fabric和ansible内部的远程管理就是使用的paramiko来现 ...
- ROS 禁止公网暴力破解SSH FTP
最简单的彻底禁止公网访问SSH FTP端口 1 2 /ip firewall filter add chain=input protocol=tcp dst-port=21-22 src-addres ...
- Linux SSH,FTP服务配置
CentOS-6.4-x86_64-minimal 0.网卡配置 参考:Linux系统\Centos没有网卡eth0配置文件怎么办? - http://jingyan.baidu.com/articl ...
- Linux expect自动登录ssh,ftp
[http://blog.51yip.com/linux/1462.html#] #!/usr/bin/expect -f set ip 192.168.1.201 set password meim ...
- 更改ssh,ftp默认端口
1. 更改ssh端口 放置升级openssh之后做此步骤 配置文件/etc/ssh/sshd_config 注释掉Subsystem sftp /usr/libexec/openss ...
- Kali Linux 初始化配置:Apache2 /SSH /FTP
Kali Linux是基于Debian的Linux发行版, 设计用于数字取证操作系统.Kali Linux预装了许多渗透测试软件,包括nmap .Wireshark .John the Ripper, ...
- Python paramiko ssh 在同一个session里run多个命令
import threading, paramiko strdata='' fulldata='' class ssh: shell = None client = None transport = ...
- Different between Telnet/SSH/FTP
http://www.differencebetween.net/category/technology/protocols-formats/ Telnet vs SSH Secure Shell, ...
随机推荐
- c#窗体虚线图形验证码设计
/************************窗体验证码背景图形设计及核心代码**********/ using System;using System.Collections.Generic;u ...
- jQuery easyui combobox获取值|easyui-combobox获取多个值
Query easyui combobox事例: name="language" data-options=" ...
- nignx软件安装与调试
1.通过yum或下载相应软件包安装nginx所需要的辅助软件:pcre.pcre-devel.openssl.openssl-devel.make.gcc.gcc+ 2.解压已经下载好的nginx软件 ...
- Oracle重启 error: ora-01034:oracle not available ora-27101:shared memory realm does not exist
error: ora-01034:oracle not available ora-27101:shared memory realm does not exist 苦咖啡 他的博客中一篇文章完美的解 ...
- JsonString,字典,模型之间相互转换
NSData转字符串 [NSString alloc] initWithData: encoding:] 模型转字典 attInfo.keyValues 字典转模型 ZTEOutputInfo *ou ...
- SVM学习笔记(二):什么是交叉验证
交叉验证:拟合的好,同时预测也要准确 我们以K折交叉验证(k-folded cross validation)来说明它的具体步骤.{A1,A2,A3,A4,A5,A6,A7,A8,A9} 为了简化,取 ...
- c# DESEncrypt 加密、解密算法
using System; using System.Security.Cryptography; using System.Text; namespace AttendService { publi ...
- tomcat(三)--基本安装配置
0x01 JDK和Tomcat安装 到oracle官网下载jdk,当前下载的版本是Linux x64 jdk-8u101-linux-x64.tar.gz 到apache官网下载tomcat,当前最 ...
- 刨一刨内核container_of()的设计精髓
新年第一帖,总得拿出点干货才行,虽然这篇水分还是有点大,大家可以晒干了温水冲服.这段时间一直在整理内核学习的基础知识点,期间又碰到了container_of()这个宏,当然还包括一个叫做offseto ...
- C# ToString("x2")的理解
1).转化为16进制. 2).大写X:ToString("X2")即转化为大写的16进制. 3).小写x:ToString("x2")即转化为小写的16进制. ...