Ant scp task: JSchException: invalid privatekey [duplicate]

徘徊边缘 提交于 2020-01-03 07:03:05

问题


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

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"/>

Does anyone have an idea ?


回答1:


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-----

instead of:

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

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

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

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



来源:https://stackoverflow.com/questions/55167874/ant-scp-task-jschexception-invalid-privatekey

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!