AEM JSCH auth faill issue | Community
Skip to main content
Level 2
August 11, 2025
Solved

AEM JSCH auth faill issue

  • August 11, 2025
  • 4 replies
  • 602 views

I am facing a issue with JSCH working fine outside the AEM. But failing inside AEM.

JSch jsch = new JSch();

// Add the private key identity
jsch.addIdentity(privateKeyPath);

// Get a session
session = jsch.getSession(username, host, port);

// Configure session properties
Properties config = new Properties();
// Important: For testing, you might set StrictHostKeyChecking to "no"
// In production, it's recommended to handle known_hosts properly.
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);

// Connect to the session
session.connect();
System.out.println("Session connected.");

This works perfectly when I run it directly with main method ( outside osgi). But gives the below error when code is ran inside AEM.

com.jcraft.jsch.JSchException: Auth fail
    at com.jcraft.jsch.Session.connect(Session.java:519)
    at com.jcraft.jsch.Session.connect(Session.java:183)

I ran the code with java 11 and AEM is also running on java 11. The code inside AEM is also able to access the private key content. ( I checked with log)

I am using the new library https://github.com/mwiede/jsch 

Best answer by sharathn8223803

Thanks all. The issue was it was still wired to old bundle although i updated the dependence. I had to explicitly add a import package for the jsch with new version. Which resolved the issue. 

4 replies

giuseppebaglio
Level 10
August 11, 2025

I recommend creating a dedicated logger for the package com.jcraft.jsch and setting it to trace or debug level. This approach may provide additional information about the reason for the failure.

narendragandhi
Community Advisor
Community Advisor
August 11, 2025

Hello @sharathn8223803 

 

You can refer the implementation here - https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/adobe/acs/commons/mcp/impl/processes/asset/FileAssetIngestor.java to compare any additional configurations required. Along with adding loggers for the specific package loggers as suggested by @giuseppebaglio 

 

Thanks

Narendra

Tanneru
Level 2
August 11, 2025

 

Is the private key in the correct format?

  • JSch does not support the new OpenSSH key format.

If your key starts with:

 

-----BEGIN OPENSSH PRIVATE KEY-----You need to convert it:
ssh-keygen -p -m PEM -f ~/.ssh/id_rsThis will create a format JSch can read.
sharathn8223803AuthorAccepted solution
Level 2
August 12, 2025

Thanks all. The issue was it was still wired to old bundle although i updated the dependence. I had to explicitly add a import package for the jsch with new version. Which resolved the issue.