我有一個rakefile.rb,它定義了一個使用net/scp和基本密碼認證將文件上傳到遠程服務器的任務,即使我檢查了一個「Net :: SSH :: AuthenticationFailed」異常主機,用戶,密碼和文件字符串。我啓用
LogLevel INFO
到
LogLevel DEBUG
然後看到下面的輸出在服務器的日誌(例如,/var/log/auth.log
),發現客戶端試圖使用公共密鑰認證因爲某些原因!
Nov 13 22:38:26 linux sshd[12514]: debug1: Forked child 12532.
Nov 13 22:38:26 linux sshd[12532]: Set /proc/self/oom_score_adj to 0
Nov 13 22:38:26 linux sshd[12532]: debug1: rexec start in 5 out 5 newsock 5 pipe 7 sock 8
Nov 13 22:38:26 linux sshd[12532]: debug1: inetd sockets after dupping: 3, 3
Nov 13 22:38:26 linux sshd[12532]: Connection from 192.168.112.1 port 38391
Nov 13 22:38:26 linux sshd[12532]: debug1: Client protocol version 2.0; client software version Ruby/Net::SSH_2.6.1 i386-mingw32
Nov 13 22:38:26 linux sshd[12532]: debug1: no match: Ruby/Net::SSH_2.6.1 i386-mingw32
Nov 13 22:38:26 linux sshd[12532]: debug1: Enabling compatibility mode for protocol 2.0
Nov 13 22:38:26 linux sshd[12532]: debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1
Nov 13 22:38:26 linux sshd[12532]: debug1: permanently_set_uid: 102/65534 [preauth]
Nov 13 22:38:26 linux sshd[12532]: debug1: list_hostkey_types: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256 [preauth]
Nov 13 22:38:26 linux sshd[12532]: debug1: SSH2_MSG_KEXINIT sent [preauth]
Nov 13 22:38:26 linux sshd[12532]: debug1: SSH2_MSG_KEXINIT received [preauth]
Nov 13 22:38:26 linux sshd[12532]: debug1: kex: client->server aes128-cbc hmac-sha1 none [preauth]
Nov 13 22:38:26 linux sshd[12532]: debug1: kex: server->client aes128-cbc hmac-sha1 none [preauth]
Nov 13 22:38:26 linux sshd[12532]: debug1: SSH2_MSG_KEX_DH_GEX_REQUEST received [preauth]
Nov 13 22:38:26 linux sshd[12532]: debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent [preauth]
Nov 13 22:38:26 linux sshd[12532]: debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT [preauth]
Nov 13 22:38:27 linux sshd[12532]: debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent [preauth]
Nov 13 22:38:27 linux sshd[12532]: debug1: SSH2_MSG_NEWKEYS sent [preauth]
Nov 13 22:38:27 linux sshd[12532]: debug1: expecting SSH2_MSG_NEWKEYS [preauth]
Nov 13 22:38:27 linux sshd[12532]: debug1: SSH2_MSG_NEWKEYS received [preauth]
Nov 13 22:38:27 linux sshd[12532]: debug1: KEX done [preauth]
Nov 13 22:38:27 linux sshd[12532]: debug1: userauth-request for user root service ssh-connection method publickey [preauth]
Nov 13 22:38:27 linux sshd[12532]: debug1: attempt 0 failures 0 [preauth]
(pause in time)
Nov 13 22:38:38 linux sshd[12532]: debug1: test whether pkalg/pkblob are acceptable [preauth]
Nov 13 22:38:38 linux sshd[12532]: debug1: PAM: initializing for "root"
Nov 13 22:38:38 linux sshd[12532]: debug1: PAM: setting PAM_RHOST to "np-complete.local"
Nov 13 22:38:38 linux sshd[12532]: debug1: PAM: setting PAM_TTY to "ssh"
Nov 13 22:38:38 linux sshd[12532]: debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
Nov 13 22:38:38 linux sshd[12532]: debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
Nov 13 22:38:38 linux sshd[12532]: debug1: temporarily_use_uid: 0/0 (e=0/0)
Nov 13 22:38:38 linux sshd[12532]: debug1: trying public key file /root/.ssh/authorized_keys
Nov 13 22:38:38 linux sshd[12532]: debug1: Could not open authorized keys '/root/.ssh/authorized_keys': No such file or directory
Nov 13 22:38:38 linux sshd[12532]: debug1: restore_uid: 0/0
Nov 13 22:38:38 linux sshd[12532]: debug1: temporarily_use_uid: 0/0 (e=0/0)
Nov 13 22:38:38 linux sshd[12532]: debug1: trying public key file /root/.ssh/authorized_keys2
Nov 13 22:38:38 linux sshd[12532]: debug1: Could not open authorized keys '/root/.ssh/authorized_keys2': No such file or directory
Nov 13 22:38:38 linux sshd[12532]: debug1: restore_uid: 0/0
Nov 13 22:38:38 linux sshd[12532]: Failed publickey for root from 192.168.112.1 port 38391 ssh2
Nov 13 22:38:38 linux sshd[12532]: Connection closed by 192.168.112.1 [preauth]
Nov 13 22:38:38 linux sshd[12532]: debug1: do_cleanup [preauth]
Nov 13 22:38:38 linux sshd[12532]: debug1: monitor_read_log: child log fd closed
Nov 13 22:38:38 linux sshd[12532]: debug1: do_cleanup
Nov 13 22:38:38 linux sshd[12532]: debug1: PAM: cleanup
所以看到發生了什麼事情我改變了我的代碼,包括:在SCP的選項SSH密鑰,指定我只支持密碼認證:
Net::SCP.upload!(:remote_server, :remote_user, local_file, remote_file,
{
:password => "(my password)",
:ssh => {:auth_methods => ["password"]}
}
)
,這導致在服務器上的以下信息:
Nov 13 23:00:36 linux sshd[12514]: debug1: Forked child 13376.
Nov 13 23:00:36 linux sshd[13376]: Set /proc/self/oom_score_adj to 0
Nov 13 23:00:36 linux sshd[13376]: debug1: rexec start in 5 out 5 newsock 5 pipe 7 sock 8
Nov 13 23:00:36 linux sshd[13376]: debug1: inetd sockets after dupping: 3, 3
Nov 13 23:00:36 linux sshd[13376]: Connection from 192.168.112.1 port 38631
Nov 13 23:00:36 linux sshd[13376]: debug1: Client protocol version 2.0; client software version Ruby/Net::SSH_2.6.1 i386-mingw32
Nov 13 23:00:36 linux sshd[13376]: debug1: no match: Ruby/Net::SSH_2.6.1 i386-mingw32
Nov 13 23:00:36 linux sshd[13376]: debug1: Enabling compatibility mode for protocol 2.0
Nov 13 23:00:36 linux sshd[13376]: debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1
Nov 13 23:00:36 linux sshd[13376]: debug1: permanently_set_uid: 102/65534 [preauth]
Nov 13 23:00:36 linux sshd[13376]: debug1: list_hostkey_types: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256 [preauth]
Nov 13 23:00:36 linux sshd[13376]: debug1: SSH2_MSG_KEXINIT sent [preauth]
Nov 13 23:00:36 linux sshd[13376]: debug1: SSH2_MSG_KEXINIT received [preauth]
Nov 13 23:00:36 linux sshd[13376]: debug1: kex: client->server aes128-cbc hmac-sha1 none [preauth]
Nov 13 23:00:36 linux sshd[13376]: debug1: kex: server->client aes128-cbc hmac-sha1 none [preauth]
Nov 13 23:00:36 linux sshd[13376]: debug1: SSH2_MSG_KEX_DH_GEX_REQUEST received [preauth]
Nov 13 23:00:36 linux sshd[13376]: debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent [preauth]
Nov 13 23:00:36 linux sshd[13376]: debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT [preauth]
Nov 13 23:00:37 linux sshd[13376]: debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent [preauth]
Nov 13 23:00:37 linux sshd[13376]: debug1: SSH2_MSG_NEWKEYS sent [preauth]
Nov 13 23:00:37 linux sshd[13376]: debug1: expecting SSH2_MSG_NEWKEYS [preauth]
Nov 13 23:00:37 linux sshd[13376]: debug1: SSH2_MSG_NEWKEYS received [preauth]
Nov 13 23:00:37 linux sshd[13376]: debug1: KEX done [preauth]
Nov 13 23:00:37 linux sshd[13376]: Connection closed by 192.168.112.1 [preauth]
Nov 13 23:00:37 linux sshd[13376]: debug1: do_cleanup [preauth]
Nov 13 23:00:37 linux sshd[13376]: debug1: monitor_read_log: child log fd closed
Nov 13 23:00:37 linux sshd[13376]: debug1: do_cleanup
顯然他們未能就如何做認證同意....希望這是人們通過它來幫助。如果/當我發現爲什麼會發生這種情況時,我會更新它。
來源
2012-11-13 23:01:14
iX3
我知道這是舊的和回答,但我得到這個錯誤,當我試圖下載與Net :: SCP。對我來說問題是遠程SSH主機沒有安裝'openssh-clients'。 – ZombieDev 2014-04-03 16:12:57