int128 / gradle-ssh-plugin

Gradle SSH Plugin
https://gradle-ssh-plugin.github.io
Apache License 2.0
319 stars 60 forks source link

com.jcraft.jsch.JSchException: invalid privatekey: [B@71d6843d error #361

Open ghost opened 4 years ago

ghost commented 4 years ago

Environment info

gradle-ssh-plugin-2.10.1 (groovy-ssh-2.10.1, jsch-0.1.54, groovy-2.5.8, java-1.8.0_72)

Steps to reproduce

run >>./gradlew copyJena

build.gradle.txt

Configure project : gradle-ssh-plugin-2.10.1 (groovy-ssh-2.10.1, jsch-0.1.54, groovy-2.5.8, java-1.8.0_72)

Task :copyJena FAILED gradle-ssh-plugin-2.10.1 (groovy-ssh-2.10.1, jsch-0.1.54, groovy-2.5.8, java-1.8.0_72)

FAILURE: Build failed with an exception.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s

xpusostomos commented 4 years ago

This is a problem in jsch. I don't know if this is fixed in jsch 0.1.55, I suspect not, but I really wish someone would fix it!

Recent versions of OpenSSH (7.8 and newer) generate keys in new OpenSSH format by default, which start with:

-----BEGIN OPENSSH PRIVATE KEY----- JSch does not support this key format.

You can use ssh-keygen to convert the key to the classic OpenSSH format:

ssh-keygen -p -f file -m pem -P passphrase -N passphrase (if the key is not encrypted with a passphrase, use "" instead of passphrase)

For Windows users: Note that ssh-keygen.exe is now built-in in Windows 10. And can be downloaded from Microsoft Win32-OpenSSH project for older versions of Windows.

On Windows, you can also use PuTTYgen (from PuTTY package):

Start PuTTYgen Load the key Go to Conversions > Export OpenSSH key. For RSA keys, it will use the classic format. If you are creating a new key with ssh-keygen, just add -m PEM to generate the new key in the classic format:

ssh-keygen -m PEM

geoff-sheldon commented 3 years ago

@xpusostomos I gave this a shot, and it did not resolve the issue - the private and public keys are changed, but the plugin is still throwing the same JSchException: invalid privatekey. Have I perhaps missed something else?

xpusostomos commented 3 years ago

@xpusostomos I gave this a shot, and it did not resolve the issue - the private and public keys are changed, but the plugin is still throwing the same JSchException: invalid privatekey. Have I perhaps missed something else?

What does the first line of your key start with? Is it "BEGIN OPENSSH" or other? Have you checked that SSH.exe works with the key?

geoff-sheldon commented 3 years ago

It starts with ----- BEGIN RSA PRIVATE KEY -----. Using SSH from the command line, as I normally would, works with the key. I did some looking into it, and it was suggested to remove any other keys and known hosts that might use OpenSSH-style, so I moved my known_hosts and my ed25519 keys to another directory and tried again, and still nothing.

I ended up having to use passwords to authenticate, populated with project.findProperty() so that the password itself wasn't added in the repo; however, if there's a way to get ssh key auth working I'd really prefer it.

xpusostomos commented 3 years ago

Well whatever the problem is, it's something to do with jsch so you might want to investigate from that angle, maybe even writing your own jsch test program. I noticed I have this in my gradle file, so this might be worth trying also.

remotes {
    gishost {
        user = System.getProperty('user.name')
        identity = file("${System.getProperty('user.home')}/.ssh/id_rsa")
    }
}
elijahfhopp commented 1 year ago

This may be resolved by #379/#381 since the Jsch version has been switched to an updated fork (https://github.com/mwiede/jsch). You would need to test it out, or check the fork.

baubakg commented 4 months ago

FYI it works for me. Thanks

elijahfhopp commented 4 months ago

We have been using the new version in production for about a year without issues, FWIW.