I want to SSH in VS Code from my local machine, A, through a proxy, B, to a destination host, C. And I have find there is a great discussion in . SSH from A through B to C, using private key on B [closed]. I followed what the best answer said, add some line in ~/.ssh/config:
Host C
ProxyCommand ssh -o 'ForwardAgent yes' B 'ssh-add && nc %h %p'
but it doesn't work, and raise a error Bad configuration option: 'forwardagent
.
I find there is only one single quote and guess maybe it's something wrong with quote, then I change all single quote to double quote, say:
Host C
ProxyCommand ssh -o "ForwardAgent yes" B "ssh-add && nc %h %p"
and it just worked.
I don't know why and very curious about this phenomenon.
I tried with several shells to test single/double quotes: double quoting is ok in each shell, but single quoting only worked on PowerShell but not work on cmd.
I have searched in google about the difference between single quote and double quote, and get about that they are different when treat text behind symbol "$". But still have no explanation for my question.
I really want to know why this little change makes my config work and why other people can also be good with the code mention in that discussion with single quote.
OpenSSH only documents double-quotes (and not single-quotes) as being valid string quote characters. See the OpenBSD OpenSSH config man page: https://man.openbsd.org/ssh_config.5.
For cross-referencing purposes (although not really necessary when you have the official man page), see also ssh.com's page on the config file format in the section titled "Format of SSH client config file ssh_config", and this other web page that ranks highly in google search: https://phoenixnap.com/kb/ssh-config#ftoc-heading-4.
As you found in your experimenting from my prompting, single-quotes for you when you run from PowerShell, but not from cmd.exe. So it's probably a shell thing, with OpenSSH not treating single-quotes with any special meaning and passing them to the shell directly (or something like that). PowerShell accepts both single-quotes or double-quotes for quoting string arguments (docs), but cmd.exe only uses double-quotes for string arguments (related GNU docs) and uses single-quotes only for enclosing a command to run within a FOR /F
statement (related Q&A). See also this loosely related superuser.com Q&A: How to make Windows command prompt treat single quote as though it is a double quote?.