2011-10-24 63 views
6

我有一個sshj(使用sshj v0.6.0)的奇怪問題,因此我需要某個人的幫助。 使用公鑰進行身份驗證在一些機器上正常工作,但在其他機器上無法正常工作,我看到下面的錯誤。處理「[HOST_KEY_NOT_VERIFIABLE]無法驗證具有指紋的ssh-rsa主機密鑰」sshj

,我可以讓出唯一的區別是,UNIX ID的問題即coonradt似乎有下的〜/ .ssh/config中的下列配置設置只在其上下方的錯誤被觸發

Host * 
    Protocol 1,2 
    FallBackToRsh no 
    ForwardAgent yes 
    ForwardX11 yes 
    PasswordAuthentication yes 
    RhostsAuthentication no 
    RhostsRSAAuthentication no 
    RSAAuthentication yes 
    NoHostAuthenticationForLocalhost yes 
    StrictHostKeyChecking no 
    KeepAlive yes 

從上面的配置文件中,我瞭解到有問題的ID應該使用協議1,2,我懷疑這可能與我的失敗有關(我對此不太確定,但這只是一個預感)

對於這個工作正常的所有其他UNIX ID,我沒有任何這樣的配置文件。

PS:我無法更改UNIX ID「coonradt」的配置,因爲中央哈德森服務器正在使用此ID。

將不勝感激,如果有人可以幫我建議,什麼可能是錯在這裏

下面是我看到的錯誤:

Oct 24, 2011 2:30:37 AM net.schmizz.sshj.DefaultConfig initCipherFactories 
WARNING: Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy 
Oct 24, 2011 2:30:38 AM net.schmizz.sshj.transport.TransportImpl init 
INFO: Client identity string: SSH-2.0-SSHJ_0_6_0 
Oct 24, 2011 2:30:38 AM net.schmizz.sshj.transport.TransportImpl init 
INFO: Server identity string: SSH-1.99-OpenSSH_4.3 
Oct 24, 2011 2:30:38 AM net.schmizz.sshj.transport.KeyExchanger sendKexInit 
INFO: Sending SSH_MSG_KEXINIT 
Oct 24, 2011 2:30:38 AM net.schmizz.sshj.transport.KeyExchanger handle 
INFO: Received SSH_MSG_KEXINIT 
Oct 24, 2011 2:30:38 AM net.schmizz.sshj.transport.kex.AbstractDHG init 
INFO: Sending SSH_MSG_KEXDH_INIT 
Oct 24, 2011 2:30:38 AM net.schmizz.sshj.transport.KeyExchanger handle 
INFO: Received kex followup data 
Oct 24, 2011 2:30:38 AM net.schmizz.sshj.transport.kex.AbstractDHG next 
INFO: Received SSH_MSG_KEXDH_REPLY 
Oct 24, 2011 2:30:38 AM net.schmizz.sshj.transport.TransportImpl die 
SEVERE: Dying because - net.schmizz.sshj.transport.TransportException: [HOST_KEY_NOT_VERIFIABLE] Could not verify `ssh-rsa` host key with fingerprint `ca:0b:b3:7f:53:5a:e3:bc:bf:44:63:d8:2d:26:c0:41` for `mymachine.domain.com` on port 22 
Oct 24, 2011 2:30:38 AM net.schmizz.concurrent.Promise tryRetrieve 
SEVERE: <<kex done>> woke to: net.schmizz.sshj.transport.TransportException: [HOST_KEY_NOT_VERIFIABLE] Could not verify `ssh-rsa` host key with fingerprint `ca:0b:b3:7f:53:5a:e3:bc:bf:44:63:d8:2d:26:c0:41` for `mymachine.domain.com` on port 22 
Oct 24, 2011 2:30:38 AM net.schmizz.sshj.transport.TransportImpl setService 
INFO: Setting active service to null-service 
Oct 24, 2011 2:30:38 AM com.test.jaws.execution.ssh.impl.SSHJClientImpl$ExceptionHandler handleSevereCondition 
SEVERE: mymachine.domain.com is not added to your /x/home/coonradt/.ssh/known_hosts file. 
Throwable occurred: net.schmizz.sshj.transport.TransportException: [HOST_KEY_NOT_VERIFIABLE] Could not verify `ssh-rsa` host key with fingerprint `ca:0b:b3:7f:53:5a:e3:bc:bf:44:63:d8:2d:26:c0:41` for `mymachine.domain.com` on port 22 
    at net.schmizz.sshj.transport.KeyExchanger.verifyHost(KeyExchanger.java:222) 
    at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:373) 
    at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:477) 
    at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127) 
    at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195) 
    at net.schmizz.sshj.transport.Reader.run(Reader.java:72) 
