Skip to content
Advertisement

Use public key fingerprint in Java Spring Boot application to solve “The authenticity of host ‘xxxx’ can’t be established”

I have a Java Spring Boot application which is using the spring-integration-sftp dependency to connect to an SFTP server. I get an error

The authenticity of host ‘xxxx’ can’t be established

and I know this can easily be rid of by setting the sftpSessionFactory.setAllowUnknownKeys(true), but that is not a good practice and I would rather not do that.

I have the below SFTP server’s public key fingerprint. How can I use that to safely connect to my SFTP server so that my host is known? What should I additionally set in the sftpSessionFactory?

JavaScript

Advertisement

Answer

Use DefaultSftpSessionFactory.setKnownHosts to provide a path to known_hosts-like file with the host key of the server.


The spring-integration-sftp uses JSch under the hood, so for more details, see:
How to resolve Java UnknownHostKey, while using JSch SFTP library?

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement