paramiko

Why does Paramiko hang if you use it while loading a module?

坚强是说给别人听的谎言 提交于 2019-11-26 22:17:50
问题 Put the following into a file hello.py (and easy_install paramiko if you haven't got it): hostname,username,password='fill','these','in' import paramiko c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(hostname=hostname, username=username, password=password) i,o,e = c.exec_command('ls /') print(o.read()) c.close() Fill in the first line appropriately. Now type python hello.py and you'll see some ls output. Now instead type python and then from within

Python - pysftp / paramiko - Verify host key using its fingerprint

落花浮王杯 提交于 2019-11-26 21:43:55
问题 This code throws an exception. How can I verify an SSH fingerprint without storing it in a file? I believe the code below is designed for a public key. But the client with the SFTP server validated the fingerprint and did not get me the public key. import os import shutil import pysftp import paramiko connection_info = { 'server': "example.com", 'user': "user", 'passwd': "password", 'target_dir': "out/prod", 'hostkey': "ssh-rsa 2048 d8:4e:f1:f1:f1:f1:f1:f1:21:31:41:14:13:12:11:aa", } def move

How to list all the folders and files in the directory after connecting through SFTP in Python

一世执手 提交于 2019-11-26 20:57:56
问题 I am using Python and trying to connect to SFTP and want to retrieve an XML file from there and need to place it in my local system. Below is the code: import paramiko sftpURL = 'sftp.somewebsite.com' sftpUser = 'user_name' sftpPass = 'password' ssh = paramiko.SSHClient() # automatically add keys without requiring human intervention ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy() ) ssh.connect(sftpURL, username=sftpUser, password=sftpPass) ftp = ssh.open_sftp() files = ftp.listdir()

installing paramiko on Windows

断了今生、忘了曾经 提交于 2019-11-26 20:45:43
问题 This may sound like a repeated question on SF, but I could not find a clear answer to it, yet.So. I installed Paramiko 1.7 with "setup.py install" command and while running the demo.py program, I got this error: Traceback (most recent call last): File "C:\Documents and Settings\fixavier\Desktop\paramiko-1.7\demos\demo.py", line 33, in <module> import paramiko File "C:\Python26\lib\site-packages\paramiko\__init__.py", line 69, in <module> from transport import randpool, SecurityOptions,

[转载]----Python Paramiko模块安装使用

孤者浪人 提交于 2019-11-26 20:31:29
本文说明:   本文属于转载,原文是:http://www.cnblogs.com/xia520pi/p/3805043.html 1、简介   大家会发现,常见的解决方法都会需要对远程服务器必要的配置,如果远程服务器只有一两台还好说,如果有N台,还需要逐台进行配置,或者需要使用代码进行以上操作时,上面的办法就不太方便了。   使用paramiko可以很好的解决以上问题,比起前面的方法,它仅需要在本地上安装相应的软件(python以及PyCrypto),对远程服务器没有配置要求,对于连接多台服务器,进行复杂的连接操作特别有帮助。 2、安装   安装paramiko有两个先决条件,python和另外一个名为PyCrypto的模块。   通常安装标准的python模块,只需要在模块的根目录下运行: python setup.py build python setup.py install 备注:安装前先检查是否安装gcc(yum -y install gcc) 2.1 PyCrypto安装 wget http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.tar.gz tar -zxvf pycrypto-2.6.tar.gz cd pycrypto-2.6/ python setup.py build && python

纪录一下这几天遇到的问题,以便以后查看

核能气质少年 提交于 2019-11-26 19:56:07
1.安装paramiko模块   python实现OpenSSH依赖于paramiko模块,安装paramiko模块又依赖于pycrypto模块,pycrypto模块又依赖于对应版本的MSVS(Microsoft Visual Studio)。因此要想在python中使用SSH,我们需要先安装正确版本的VS和pycrypto,然后再安装paramiko模块 在用cmd命令安装pycrypto的时候,不知道是什么原因一直报错,然后我就想着直接略过这一步安装paramiko模块,然后我就去下载了个老版本的paramiko模块,没想到直接装成功了,但是在pycharm调用的时候又出错了,错误原因是pycrypto未定义,只有老老实实的去装pycrypto了 pycrypto安装参考网址: https://blog.csdn.net/a624806998/article/details/78596543 paramiko安装参考网址: https://blog.csdn.net/byf0521hlyp/article/details/81064236 2.安装xshell以及centos系统 参考网址: https://blog.csdn.net/babyxue/article/details/80970526 xhell连接: https://www.jianshu.com/p

How do you execute multiple commands in a single session in Paramiko? (Python)

折月煮酒 提交于 2019-11-26 19:55:25
def exec_command(self, command, bufsize=-1): #print "Executing Command: "+command chan = self._transport.open_session() chan.exec_command(command) stdin = chan.makefile('wb', bufsize) stdout = chan.makefile('rb', bufsize) stderr = chan.makefile_stderr('rb', bufsize) return stdin, stdout, stderr When executing a command in paramiko, it always resets the session when you run exec_command. I want to able to execute sudo or su and still have those privileges when I run another exec_command. Another example would be trying to exec_command("cd /") and then run exec_command again and have it be in

Ubuntu下使用python实现全自动ssh免密登录设置

冷暖自知 提交于 2019-11-26 19:24:36
Ubuntu下使用python实现全自动ssh免密登录设置 本文主要是使用了python自带的模块os和第三方的模块paramiko,实现在知道用户名和密码的情况下,将ssh远程连接设置为免密登录的形式。本质就是为要登录的主机添加公钥,本机添加私钥。当然一切的前提是你已经开启了ssh服务。 这个函数也可以嵌入的你的代码中,在需要ssh登录的地方提前设置好免登录,今后就可以不用再输密码了。 本人在服务端的Ubuntu和centos上均测试通过。centos你可能需要修改一下sshd服务重启的指令。 import os, paramiko def ssh_authentication(server_ip, user, passwd): """进行ssh的免密码认证""" # server_id 备份服务器地址,字符串 logger.info("test ping server %s ..." % server_ip) if os.system("ping %s -c 3 >>/dev/null" % server_ip): # 先测试一下连通性 return -1 if os.path.exists(os.path.expanduser("~/.ssh/id_rsa")) and os.path.exists( os.path.expanduser("~/.ssh/id_rsa.pub

Nested SSH session with Paramiko

 ̄綄美尐妖づ 提交于 2019-11-26 18:42:01
I'm rewriting a Bash script I wrote into Python. The crux of that script was ssh -t first.com "ssh second.com very_remote_command" I'm having a problem with the nested authentication with paramiko. I wasn't able to find any examples dealing with my precise situation, but I was able to find examples with sudo on a remote host. The first method writes to stdin ssh.connect('127.0.0.1', username='jesse', password='lol') stdin, stdout, stderr = ssh.exec_command("sudo dmesg") stdin.write('lol\n') stdin.flush() The second creates a channel and uses the socket-like send and recv . I was able to get

Python自学第九周(1)

别等时光非礼了梦想. 提交于 2019-11-26 17:38:39
Day9 paramiko 实现ssh远程连接 1、简单的ssh 1 #Author: Zachary 2 import paramiko 3 4 # 创建SSH对象 5 ssh = paramiko.SSHClient() 6 # 允许连接不在know_hosts文件中的主机 7 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 8 9 # 连接服务器 10 ssh.connect(hostname='ip', port=22, username='root', password='password') 11 # 执行命令 12 stdin, stdout, stderr = ssh.exec_command('ls') 13 14 # 获取命令结果 15 res,err = stdout.read(),stderr.read() 16 result = res if res else err 17 print(result.decode()) 18 19 # 关闭连接 20 ssh.close() 2、封装ssh 1 #Author: Zachary 2 import paramiko 3 4 transport = paramiko.Transport(('ip', 22)) 5 transport