I have a bunch of Linux machines behind 2 gateways. To connect to set one I do
ssh -o ProxyCommand="ssh gateway1 nc %h %p" machines_behind_1 ssh -o ProxyCommand="ssh gateway2 nc --proxy %h %p --proxy-type socks4" machines_behind_2
To simplify this process, I thought I would create a environment variable to hold the proxycommand and simply use that. So I did
export PGWA='-o ProxyCommand="ssh gateway1 nc %h %p"' export PGWB='-o ProxyCommand="ssh gateway2 nc --proxy %h %p --proxy-type socks4"'
Then, depending on the machine I want to connect, I would do
ssh $PGWA machine_behind_1 ssh $PGWB machine_behind_2
But I get this error -
/bin/bash: -c: line 0: unexpected EOF while looking for matching `"' /bin/bash: -c: line 1: syntax error: unexpected end of file
Any idea why?
I can't use any ssh_config tricks, because I don't know the hostnames ahead of time. I might create a new VM behind gateway1 , and I will need to use the first proxy command.
The only thing I can think of is create a new alias, a function or a shell script which basically does
ssh -o foo $@ and use that instead. But then, I need to remember to create an alias/shell script or function for scp as well, which too I use regularly. I would rather be able to do it automatically.
I kinda hoped I could do something like
ssh gw1-host and do some manipulation inside the config file to convert it to
ssh -o foo host through the first gateway, but that kind of regex manipulation is not allowed inside the ssh_config.
Any way I can achieve what I want without individual ssh / scp alias/script/function?
EDIT: I had made a mistake with the quoting when I copy-pasted the environment variable into stack exchange here.