2010-11-09 37 views
9

Tôi gặp một vấn đề kết nối với một thiết bị với một paramiko (phiên bản 1.7.6-2) ssh client:paramiko AuthenticationException vấn đề

$ python 
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import paramiko 
>>> ssh = paramiko.SSHClient() 
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
>>> ssh.connect("123.0.0.1", username="root", password=None) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/lib/pymodules/python2.6/paramiko/client.py", line 327, in connect 
    self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys) 
    File "/usr/lib/pymodules/python2.6/paramiko/client.py", line 481, in _auth 
    raise saved_exception 
paramiko.AuthenticationException: Authentication failed. 
>>> 

Khi tôi sử dụng ssh từ dòng lệnh, nó hoạt động tốt:

ssh [email protected] 


BusyBox v1.12.1 (2010-11-03 13:18:46 EDT) built-in shell (ash) 
Enter 'help' for a list of built-in commands. 

# 

Bất cứ ai nhìn thấy điều này trước đây?

Sửa 1

Dưới đây là sản phẩm tiết của lệnh ssh:

:~$ ssh -v [email protected] 
OpenSSH_5.3p1 Debian-3ubuntu4, OpenSSL 0.9.8k 25 Mar 2009 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: Applying options for * 
debug1: Connecting to 123.0.0.1 [123.0.0.1] port 22. 
debug1: Connection established. 
debug1: identity file /home/waffleman/.ssh/identity type -1 
debug1: identity file /home/waffleman/.ssh/id_rsa type -1 
debug1: identity file /home/waffleman/.ssh/id_dsa type -1 
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1 
debug1: match: OpenSSH_5.1 pat OpenSSH* 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu4 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: server->client aes128-ctr hmac-md5 none 
debug1: kex: client->server aes128-ctr hmac-md5 none 
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent 
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP 
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent 
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY 
debug1: Host '123.0.0.1' is known and matches the RSA host key. 
debug1: Found key in /home/waffleman/.ssh/known_hosts:3 
debug1: ssh_rsa_verify: signature correct 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug1: SSH2_MSG_NEWKEYS received 
debug1: SSH2_MSG_SERVICE_REQUEST sent 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug1: Authentication succeeded (none). 
debug1: channel 0: new [client-session] 
debug1: Requesting [email protected] 
debug1: Entering interactive session. 
debug1: Sending environment. 
debug1: Sending env LANG = en_US.utf8 

Chỉnh sửa 2 Dưới đây là đầu ra python với sản lượng debug:

Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import paramiko, os 
>>> paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG) 
>>> ssh = paramiko.SSHClient() 
>>> ssh.load_system_host_keys() 
>>> ssh.load_host_keys(os.path.expanduser('~/.ssh/known_hosts')) 
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
>>> ssh.connect("123.0.0.1", username='root', password=None) 
DEBUG:paramiko.transport:starting thread (client mode): 0x928756cL 
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_5.1) 
DEBUG:paramiko.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-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', 'aes192-cbc', 'aes256-cbc', '[email protected]', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr'] server encrypt:['aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', 'aes192-cbc', 'aes256-cbc', '[email protected]', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr'] client mac:['hmac-md5', 'hmac-sha1', '[email protected]', 'hmac-ripemd160', '[email protected]', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', '[email protected]', 'hmac-ripemd160', '[email protected]', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False 
DEBUG:paramiko.transport:Ciphers agreed: local=aes128-ctr, remote=aes128-ctr 
DEBUG:paramiko.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 
DEBUG:paramiko.transport:Switch to new keys ... 
DEBUG:paramiko.transport:Trying discovered key b945197b1de1207d9aa0663f01888c3c in /home/waffleman/.ssh/id_rsa 
DEBUG:paramiko.transport:userauth is OK 
INFO:paramiko.transport:Authentication (publickey) failed. 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/lib/pymodules/python2.6/paramiko/client.py", line 327, in connect 
    self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys) 
    File "/usr/lib/pymodules/python2.6/paramiko/client.py", line 481, in _auth 
    raise saved_exception 
paramiko.AuthenticationException: Authentication failed. 
>>> 
+0

Tôi đã thử kết nối với QNAP TS-409 chạy Linux nhúng. Làm việc tốt. – hughdbrown

+0

Tôi đoán bạn có thể làm 'ssh root @ 123.0.0.1' để xem ssh đang kết nối như thế nào. –

