gradle-ssh-plugin icon indicating copy to clipboard operation
gradle-ssh-plugin copied to clipboard

Prompting the user for ssh password / keyfile password (passphrase)

Open maltalex opened this issue 7 years ago • 3 comments

Instead of defining a password/passphrase within the gradle script or an environment variable, is there a way of prompting for a password from the command line when initiating an ssh session with a specific machine? I'd like to avoid storing plain text files anywhere.

I tried reading from System.in in the ssh.run block, but that didn't work.

maltalex avatar Jun 04 '17 14:06 maltalex

I use:

task run_pi_home {
     doLast {
         ssh.run {
             session(remotes.pi_home) {
 		remotes.pi_home.password="$word"
            }
         }
     }
}

./gradlew run_pi_home -Pword=<MyPassword>

FlorianTim avatar Dec 09 '17 18:12 FlorianTim

A nice solution I've found is presented bellow. It asks the password during the build and masks the characters:

def pass = "";

remotes {
  webServer {
    host = 'localhost'
    port = 22
    user = 'user'
  }
}

task deploy {
  doLast {
    pass = new String(System.console().readPassword("\nPlease enter password: "))  
    remotes.webServer.password = pass
    ssh.run {
      session(remotes.webServer) {
            ....
      }
    }
  }
}

Thanks for https://www.timroes.de/2014/01/19/using-password-prompts-with-gradle-build-files/

cawal avatar Jan 10 '18 01:01 cawal

pass = new String(System.console().readPassword("\nPlease enter password: "))  
    remotes.webServer.password = pass

System.console() is null

javaone199 avatar Jan 04 '21 06:01 javaone199