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