diff --git a/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java b/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java index 8fe922e6c8..0728c75106 100644 --- a/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java +++ b/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java @@ -2626,6 +2626,15 @@ public File getSSHExecutable() { return sshexe; } + // Check for ssh.exe on the system PATH (supports Microsoft OpenSSH and other alternate implementations) + String sshPath = getPathToExe("ssh"); + if (sshPath != null) { + sshexe = new File(sshPath); + if (sshexe.exists()) { + return sshexe; + } + } + // Check Program Files sshexe = getFileFromEnv("ProgramFiles", "\\Git\\bin\\ssh.exe"); if (sshexe != null && sshexe.exists()) { @@ -2701,7 +2710,8 @@ Path createWindowsGitSSH(Path key, String user, Path knownHosts) throws IOExcept w.write("setlocal enabledelayedexpansion"); w.newLine(); w.write("\"" + sshexe.getAbsolutePath() - + "\" -i \"!JENKINS_GIT_SSH_KEYFILE!\" -l \"!JENKINS_GIT_SSH_USERNAME!\" " + + "\" -n -T -i \"!JENKINS_GIT_SSH_KEYFILE!\" -l \"!JENKINS_GIT_SSH_USERNAME!\" " + + "-o BatchMode=yes -o PasswordAuthentication=no " + getHostKeyFactory().forCliGit(listener).getVerifyHostKeyOption(knownHosts) + " %* "); w.newLine(); } @@ -2724,7 +2734,8 @@ Path createUnixGitSSH(Path key, String user, Path knownHosts) throws IOException w.newLine(); w.write("fi"); w.newLine(); - w.write("ssh -i \"$JENKINS_GIT_SSH_KEYFILE\" -l \"$JENKINS_GIT_SSH_USERNAME\" " + w.write("ssh -n -T -i \"$JENKINS_GIT_SSH_KEYFILE\" -l \"$JENKINS_GIT_SSH_USERNAME\" " + + "-o BatchMode=yes -o PasswordAuthentication=no " + getHostKeyFactory().forCliGit(listener).getVerifyHostKeyOption(knownHosts) + " \"$@\""); w.newLine(); }