【python安装paramiko模块】教程文章相关的互联网学习教程文章

python – 由Paramiko无法识别由ssh-keygen生成的SSH密钥:“不是有效的RSA私钥文件”【代码】

我有以下代码:ssh_key = paramiko.RSAKey.from_private_key_file(key_filename)键看起来像这样:-----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn NhAAAAAwEAAQAAAQEAqdgmJ2AQlmvpCsDWjbpIvIrx4AwtKn2t10wmGZIN9pqcJgQpo3HD并且有效:$ssh-keygen -l -f <mykeyfile>$2048 SHA256:x8jlUAObU3q2KXRtuGpxwhnGvB/ZoeD2IUqSA1OkCmI thomas@Thomas-MBP-2017 (RSA)但是我收...

python – Paramiko的端口转发【代码】

我正在尝试使用Paramiko从python应用程序进行一些端口转发.我可以很好地设置SSH连接,但我对如何使用paramiko.Transport感到有点难过.我已经找到了this file,但我无法弄清楚它里面发生了什么.从查看paramiko.Transport docs,似乎单行使用open_channel函数,但我无法弄清楚如何实现它.我正在尝试复制一个简单的ssh -L 8000:localhost:8000. 谁能帮我吗?解决方法:请使用paramiko-1.7.7.1,pycrypto-2.6和forward.py script找到一些代...

如何通过python Paramiko与ppk公钥进行ssh连接【代码】