+0

我認爲問題確實與coonradt用戶配置有關,請參閱嚴重通知:「嚴重:mymachine.domain.com未添加到您的/x/home/coonradt/.ssh/known_hosts文件中。 「你應該修復這個問題;-) –

+0

你好,非常感謝你的迅速回復,但是你能否建議你應該向用戶提供什麼修補程序?是否意味着我必須去掉協議我希望sshj能以某種方式讓我指定可以使用的協議版本(如果聽起來很亂,請耐心等待我的天真,但正如我在對內部知識不太瞭解之前所承認的那樣如何使用ssh) –

+0

它實際上與協議實際上很少有關(事實上,就此消息而言,沒有什麼關係)。需要發生的事情是文件'/ x/home/coonradt /。在這種情況下,ssh/known_hosts'應該包含客戶端的指紋。我想你已經偶然發現了一種安全措施,並非每臺計算機都可以使用該用戶連接到該服務器。 –

回答

12

如何添加HostKeyVerifier爲這臺機器?

sshClient.addHostKeyVerifier("ca:0b:b3:7f:53:5a:e3:bc:bf:44:63:d8:2d:26:c0:41"); 

它不會自動發生的原因可能是因爲known_hosts文件不在$(的user.home)/。SSH/known_hosts中。您還可以從特定位置顯式加載已知主機。

sshClient.loadKnownHosts(new File("path_to_known_hosts")); 
+0

@Shikar:我不認爲這個問題與known_host文件有任何關係。我發現sshj在我的有限知識中並沒有處理ssh v1協議。 –

+1

@Shikar:請看看https://gist.github.com/1321719,其中詳細說明了問題。 –

+0

@Shikar:我也忘了告訴你,known_hosts文件在〜/ .ssh文件夾下,我確認了它的可用性。 –

0

對於備選答案,請確保您嘗試連接的主機名與您的known_hosts文件中的主機名完全匹配。我是做一個例子的錯誤是試圖連接到的完整URL bob.insidenetwork.pvt但我known_hosts文件只有bob作爲入門,因爲當我ssh手動我太懶得輸入完整的網址...

7
try { 
    ssh.connect(envConf.getIp(), port); 
} catch (TransportException e) { 
    if (e.getDisconnectReason() == DisconnectReason.HOST_KEY_NOT_VERIFIABLE) { 
     String msg = e.getMessage(); 
     String[] split = msg.split("`"); 
     String vc = split[3]; 
     ssh = new SSHClient(); 
     ssh.addHostKeyVerifier(vc); 
     ssh.connect(envConf.getIp(), port); 
    } else { 
     throw e; 
    } 
} 
ssh.authPassword(envConf.getName(), envConf.getPw()); 
ssh.newSCPFileTransfer().download(envConf.getHomePath() + FilePath, toPath); 
8

你可以設置SSH客戶端接受所有的按鍵沒有任何驗證(忽略主機密鑰驗證)

SSHClient sshClient = new SSHClient(); 
sshClient.addHostKeyVerifier(new PromiscuousVerifier()); 
... 
-1

它爲我的作品:

try (final SSHClient sshClient = new SSHClient()) { 
    sshClient.addHostKeyVerifier(new PromiscuousVerifier()); 
    KeyProvider keys = sshClient.loadKeys("path_to_private_key.ppk"); 
    sshClient.connect("hostname"); 
    sshClient.authPublickey("username", keys); 
} catch (IOException e) { 
} 
+1

丟棄異常是一種不好的做法。 – Kenster

相關問題