2017-02-16 201 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

相關問題