int128 / gradle-ssh-plugin

Gradle SSH Plugin
https://gradle-ssh-plugin.github.io
Apache License 2.0
319 stars 60 forks source link

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

Open maltalex opened 7 years ago

maltalex commented 7 years ago

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.

FlorianTim commented 6 years ago

I use:

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

./gradlew run_pi_home -Pword=

cawal commented 6 years ago

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/

javaone199 commented 3 years ago
pass = new String(System.console().readPassword("\nPlease enter password: "))  
    remotes.webServer.password = pass

System.console() is null