+0

làm "ssh -v [email protected]" và xem liệu SSH có đang sử dụng xác thực khoá công khai hoặc một số phương pháp xác thực khác không? –

Trả lời

7

Máy chủ ssh trên thiết bị từ xa đã từ chối xác thực của bạn. Đảm bảo bạn đang sử dụng đúng khóa và thiết bị không có bất kỳ hạn chế truy cập nào khác. Thật khó để nói những gì đang xảy ra mà không có các bản ghi từ máy chủ.

[EDIT] Tôi vừa xem lại kết quả của bạn, bạn đang xác thực bằng cách sử dụng xác thực None. Điều này thường không bao giờ được phép và được sử dụng để xác định các phương thức xác thực nào được máy chủ cho phép. Có thể máy chủ của bạn đang sử dụng xác thực dựa trên máy chủ (hoặc không có gì cả!).

auth_none() hiếm khi được sử dụng nên không thể truy cập từ lớp SSHClient, vì vậy bạn cần sử dụng trực tiếp Transport.

transport.auth_none('root') 
+0

Đó là ... khó khăn. Cảm ơn. – waffleman

+0

Hi @ waffleman, tôi cũng gating cùng một vấn đề .. vì vậy tôi đặt transport.auth_none ('root') dòng trong mã nhưng bây giờ nhận được lỗi như .. NameError: name 'transport' không được định nghĩa –

+0

@Spike: Bạn đã khai báo chưa vận chuyển? transport = ssh.get_transport() – waffleman

0

paramiko's SSHClient có phương thức load_system_host_keys bạn có thể sử dụng để tải tập hợp khóa cụ thể của người dùng. Ví dụ trong tài liệu giải thích, nó cần phải được chạy trước khi kết nối với một máy chủ.

+0

Không may mắn. Tôi cũng đã thử xóa các known_hosts để xem nếu có bất kỳ tác dụng. – waffleman

+0

@waffleman: bạn đã thử phương thức 'load_host_keys' chưa? – SilentGhost

+0

Không hoạt động hoặc – waffleman

0

Tôi gặp lỗi tương tự khi máy chủ sử dụng xác thực AD. Tôi nghĩ đây là lỗi của paramiko. Tôi đã học được rằng tôi phải thiết lập các khóa ssh trước khi sử dụng paramiko.

2

Đảm bảo rằng quyền trên tệp khóa công cộng và khóa cá nhân (và có thể là thư mục chứa) được đặt thành rất hạn chế (ví dụ: chmod 600 id_rsa). Nó chỉ ra điều này là bắt buộc (bởi hệ điều hành?) Để sử dụng các tập tin như các khóa ssh. Tìm thấy điều này từ đồng nghiệp hữu ích của tôi :) Cũng đảm bảo rằng bạn đang sử dụng tên người dùng chính xác cho khóa ssh đã cho.

-3

Tôi đã cố gắng loại bỏ các thư mục ~./Ssh, sau đó nó làm việc tốt

+3

Bạn không nên xóa thư mục '.ssh' – dazedconfused

3

Là một rất muộn theo dõi về vấn đề này, tôi tin rằng tôi đã chạy vào cùng một vấn đề như waffleman, trong một bối cảnh một mạng hạn chế.

Gợi ý về việc sử dụng auth_none trên đối tượng Transport hóa ra khá hữu ích, nhưng tôi thấy mình hơi bối rối về cách triển khai điều đó. Thing, ít nhất là ngày hôm nay, tôi không thể lấy đối tượng Transport của một đối tượng SSHClient cho đến khi nó kết nối; nhưng nó sẽ không kết nối ở nơi đầu tiên ...

Vì vậy, trong trường hợp điều này hữu ích cho người khác, công việc của tôi xung quanh bên dưới. Tôi chỉ ghi đè lên phương pháp _auth.

OK, điều này là mong manh, vì _auth là một điều riêng tư. Các lựa chọn thay thế khác của tôi là - thực ra vẫn là - để tạo các đối tượng TransportChannel theo cách thủ công, nhưng trong thời gian này, tôi cảm thấy mình khá hơn với tất cả những điều này vẫn còn ở dưới mui xe.

from paramiko import SSHClient 

class SSHClient_noauth(SSHClient): 

    def _auth(self, username, *args): 
     self._transport.auth_none(username) 
     return