Testing jsch on gitlab results in invalid privatekey error

Darlyn

I am trying to configure gitlab to run tests upon commiting, howerver in my test i use SFTP ( JSch ) like this:

sftp = new JSch();
sftp.addIdentity(Paths.get(ClassLoader.getSystemResource("private.ppk").toURI()).toString());
//sftp.setKnownHosts("~/.ssh/known_hosts");

Session session = sftp.getSession("test", "localhost", port);
session.setConfig("StrictHostKeyChecking", "no");
session.setConfig("PreferredAuthentications", "publickey");
session.connect();

sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();

( port is random port that is free. )

this code, upon runnin in gitlab enviroment throws

com.jcraft.jsch.JSchException: invalid privatekey: [B@27e47833

Which i quite do not understand why, running this code locally works as it should. The private key which i load from resources also in my gitlab repo.

Why is this happening? Are there any extra steps i omited or why is Jsch on gitlab refusing private key that is valid when i run it locally?

Thanks for help!

VonC

As mentioned here:

  • Check the PPK file and ensure that there are no obvious signs of a malformation. IE. Truncations, encoding issues, etc.
    
  • Verify the line endings in the PPK file.
    If you are developing a project and maintaining your code through a source code versioning system it is possible that your code gets versioned by different collaborators using different O.S. and architectures.
    As each operating system handles text end of lines differently (in Linux and OSX is handled as 'LF', in Windows as CRLF), if the PPK file gets modified, the character used to determine EOL could also be modified, thus impacting the matching of the private key. In these cases, it would be important to define the EOL character to use in your source code versioning tool settings or to directly avoid tracking the PPK file modifications.

See the comments of "invalid private key when opening SSH tunnel with jsch":

At least in 0.1.53 (and I doubt this would be removed) it does read PPK (in addition to OpenSSL PEMs = non-newfmt OpenSSH and several others) but only with Windows-type EOL (CR LF).
Did you copy your PPK to the affected system by a method that can change EOLs such as pasting to an editor or FTP TYPE A?

That or use a PEM format instead of PPK.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

"Invalid privatekey" when using JSch

From Dev

"Invalid privatekey" when using JSch

From Dev

Spring MVC testing results in 415 error

From Dev

JSCH: No such file error

From Dev

JSCH: No such file error

From Dev

Declaration of inner struct in another struct results in error: invalid use of struct

From Dev

Unable to say "invalid entry" to my code, always results in error with int

From Dev

Testing the router for invalid routes

From Dev

When pushing an image in GitLab registry using jenkins, the error fails: Invalid repository name

From Dev

Git push results in "fatal: sha1 file '<stdout>' write error: Invalid argument" error

From Dev

Error in testing

From Dev

iOS IAP testing, login doesn't say sandbox, and invalid login error

From Dev

Gitlab and Gitlab CI CSRF error

From Dev

Gitlab and Gitlab CI CSRF error

From Dev

SFTP via JSch is throwing error 4: Failure

From Dev

Permission error when getting file for use with JSch

From Dev

Why does order of testing change testing results?

From Dev

NancyFx Testing returning invalid Json

From Dev

Using GPXPY to parse gpx file results in not well-formed invalid token error

From Dev

CudaAPIError: [1] Call to cuLaunchKernel results in CUDA_ERROR_INVALID_VALUE in Python

From Dev

Starting Tomcat in Eclipse results in an error like "source name, file name, label name is invalid"

From Dev

"tar ./files.tar -C $HOME" results in a "tar: invalid option -- ." error

From Dev

xargs command is running on local machine but results in an "invalid command" error when run on remote host

From Dev

CudaAPIError: [1] Call to cuLaunchKernel results in CUDA_ERROR_INVALID_VALUE in Python

From Dev

Spring Boot, Spring Security, MySQL - CustomUserDetailsService always results in the error "Invalid Username or Password"

From Dev

Creating a draft via gmail api results with invalid_grant error - proper scopes are provided

From Dev

"Get-WMIObject Win32_NetworkAdaptorConfiguration" results in ERROR: invalid class

From Dev

Clarification on Sitecore A/B Testing Results

From Dev

Testing multicast - not getting proper results

Related Related

  1. 1

    "Invalid privatekey" when using JSch

  2. 2

    "Invalid privatekey" when using JSch

  3. 3

    Spring MVC testing results in 415 error

  4. 4

    JSCH: No such file error

  5. 5

    JSCH: No such file error

  6. 6

    Declaration of inner struct in another struct results in error: invalid use of struct

  7. 7

    Unable to say "invalid entry" to my code, always results in error with int

  8. 8

    Testing the router for invalid routes

  9. 9

    When pushing an image in GitLab registry using jenkins, the error fails: Invalid repository name

  10. 10

    Git push results in "fatal: sha1 file '<stdout>' write error: Invalid argument" error

  11. 11

    Error in testing

  12. 12

    iOS IAP testing, login doesn't say sandbox, and invalid login error

  13. 13

    Gitlab and Gitlab CI CSRF error

  14. 14

    Gitlab and Gitlab CI CSRF error

  15. 15

    SFTP via JSch is throwing error 4: Failure

  16. 16

    Permission error when getting file for use with JSch

  17. 17

    Why does order of testing change testing results?

  18. 18

    NancyFx Testing returning invalid Json

  19. 19

    Using GPXPY to parse gpx file results in not well-formed invalid token error

  20. 20

    CudaAPIError: [1] Call to cuLaunchKernel results in CUDA_ERROR_INVALID_VALUE in Python

  21. 21

    Starting Tomcat in Eclipse results in an error like "source name, file name, label name is invalid"

  22. 22

    "tar ./files.tar -C $HOME" results in a "tar: invalid option -- ." error

  23. 23

    xargs command is running on local machine but results in an "invalid command" error when run on remote host

  24. 24

    CudaAPIError: [1] Call to cuLaunchKernel results in CUDA_ERROR_INVALID_VALUE in Python

  25. 25

    Spring Boot, Spring Security, MySQL - CustomUserDetailsService always results in the error "Invalid Username or Password"

  26. 26

    Creating a draft via gmail api results with invalid_grant error - proper scopes are provided

  27. 27

    "Get-WMIObject Win32_NetworkAdaptorConfiguration" results in ERROR: invalid class

  28. 28

    Clarification on Sitecore A/B Testing Results

  29. 29

    Testing multicast - not getting proper results

HotTag

Archive