0

I am trying to simplify the following part:

Host sandbox*
   Port 22
   User myUser
   ProxyCommand=nc -X 5 -x gateway.test.io:1080 %h %p

Host sandbox9 HostName 1.0.9.10

Host sandbox10 HostName 1.0.10.10

Host sandbox11 HostName 1.0.11.10

I read, that I can use %h in HostName, which would then look like that:

Host sandbox*
   Port 22
   User myUser
   ProxyCommand=nc -X 5 -x gateway.test.io:1080 %h %p
   HostName 1.0.%h.10

But then I get the following error when trying to use ssh:

❯ ssh sandbox9
nc: connection failed, SOCKS error 8
kex_exchange_identification: Connection closed by remote host
Connection closed by UNKNOWN port 65535

ChatGPT first told me that the first approach should work, but then tells me this:

The %h placeholder cannot be directly used in the HostName directive of the SSH configuration file to substitute a variable for the hostname. Using placeholders in this specific directive is not supported.

Am I doing something wrong?

Mr.Tr33
  • 101
  • 3
    Your command, ssh sandbox9, tries to connect to 1.0.sandbox9.10. – Kusalananda May 10 '23 at 14:44
  • @MarcusMüller I only asked ChatGTP because I found many different answers only, also in StackExchange, but nothing worked. – Mr.Tr33 May 10 '23 at 14:51
  • Reference: https://unix.meta.stackexchange.com/questions/6021/how-do-we-want-to-handle-ai-generated-answers/ and the very comparable discussions regarding questions based on ChatGPT statements over at StackOverflow, Electronics.SE, and several other sites. – Marcus Müller May 10 '23 at 14:51
  • 2
    then just ignore ChatGPT: As said, it just forms answer sentences that sound right. And agreeing with you sounds great! No matter how wrong you are. – Marcus Müller May 10 '23 at 14:52
  • the variables you can use are documented. There's an authorative source: when you read man ssh, you will be pointed at man ssh_config (or you directly go there, because you already know where to look), and it says exactly which placeholders you can use. Same for documentation of nc. man nc tells us that -x gateway.test.io:1080 tells nc to dump communication as hexdump to a file called "gateway.test.io:1080". Was that what you set out to do? – Marcus Müller May 10 '23 at 14:53
  • (NB: there's various different nc out there: the original linuxops one, the nmap one, and the GNU one; on most systems I encounter, you get the nmap netcat as default nc, and that's lead to trouble more than once, hence I'm mentioning it) – Marcus Müller May 10 '23 at 14:59

1 Answers1

-1

Possible that in your OpenSSH client version the %h placeholder is not intercepted as the original host, and replaced by %n placeholder.

Try the same configuration with %n placeholder:

Host sandbox*
   Port 22
   User myUser
   ProxyCommand=nc -X 5 -x gateway.test.io:1080 %n %p

You can determine your OpenSSH client version using ssh -V