From 060bfd40c72f70d68a07846c94efe1051a41b093 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Mon, 15 Dec 2025 21:10:08 -0700 Subject: [PATCH] Use system temporary directory for known_hosts file Windows ssh.exe 9.5p1 and ssh.exe 9.5p2 will not read the known_hosts file if there is a space character in the path to the file. Since we already use the system temporary directory for other scripts that do not contain sensitive information, we'll use it for the known_hosts file as well. The contents of the known_hosts file is not sensitive information. Testing done: * Confirmed that without this change, Windows ssh.exe does not read the known_hosts file when using a manually verified known_hosts file from a workspace that has spaces in its absolute path. * Confirmed that with this change, Windows ssh.exe reads the known_hosts file when using a manually verified known_hosts file from a workspace that has spaces in its absolute path. Fixes #1703 --- .../java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java b/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java index fc0a850a82..c7cb7dd677 100644 --- a/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java +++ b/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java @@ -2130,7 +2130,10 @@ private String launchCommandWithCredentials( userName = sshUser.getUsername(); } passphrase = createPassphraseFile(sshUser); - knownHostsTemp = createTempFile("known_hosts", ""); + /* ssh.exe 9.5 on Windows does not accept spaces in path to known_hosts. + * Use temp file wrapper location because known_hosts is not sensitive info. + */ + knownHostsTemp = createTempFileForWrapper("known_hosts", ""); if (launcher.isUnix()) { ssh = createUnixGitSSH(key, userName, knownHostsTemp); askpass = createUnixSshAskpass(sshUser, passphrase);