Search code examples
javasshapache-kafkaapache-flink

Does Java make use of SSH config file?


I am currently trying to access an Apache Kafka broker using Flink. Within my code, I configured the host IP to be 10.0.x.x which is an EC2 instance within a private subnet and can only be accessed through a bastion host. There is a working setup in ~/.ssh/config which tunnels all my SSH requests through the bastion, so I can access the machine by directly addressing the local IP. However, I am not sure, whether Eclipse or Java makes use of that, nor am I even sure who exactly would be responsible for that, the JVM or my IDE.

Do I have to go an extra mile and configure an explicit SSH tunnel in my Java application, e.g. with JSch, or should this already work and I messed something completely else up?


Solution

  • Java can't see your existing tunnel. For example in IntelliJ you can open an SSH Tunnel, but this is only temporary.

    You have to create a connection to localhost. In Java you are able to load config files into your program, which is fairly easy to do. Depending on your use-case you can use JSch for that.

    Before you start you should use the search on this site. There are some very different methods and libraries you can chose from. Maybe this helps : SSH connection using Java or this SSH connection with Java

    You should consider which one suits best for you.

    EDIT: What Marged said basically answers your question.