0

I have a server that hosts multiple domains:

  • server FQDN: server.provider.com
  • host 1 FQDN: example.com
  • host 2 FQDN: example.it
  • host 3 FQDN: example.es

I like to use FQDN to connect, I don’t want to use nicknames.

When I connect directly to server.provider.com a tunnel is made from my port 3315 to server's 3306 port.

I want this tunnel to be opened every time I SSH into one host (for example when I do ssh example.com)

Here is my actual SSH config:

Host server.provider.com
  LocalForward 3315 localhost:3306  
Host example.com
  User user1
Host example.it
  User user2
Host example.es
  User user3

I've tried this, but is not working:

Host server.provider.com
  LocalForward 3315 localhost:3306  
Host example.com
  HostName server.provider.com
  User user1
Host example.it
  HostName server.provider.com
  User user2
Host example.es
  HostName server.provider.com
  User user3
2

Simplest approach:

Host server.provider.com
  LocalForward 3315 localhost:3306

Host example.com
  User user1
  LocalForward 3315 localhost:3306

Host example.it
  User user2
  LocalForward 3315 localhost:3306

Host example.es
  User user3
  LocalForward 3315 localhost:3306

You can group multiple names:

Host server.provider.com example.com example.it example.es
  LocalForward 3315 localhost:3306

Host example.com
  User user1

Host example.it
  User user2

Host example.es
  User user3

And to make your 2nd example work, you can use the Match final feature (new in OpenSSH 8.0) which enables two-pass parsing of the config file:

Match final host server.provider.com
  LocalForward 3315 localhost:3306

Host example.com
  HostName server.provider.com
  User user1

Host example.it
  HostName server.provider.com
  User user2

Host example.es
  HostName server.provider.com
  User user3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.