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

查看:38
本文介绍了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 时私钥无效.感谢和感谢 NatanRoman Vottner

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天全站免登陆