Ant scp任务:JSchException:无效的私钥 [英] Ant scp task: JSchException: invalid privatekey

查看:215
本文介绍了Ant scp任务:JSchException:无效的私钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ssh-keygen创建了一个新的密钥对,并在服务器上添加了公共密钥.使用sftp -i private_key_file user@server,我可以成功打开与服务器的连接并放入文件. 但是,当我尝试使用Ant scp任务时,会收到:

I created a new key pair using ssh-keygen and added the public key on the server. Using sftp -i private_key_file user@server I can successfully open a connection to the server and put files. However, when I try to use the Ant scp task I receive:

com.jcraft.jsch.JSchException: invalid privatekey: [B@5e9d5728

Ant脚本的相关部分:

The relevant part of the Ant script:

<scp file="local-file.zip"
             trust="true"
             sftp="true"
             todir="user@server:/dir/to/put/files"
             keyfile="private_key_file"
             verbose="true"/>

有人有主意吗?

推荐答案

看起来像最近的OpenSSH版本(我的F29中安装了7.9)ssh-keygen生成的密钥格式略有不同 现在开始于:

Looks like in recent OpenSSH versions (I have 7.9 installed in my F29) ssh-keygen generates a slightly different key format which starts now with:

-----BEGIN OPENSSH PRIVATE KEY-----

代替:

-----BEGIN RSA PRIVATE KEY-----

我安装了1.50版的JSch,它不喜欢新格式. 在密钥生成过程中使用-m PEM选项解决了我的问题:

I have version 1.50 of JSch installed, which does not like the new format. Using -m PEM option during key generation solved my issue:

ssh-keygen -t rsa -m PEM

在此线程中找到解决方案:使用JGit和JSCH时无效的私钥. 感谢和感谢进入 Natan

Found the solution in this thread: Invalid privateKey when using JGit and JSCH. Thanks and credits go to Natan and Roman Vottner !

(不确定是否还有可用的新版本的JSch接受新的密钥格式.)

(Not sure if there also is a new version of JSch available that will accept the new key format.)

这篇关于Ant scp任务:JSchException:无效的私钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