-1

when I run kinit ganesh@abc.com it asks for the password when I run through the terminal. I am trying to build same as web application using java

Acceptance criteria:-

  1. password should pass through UI and we should able connect to the server. i.e password which we pass through UI should assign asa password.
Ganesh
  • 167
  • 1
  • 7
  • 21

2 Answers2

0

I would recommend you to use Jsch, you can find this library here

http://www.jcraft.com/jsch

And an example or ssh connection here

http://www.jcraft.com/jsch/examples/Shell.java.html

reos
  • 8,766
  • 6
  • 28
  • 34
0
  • If you're using OpenSSH ssh client, you can try implementing passing password via a companion program, specified via SSH_ASKPASS variable. Basically, you need SSH_ASKPASS to point to a binary ssh would run, and that binary must output the password on stdout.

    Check this answer: How to make ssh receive the password from stdin for more details and a concrete example.

    The downside is, you need an external binary - and you need to think about its security. For example, if the binary is a dynamically-generated shell script in /tmp - you need strict filesystem permissions so no one but your ssh child process can read or execute it. And if the binary itself is static and takes password from, for example, an environment variable, you must make sure that SSH won't accidentally pass this variable to remote host (e.g. via accidentally specified SendEnv).

  • You can use some Java SSH library (like suggested Jsch - there is a list here: SSH library for Java), if that fits your requirements. It should be the most flexible option - in terms of control you have over SSH client behavior, unless you want something Jsch doesn't support.

  • Also, I'd strongly suggest to consider not using passwords, but your server having a private key, and servers you connect to appending its public key to ~/.ssh/authorized_keys (unless you need password-based logins for exactly this purpose, of course). If that's a feasible scenario, you can avoid sharing any sensitive information entirely, significantly improving the security.

drdaeman
  • 11,159
  • 7
  • 59
  • 104