2017-02-16 205 views
10

我正在尝试在Windows PC和Linux服务器(amazon ec2)之间建立SSH连接。如何使用Fabric通过代理建立SSH连接?

我决定使用使用python实现的Fabric API。

我在Windows PC上安装了Putty。

我fabfile脚本是这样的:

import sys 
from fabric.api import * 


def testlive(): 
    print 'Test live ...' 
    run("uptime") 

env.use_ssh_config = False 
env.host_string = "host.something.com" 
env.user = "myuser" 
env.keys_filename = "./private_openssh.key" 
env.port = 22 
env.gateway = "proxyhost:port" 

testlive() 

我在用私钥同一目录下运行面料。

我可以使用腻子在本机上登录。

问题:我一直要求输入指定用户的登录密码。

基于其他职位(herehere)我已经尝试过:

  • 通作为一个列表中的密钥文件env.keys_filename
  • 使用用户名@ host_string
  • 使用env.host代替env.host_string

如何正确配置Fabric来处理代理服务器和ssh私钥文件?

+0

'“host.something.com”'等于'user @ ip_addr_numbers'?你的模块如何处理'wellcome'和'handshake'? – dsgdfg

回答

1

以下应该工作。

env.key_filename = "./private_openssh.key" 

(请注意你的企图错字)

+0

它不工作:) –

2

面料的API是最真的避免了太多的错误和问题(见问题跟踪)。

你可以做你想做的事,用Python以下几点:

from __future__ import print_function 

from pssh import ParallelSSHClient 
from pssh.utils import load_private_key 

client = ParallelSSHClient(['host.something.com'], 
          pkey=load_private_key('private_openssh.key'), 
          proxy_host='proxyhost', 
          proxy_port=<proxy port number>, 
          user='myuser', 
          proxy_user='myuser') 
output = client.run_command('uname') 
for line in output['host.something.com'].stdout: 
    print(line) 

ParallelSSH可从PIP为parallel-ssh

+0

感谢您的建议。我会尽快尝试。 –

0

的puttygen是你将用什么来生成SSH密钥,然后上传复制SSH密钥到您的云管理门户网站 - See Joyant

+0

这是默认强制性的:)我已经很久以前做了:) –

-1

你将不得不生成和验证私有密钥,这样做,你需要的puttygen使用带密码的RSA密钥,密钥注释并符合密钥密码来生成SSH访问,这里是一步一步的指导文档SSH Access using RSA Key Authentication

相关问题