I had this ssh config:

Host git.domain.net
    Port 22

Host *.domain.net
    Port 2121

Host bastion
    HostName nx4201.domain.net
    User dummy

Host project_production
    HostName nx4242.domain.net
    User project

I was on Ubuntu 15.10 and doing ssh project_production was working, connecting on nx4242.domain.net with port 2121.

I'm now on a fresh install of Ubuntu 16.04 and I reimported the same config file (it's versionning under a private git repository).

This is not working anymore:

$ ssh -vvv project_production 
OpenSSH_7.2p2 Ubuntu-4ubuntu1, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /home/sullivan/.ssh/config
debug1: /home/sullivan/.ssh/config line 12: Applying options for project_production
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "nx4242.domain.net" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to nx4242.domain.net [] port 22.

As you can see, ssh now tries to connect with port 22 and doesn't care about the *.domain.net rule.

I know I can specify the port on each host but I have a lot of them.

Why is this not working now but working on the old system? How to fix it?

FYI, here is the system ssh config file:

Host *
#   ForwardAgent no
#   ForwardX11 no
#   ForwardX11Trusted yes
#   RhostsRSAAuthentication no
#   RSAAuthentication yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/identity
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Port 22
#   Protocol 2
#   Cipher 3des
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials no

The SSH version:

$ ssh -V
OpenSSH_7.2p2 Ubuntu-4ubuntu1, OpenSSL 1.0.2g  1 Mar 2016
  • Incidentally, underscore characters are not legal in hostnames per RFC 952. That might be related to why you ran into trouble.
    – Wildcard
    May 7 '19 at 21:31

I finally found my answer here: https://superuser.com/a/1024928/650657

In a nutshell I have to add this line:

CanonicalizeHostname yes
Host *.mydomain.com
    User myusername

Host host1
    HostName host1.mydomain.com

With this, the config file will be re-parsed.

The strange thing is I didn't have to use the CanonicalizeHostname option before...


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.