Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
maltalex opened this issue Jun 4, 2017 · 3 comments
Open

Comments

@maltalex
Copy link

maltalex commented Jun 4, 2017

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
Copy link

FlorianTim commented Dec 9, 2017

I use:

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

./gradlew run_pi_home -Pword=

@cawal
Copy link

cawal commented Jan 10, 2018

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
Copy link

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

System.console() is null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants