10

最初にファブリックを機能させようとしましたが、パスワードを何度も要求されました。

だから私は問題を減らそうとしています。おそらく、Python から SSH 接続を作成するだけでよい POC になるでしょう。fabric が SSH 処理に parmiko を使用していることを発見しました。うーん。では、例を動かしてみましょう。

これが私が書いたものです。

from ssh import *
import os 

print "SSH-AGENT VARS"

print "SSH_AGENT_PID: %s " % os.environ['SSH_AGENT_PID']
print "SSH_AUTH_SOCK: %s " % os.environ['SSH_AUTH_SOCK']

a = Agent()
keys=a.get_keys()
print keys.count("192.168.1.10")


client = SSHClient()
client.load_system_host_keys()
client.connect('192.168.1.10')

次のエラー メッセージが表示されます。

% ./ssh_test.py
SSH-AGENT VARS
SSH_AGENT_PID: 26557 
SSH_AUTH_SOCK: /tmp/ssh-pZHBElj26556/agent.26556 
0
Traceback (most recent call last):
  File "./ssh_test.py", line 18, in <module>
    client.connect('192.168.1.10')
  File "/usr/local/lib/python2.7/dist-packages/ssh/client.py", line 332, in connect
    self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
  File "/usr/local/lib/python2.7/dist-packages/ssh/client.py", line 493, in _auth
    raise saved_exception
ssh.PasswordRequiredException: Private key file is encrypted

セッションで ssh-agent が実行されています。そのボックスに SSH で接続できます。問題はありません。パスワードなどの入力を求めるプロンプトは表示されません。

何らかの奇妙な理由で、paramiko が実行中の ssh-agent に接続できないと推測しています。

他の誰かがこのような問題を抱えていましたか? Ubuntu 11.10 を使用しています

しばらく前に Fabric を試して同様の問題を抱えていたのを覚えているようですが、しばらくの間壊れていたのでしょうか?

ホスト名を引数として使用するだけで接続します。これはドキュメントのとおりです。

http://www.lag.net/paramiko/docs/paramiko.SSHClient-class.html

connect(self, hostname, port=22, username=None, password=None, pkey=None, key_filename=None, timeout=None, allow_agent=True, look_for_keys=True, compress=False)
4

5 に答える 5

7

したがって、リストを返す必要があるa.get_keys()を実行すると、paramikoコードとあなたのコードから。私はそれが何を返すかを見るでしょう。また、実際の暗号化されたキービットを返すため、そのように数えることができるものは返されません。しかし、とにかく、sshに移行し、それが機能するので、Fabricに移行しましょう。

次のようにして、ssh libに対してオンにすることで、より多くのログを取得できます。

import ssh
ssh.util.log_to_file("paramiko.log", 10)

fabfileで。これにより、すべてのログが表示され、paramiko / ssh自体が実行していることの詳細が表示され、問題をさらにデバッグするのに役立つ場合があります。

于 2012-03-28T05:01:09.480 に答える
5

さて、私が最初に発見したのは、パラミコが時代遅れで、メンテナンスされていないということでした。

少なくともUbuntuではパッケージsshとして知られ、別のメンテナ(bitprophet)があります。

これを使用したサンプルセッションは次のとおりです。

$ ./ssh_demo.py
Hostname: 192.168.1.10
*** Host key OK.
Username [bryan]: root
Trying ssh-agent key eee5638f390e1698898984b10adfa9317 ... success!
*** Here we go!

Linux top.secret.com 2.9.37-1-amd64 #1 SMP Thu Nov 3 03:41:26 UTC 2011 x86_64
┌┌(root@top)-(10:44am-:-03/27)┌-¨-¨¨˙

それは、ファブリックがssh-agentに対して正しく認証されていない理由の質問に答えるものではありません。したがって、質問は未解決のままです。

アップデート:

モーガンのヒントのおかげで、私はこの問題についてもう少し進んだ。彼が提案したように、fabfile.pyの先頭に以下を追加してsshロギングを有効にしました

from fabric.api import *
import ssh
ssh.util.log_to_file("paramiko.log", 10)

サーバーログも監視しました。そうすることで、指定したユーザーが無視され、代わりにローカルユーザー名が使用されていることがわかりました。

サーバー上:

tail -f /var/log/auth.log 
Mar 28 11:12:36 xxxxxxxxxxx sshd[17652]: Invalid user bryan from xxx.xxx.xxx.xxx

ローカル:

tail -f paramiko.log    
DEB [20120328-11:39:29.038] thr=1   ssh.transport: starting thread (client mode): 0x8dfc66cL
INF [20120328-11:39:29.066] thr=1   ssh.transport: Connected (version 2.0, client OpenSSH_5.5p1)
DEB [20120328-11:39:29.093] thr=1   ssh.transport: kex algos:['diffie-hellman-group-exchange-sha256', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', 'rijndael-cbc@lysator.liu.se'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', 'rijndael-cbc@lysator.liu.se'] client mac:['hmac-md5', 'hmac-sha1', 'umac-64@openssh.com', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', 'umac-64@openssh.com', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] client lang:[''] server lang:[''] kex follows?False
DEB [20120328-11:39:29.093] thr=1   ssh.transport: Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
DEB [20120328-11:39:29.093] thr=1   ssh.transport: using kex diffie-hellman-group1-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
DEB [20120328-11:39:29.183] thr=1   ssh.transport: Switch to new keys ...
DEB [20120328-11:39:29.224] thr=2   ssh.transport: Trying SSH agent key cda5638f390e166864444b1093b91017
DEB [20120328-11:39:29.272] thr=1   ssh.transport: userauth is OK
INF [20120328-11:39:53.310] thr=1   ssh.transport: Authentication (publickey) failed.
DEB [20120328-11:41:29.076] thr=1   ssh.transport: EOF in transport thread

うーん、それは奇妙です、私は次のようにコマンドを実行しました:fab diskfree -H xxx.xxx.xxx.xxx -u root

しかし、これは何ですか?

$ cat ./fabfile.py
from fabric.api import *
import ssh
ssh.util.log_to_file("paramiko.log", 10)

env.user = 'bryan'

def host_type():
 run('uname -s')

def diskfree():
 run('df -h') 

うーん

env.user = 'bryan'

それが問題の原因でしょうか?sshエラーメッセージは私を誤解させるだけでしょうか?

行を削除して機能したので、そうだと思います。

于 2012-03-27T09:49:41.613 に答える
1

passwordへのキーワード引数としてパスフレーズを指定しようとしますconnect()

のドキュメントに記載されているように、特定のものが提供されていない場合は、システムで見つけることができるSSHCLient.connect()ものを使用します。PKeyクラス メソッドfrom_private_key()from_private_key_file()(どちらが呼び出されるかはわかりませんが、おそらく両方) は、オプションの引数を取りますpassword。ドキュメントによると、

秘密鍵が暗号化されていて、パスワードが None でない場合、指定されたパスワードが鍵の復号化に使用されます (それ以外の場合は PasswordRequiredException がスローされます)。

...これはおそらくあなたの場合に起こっていることです。

于 2012-03-26T21:26:18.333 に答える
-1

おそらく、エージェントにキーを追加するために実行する必要があります。

$ ssh-add ~/.ssh/id_dsa 

https://groups.google.com/forum/?fromgroups=#!topic/ansible-project/yRSMmlqKsAA

于 2012-12-22T14:06:44.750 に答える