paramiko

Paramiko SSH failing with “Server '…' not found in known_hosts” when run on web server

旧城冷巷雨未停 提交于 2020-01-28 10:13:08
问题 I am trying to use Paramiko to make an SSH communication between 2 servers on a private network. The client server is a web server and the host server is going to be a "worker" server. The idea was to not open up the worker server to HTTP connections. The only communication that needs to happen, is the web server needs to pass strings to a script on the worker server. For this I was hoping to use Paramiko and pass the information to the script via SSH. I set up a new user and created a test

paramiko

余生颓废 提交于 2020-01-26 10:30:32
paramiko 什么是paramiko? 基于ssh用于连接远程服务器做操作:远程执行命令。上传文件 import paramiko # ssh username@ip passwd # 创建一个ssh对象 client = paramiko . SSHClient ( ) 解决的问题 :如果之前没有连接过的ip 会出现 # 自动选择yes client . set_missing_host_key_policy ( paramiko . AutoAddPolicy ( ) ) # 连接的服务器 client . connect ( hostname = '172.25.254.11' , username = 'root' , password = 'westos' ) # 执行操作 # 标准输入 标准正确输出 标准错误输出 stdin , stdout , stderr = client . exec_command ( 'hostname' ) # 获取命令的执行结果 print ( stdout . read ( ) . decode ( 'utf-8' ) ) # 关闭连接 client . close ( ) paramiko批量远程密码连接 from paramiko . ssh_exception import NoValidConnectionsError ,

使用Paramiko库sftp远程主机上传下载文件

China☆狼群 提交于 2020-01-24 09:55:14
前一篇文章说了怎样通过 Paramiko 来 SSH 到远程主机执行命令,今天看看怎样通过 Paramiko 使用 SFTP 来传输文件。 import paramiko transport = paramiko . Transport ( ( < host > , 22 ) ) transport . connect ( username = < username > , password = < password > ) sftp = paramiko . SFTPClient . from_transport ( transport ) # 上传文件 sftp . put ( 'readme.md' , '/home/kongxx/readme.md' ) # 下载文件 sftp . get ( '/home/kongxx/readme.md' , 'readme_new.md' ) # 列出目录下文件 files = sftp . listdir ( '/home/kongxx' ) for file in files : print ( file ) transport . close ( ) 来源: CSDN 作者: kongxx 链接: https://blog.csdn.net/kongxx/article/details/103753749

Reading output of Top command using Paramiko

孤街醉人 提交于 2020-01-24 05:35:06
问题 I am writing a script in Python for login to ssh and read the output of commands just executed. I am using paramiko package for this. I am trying to execute command "top" and get its output printed on the console. However, I am not able to do this. Please find the snippet: import sys import time import select import paramiko host = 'localhost' i = 1 # # Try to connect to the host. # Retry a few times if it fails. # while True: print 'Trying to connect to %s (%i/30)' % (host, i) try: ssh =

python模块

与世无争的帅哥 提交于 2020-01-24 04:57:35
一、模块(Module)定义   为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件包含的代码就相对较少,很多编程语言都采用这种组织代码的方式。在Python中,一个.py文件就称之为一个模块(Module)。 模块好处:   1、最大的好处是大大提升了代码的 可维护性 。   2、编写代码不必从零开始,当一个模块编写完毕,就可以被其他地方引用( 可重用 )   3、使用模块可以 避免函数名和变量名冲突     每个模块有独立的命名空间,相同名字函数、变量可分别存在不同模块     编写模块时,不必考虑名字与其他模块冲突 模块分类:   1、 内置标准模块(标准库) 执行help('modules')查看所有Python自带模块列表   2、 第三方开源模块 ,可通过pip install模块名 联网安装   3、 自定义模块 二、模块调用 模块导入方法   第一种:import module 把整个模块都导入 import os   第二种:from module import xx 是从什么导入什么 from os import rmdir,rename # 可以一次导入多个子模块   第三种:from module xx.xx import xx as rename from django.core import handler # 一层层进入

PySFTP failing with “No hostkey for host X found” when deploying Django/Heroku

若如初见. 提交于 2020-01-23 17:27:32
问题 I'm trying to deploy a Django web application which uses pysftp to access to a SFTP server through some views. The thing was perfectly working in local development, but when trying the first deployment on Heroku, the traceback below appeared ending with an error. It seems like I need to configure host keys and I believe I also need to set them in known_hosts at Heroku, but I have no idea about how to do that. In local development I was accessing with user/password without a problem, but from

Paramiko not working properly after cx_Freeze?

霸气de小男生 提交于 2020-01-23 14:13:54
问题 so I've writing this code where I connect to a computer over SSH using Paramiko, the script works normally, but when I convert it to ".exe" using cx_Freeze the program stops working at "self.ssh.load_system_host_keys", so i remove that function from the script and it kept working as usual (maybe not always needed?), but then again, when I converted the script to .exe, it was the "self.ssh.connect" function of Paramiko which now seems to be stopping the program, and by that i mean, no

Kill remote session after certain time, if no response from command launched on remote server using Paramiko

可紊 提交于 2020-01-21 09:50:14
问题 I am having some trouble with Paramiko module while running a command on remote server. def check_linux(cmd, client_ip, client_name): port = 22 username = 'xxxxxxx' password = 'xxxxxxxx' try: sse = paramiko.SSHClient() sse.set_missing_host_key_policy(paramiko.AutoAddPolicy()) sse.connect(client_ip, port, username, password, timeout=5) (stdin, stdout, stderr) = sse.exec_command("my cmd") del stdin status = stdout.read() status = status.decode('ascii') return status except (paramiko

How to send an arrow key use paramiko library in python?

余生长醉 提交于 2020-01-14 19:31:46
问题 I'm using python 2.7 and code ssh client with paramiko library, I use myhost.channel.send(chr(keycode)) to send every keycode to server. But It only works with 1 byte keycodes. I want to send other multi-byte keycodes like arrow keys. How can I achieve this? Please help me. 回答1: A GUI like Windows or MacOS identifies keys with 'keycodes', but an SSH pipe just transfers bytes, not keycodes. Assuming the program running inside ssh on your server is interactive (that is, it's expecting a human

How to send an arrow key use paramiko library in python?

寵の児 提交于 2020-01-14 19:30:30
问题 I'm using python 2.7 and code ssh client with paramiko library, I use myhost.channel.send(chr(keycode)) to send every keycode to server. But It only works with 1 byte keycodes. I want to send other multi-byte keycodes like arrow keys. How can I achieve this? Please help me. 回答1: A GUI like Windows or MacOS identifies keys with 'keycodes', but an SSH pipe just transfers bytes, not keycodes. Assuming the program running inside ssh on your server is interactive (that is, it's expecting a human