You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: config-ssh writes bad Match exec clause on Windows #18199
# ------------START-CODER-----------
# This section is managed by coder. DO NOT EDIT.
#
# You should not hand-edit this section unless you are removing it, all
# changes will be lost when running "coder config-ssh".
#
Host coder.*
ConnectTimeout=0
StrictHostKeyChecking=no
UserKnownHostsFile=/dev/null
LogLevel ERROR
ProxyCommand "C:\Program Files\Coder\bin\coder.exe" --global-config C:\Users\micha\AppData\Roaming\coderv2 ssh --stdio --ssh-host-prefix coder. %h
Host *.coder
ConnectTimeout=0
StrictHostKeyChecking=no
UserKnownHostsFile=/dev/null
LogLevel ERROR
Match host *.coder !exec ""C:\Program Files\Coder\bin\coder.exe" connect exists %h"
ProxyCommand "C:\Program Files\Coder\bin\coder.exe" --global-config C:\Users\micha\AppData\Roaming\coderv2 ssh --stdio --hostname-suffix coder %h
# ------------END-CODER------------
This results in a failed ssh invocation
C:\Users\micha\Downloads> ssh net-integration.coder
Missing Match criteria for exec
C:\\Users\\micha/.ssh/config line 66: Bad Match condition
C:\\Users\\micha/.ssh/config: terminating, 1 bad configuration options
Relevant Log Output
Expected Behavior
ssh should connect
Steps to Reproduce
Install Coder on Windows to a path with a space in it like C:\Program Files\Coder\
The news is pretty bad. OpenSSH parses the Match line with a very simple tokenizer that accepts "-enclosed strings for the exec command, and has no supported escape sequences for ". This means we cannot include " within the command to execute.
To make matters worse, on Windows, OpenSSH passes the string directly to cmd.exe for execution, and as far as I can tell, the only supported way to call a path that has spaces in it is to surround it with ".
We can't actually include " directly, but here is a horrible workaround:
Match host *.coder !exec "for /f %%a in ('powershell.exe -Command [char]34') do @cmd.exe /c %%aC:\Program Files\Coder\bin\coder.exe%%a connect exists %h"
ProxyCommand "C:\Program Files\Coder\bin\coder.exe" --global-config C:\Users\micha\AppData\Roaming\coderv2 ssh --stdio --hostname-suffix coder %h
The key insight here is to store the character " in a variable (%a in this case, but the % itself needs to be escaped, so it becomes %%a), and then use that variable to construct the double-quoted path: %%aC:\Program Files\Coder\bin\coder.exe%%a connect exists %h. How do we generate a single " character without actually using that character? I couldn't find any command in cmd.exe to do it, but powershell.exe can convert ASCII to characters like this: [char]34 (where 34 is the code point for ").
Activity
spikecurtis commentedon Jun 5, 2025
The news is pretty bad. OpenSSH parses the
Matchline with a very simple tokenizer that accepts"-enclosed strings for theexeccommand, and has no supported escape sequences for". This means we cannot include"within the command to execute.To make matters worse, on Windows, OpenSSH passes the string directly to
cmd.exefor execution, and as far as I can tell, the only supported way to call a path that has spaces in it is to surround it with".We can't actually include
"directly, but here is a horrible workaround:The key insight here is to store the character
"in a variable (%ain this case, but the%itself needs to be escaped, so it becomes%%a), and then use that variable to construct the double-quoted path:%%aC:\Program Files\Coder\bin\coder.exe%%a connect exists %h. How do we generate a single"character without actually using that character? I couldn't find any command incmd.exeto do it, butpowershell.execan convert ASCII to characters like this:[char]34(where 34 is the code point for").fix: handle paths with spaces in Match exec clause of SSH config (#18266
fix: handle paths with spaces in Match exec clause of SSH config (#18266
fix: handle paths with spaces in Match exec clause of SSH config (che…