我正在使用Paramiko通过ssh连接到服务器. 基本身份验证运行良好,但我无法理解如何连接公钥. 当我用putty连接时,服务器告诉我这个:Using username "root". Authenticating with public key "rsa-key@ddddd.com" Passphrase for key "rsa-key@ddddd.com": [i've inserted the passphrase here] Last login: Mon Dec 5 09:25:18 2011 from ...我用这个ppk文件连接到它:PuTTY-User-Key-File-2: ssh-rsa Encryption: aes256-cbc Comm...

当使用Python Paramiko exec_command执行时,某些Unix命令失败并显示“未找到”【代码】

我试图在Paramiko exec_command的帮助下从Python在Unix服务器上运行sesu命令.但是当我运行这个命令exec_command(‘sesu test’)时,我得到了sh: sesu: not found当我运行简单的ls命令时,它给我所需的输出.只有使用sesu命令它才能正常工作. 这是我的代码的样子:import paramikohost = host username = username password = password port = portssh=paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy(...

python – Paramiko“未知服务器”【代码】

我正在尝试开始使用Paramiko库,但是当我尝试连接以下简单程序时,库就会抛出异常:import paramiko ssh = paramiko.SSHClient() ssh.connect('127.0.0.1', username='boatzart', password='mypassword')我得到的错误是:Traceback (most recent call last): File "test.py", line 6, in <module> ssh.connect('127.0.0.1') File "build/bdist.macosx-10.7-intel/egg/paramiko/client.py", line 316, in connect File "build/bdist.m...

python – 使用ssh-keygen命令时Paramiko挂起【代码】

我正在创建一个用户,并希望为该用户设置ssh密钥 我的剧本是import paramikossh_conn = paramiko.SSHClient() ssh_conn.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_conn.load_system_host_keys() ssh_conn.connect('localhost', username='test', password='test')cmd = 'ssh-keygen -t dsa'stdin, stdout, stderr = ssh_conn.exec_command(cmd) stdin.write('\n') stdin.flush() stdin.write('\n') stdin.flush()...

python – Paramiko:从公钥字符串创建一个PKey【代码】

我试图在低级别使用SSH协议(即我不想启动shell或任何东西,我只想传递数据).因此,我直接使用Paramiko的Transport课程. 我已经完成了服务器端,但现在我正在用愚蠢的东西撞墙.对于客户端连接到服务器,Transport的connect method将两个PKey对象作为参数:客户端的私钥(pkey)和服务器的公钥(hostkey). PKey类被描述为“公钥的基类”.然而问题是我无法弄清楚如何用ssh公钥创建这样的PKey对象(即字符串ssh-无论是AAblablabla).它有从私钥构...

python – paramiko ssh.connect – 要发送什么参数?【代码】

我真的是python和ssh的新手. 我正在尝试编写一个简单的程序来使用python打开ssh连接.我已经有了paramiko,但我遇到的问题是: 使用终端我使用以下命令打开我的ssh:ssh username%hostname@gw.cs.huji.ac.il现在我不知道发送什么参数 – ssh.connect() 有任何想法吗?解决方法:在paramiko documentation中有以下示例:client = SSHClient() client.load_system_host_keys() client.connect('ssh.example.com') stdin, stdout, stder...

python – 从Paramiko命令中捕获标准【代码】

我有一个Paramiko的SSHClient.exec_command()包装器.我想捕捉标准.这是我的函数的缩短版本:def __execute(self, args, sudo=False, capture_stdout=True, plumb_stderr=True,ignore_returncode=False):argstr = ' '.join(pipes.quote(arg) for arg in args)channel = ssh.get_transport().open_session()channel.exec_command(argstr)channel.shutdown_write()# Handle stdout and stderr until the command terminatescaptured =...

python – paramiko中的管道命令【代码】

我如何在paramiko中运行管道命令?我这样做: – statement = 'grep thing file | grep thing2 | tail -1' last_msg = conn.execute(statement)我只得到grep thing文件的输出.解决方法:因为grep不知道如何处理|.准备好一些讨厌的逃脱:statement = """sh -c 'grep thing file | grep thing2 | tail -1'"""这会在另一侧创建一个shell,并要求它解释字符串grep thing file | grep thing2 |尾巴-1.单引号是必要的,因为sh -c只接受一个参...

Python模块学习 - Paramiko

Python模块学习 - Paramiko ?阅读目录 回到顶部 简介 ssh是一个协议,OpenSSH是其中一个开源实现,paramiko是Python的一个库,实现了SSHv2协议(底层使用cryptography)。 有了Paramiko以后,我们就可以在Python代码中直接使用SSH协议对远程服务器执行操作,而不是通过ssh命令对远程服务器进行操作。 由于paramiko属于第三方库,所以需要使用如下命令先行安装?1pip3 install paramiko回到顶部 Paramiko介绍 paramiko包含两个核心组件...

Python paramiko模块(实现ssh)【代码】

开发堡垒机之前,先来学习Python的paramiko模块,该模块基于SSH用于连接远程服务器并执行相关操作 安装paramiko模块 pip3 install paramiko 基于用户密码方式 import paramiko# 创建SSH对象 ssh = paramiko.SSHClient() # 允许连接不在know_hosts文件中的主机 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # 连接服务器 ssh.connect(hostname="10.0.0.200", port=22, username='root', password='1')# 执行命令 # s...

python – 面料和Paramiko【代码】

我试图在我的CentOS 6.2上安装Fabric. 从GitHub克隆结构,通过setup.py install安装它 现在面料本身有效,但当我尝试使用本地时:from fabric.api import localdef say_hi():local("echo hi!")我收到一个错误:$fab say_hi Traceback (most recent call last):File "/usr/bin/fab", line 5, in <module>from pkg_resources import load_entry_pointFile "/usr/lib/python2.6/site-packages/pkg_resources.py", line 2655, in <module...

python – Paramiko SSH隧道关闭问题【代码】

我正在研究一个python脚本,经常在已建立的ssh隧道上查询一些远程数据库.我对paramiko库非常熟悉,所以这是我选择的路线.我更喜欢将它保留在完整的python中,因此我可以使用paramiko来处理关键问题,以及使用python来启动,控制和关闭ssh隧道. 这里有关于这个主题的一些相关问题,但大多数问题似乎都不完整.我下面的解决方案是我迄今为止找到的解决方案. 现在问题是:我能够很容易地创建第一个隧道(在一个单独的线程中)并执行我的DB / py...

Python守护程序中的Paramiko导致IOError【代码】

我正在尝试使用python守护进程内部的paramiko执行ssh命令.我正在为守护进程使用以下实现:https://pypi.python.org/pypi/python-daemon/ 当程序启动时,当paramiko尝试连接时,pycrypto会使用Bad文件描述符引发IOError.如果我删除守护程序代码(只是取消注释最后一行并注释上面两个),则按预期建立ssh连接. 短测试程序的代码如下所示:#!/usr/bin/env python2 from daemon import runner import paramikoclass App():def __init__(self...

模块 - 相关标签