简体   繁体   English

Net :: SFTP perl rsa authentification

[英]Net::SFTP perl rsa authentification

I've been trying to sftp with the package Net::SFTP and an RSA key. 我一直在尝试使用Net :: SFTP和RSA密钥进行sftp。 I can manually sftp without password to my sftp server but when using the package it doesn't work. 我可以手动sftp没有密码到我的sftp服务器,但使用该包它不起作用。 I'm running out of idea. 我已经没想完了。

my $ftp = Net::SFTP->new($HOST, user => $USER, ssh_args => { identity_files => [ "/Users/user/.ssh/id_rsa" ] }, debug => 3 );

It gives me the following error: 它给了我以下错误:

Trying pubkey authentication with key file '/Users/tom/.ssh/id_rsa' 尝试使用密钥文件'/Users/tom/.ssh/id_rsa'进行pubkey身份验证

FATAL: rsa import failed: Invalid input packet. 致命:rsa导入失败:输入数据包无效。 at /Library/Perl/5.18//Crypt/PK/RSA.pm line 123. 在/Library/Perl/5.18//Crypt/PK/RSA.pm第123行。

Any help would be much appreciated, Thanks! 任何帮助将不胜感激,谢谢!

I just ran into this myself. 我自己就碰到了这个。

The problem is that my (and your) private keys are encrypted, as you noted in your comment. 问题是我的(和您的)私钥是加密的,正如您在评论中指出的那样。 An encrypted private key requires you to enter the password before it can be used, and it seems the perl module doesn't support this. 加密的私钥要求您在使用之前输入密码,而perl模块似乎不支持此密码。

You claimed that you didn't need a password when using this key, but perhaps that was because sftp was using your ssh agent? 您声称使用此密钥时不需要密码,但也许这是因为sftp正在使用您的ssh代理? ie where you enter the password once and then the key remains in memory for use by all ssh-family of tools? 即,您输入密码一次,然后密钥保留在内存中供所有ssh系列工具使用? It would appear that the perl module doesn't support the agent, either, but @salva's suggestion to use Net::SFTP::Foreign should solve that. 似乎perl模块也不支持代理,但是@ salva建议使用Net :: SFTP :: Foreign应该解决这个问题。

It's worth noting that I got this exception while running code that used to work just fine on my workstation, but on a new install of perl. 值得注意的是,我在运行过去在我的工作站上运行良好的代码时遇到了这个异常,但是在新安装的perl上运行。 I think what happened is that the Net::SSH::Perl module added support for reading private keys or changed the failure to read a private key into a fatal error rather than just ignoring the key. 我认为发生的事情是Net :: SSH :: Perl模块添加了对读取私钥的支持,或者将读取私钥的失败更改为致命错误而不是忽略密钥。 My code wasn't using a key anyway, but now won't work with that encrypted key around. 我的代码无论如何都没有使用密钥,但现在无法使用该密钥。 This is fixed with: 这是固定的:

my $sftp= Net::SFTP->new(
   ...
   ssh_args => [ identity_files => [] ]
);

and of course you could add a list of specific (unencrypted) identity files that you want it to use rather than the default user's RSA id. 当然,您可以添加要使用的特定(未加密)身份文件列表,而不是默认用户的RSA ID。

If the code isn't easily edited, you could also avoid the problem by setting the environment variable $HOME to something that doesn't have a key in it. 如果代码不易编辑,您还可以通过将环境变量$HOME设置为没有密钥的内容来避免此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM