2012-06-20 47 views
1

當我手動運行此Perl腳本時,它可以建立連接。但是當我執行到系統中時,它顯示了這個:authenticity of the target host can't be established, the remote host public key is probably not present on the '~/.ssh/known_hosts' filePerl遠程寫入文件連接錯誤消息Net :: SFTP :: Foreign

我需要幫助和建議。

my $host = "xxxs.com"; 
my $sftp = Net::SFTP::Foreign->new($host,user => 'xxx', password => 'xxx', 
            more => '-v',stderr_fh => $ssherr); 
+0

如果你可以把其餘的代碼,它可能會幫助更多。 你是什麼意思「實施到系統」? – spydadome

回答

2

看看Net :: SFTP :: Foreign doc中的FAQ。它在下提交主機密鑰檢查並且是最後一個條目。這是一個摘錄。

Host key checking

Q: Connecting to a remote server with password authentication fails with the following error:

The authenticity of the target host can not be established, 
connect from the command line first 

A: That probably means that the public key from the remote server is not stored in the ~/.ssh/known_hosts file . Run an SSH Connection from the command line as the same user as the script and answer yes when asked to confirm the key supplied.

這裏也有一個例子。

0

解決方案對我來說是:

my $ftp = Net::SFTP::Foreign->new($HOST, 
            user => $USERNAME, 
            password => $PASSWORD, 
            more => [-o => 'StrictHostKeyChecking no']); 

凡StrictHostKeyChecking的伎倆。

ref:https://www.freebsd.org/cgi/man.cgi?query=Net::SFTP::Foreign

+0

不要禁用嚴格的主機密鑰檢查,除非你知道你在做什麼!引用[模塊文檔](https://metacpan.org/pod/Net::SFTP::Foreign#Host-key-checking):「您的SSH客戶端也可能支持某些標誌來禁用此檢查(嚴格的主機密鑰) ,但這樣做可能會破壞SSH協議的安全性,因此我建議不要使用它「 – salva

相關問題