6

I have a bunch of machines under one domain that I frequently connect to; apollo.my.university.edu hades.my.university.edu zeus.my.university.edu and I use the same configuration settings for each of them. Instead of typing them all out in my .ssh/config,

Host apollo
    Hostname apollo.my.university.edu

Host hades
    Hostname hades.my.university.edu

Host zeus
    Hostname zeus.my.university.edu

is there a makefile-esque way to use the alias to complete the hostname for all of them simultaneously? Something like

Host apollo hades zeus
    Hostname *.my.university.edu
1
  • Off-topic here, but I really would love to know if this is possible.
    – ceejayoz
    May 28, 2013 at 18:17

2 Answers 2

9

Try

Host apollo hades zeus
    Hostname %h.my.university.edu

If I am reading man ssh_config correctly, this should do what you want.

HostName
         Specifies the real host name to log into.  This can be used to specify nicknames
         or abbreviations for hosts.  If the hostname contains the character sequence
         `%h', then this will be replaced with the host name specified on the command
         line (this is useful for manipulating unqualified names).  The default is the
         name given on the command line.  Numeric IP addresses are also permitted (both
         on the command line and in HostName specifications).
1
  • 1
    Off topic, but you can find a lot of nice config tricks here
    – demure
    May 28, 2013 at 19:31
3

Besides using ssh_config as shown by demure, you can also make DNS lookups consider your domain if there is no other match. To do so, add the following to the /etc/resolv.conf file:

search my.university.edu

In this way, you do not even need to add the hosts to ~/.ssh/config. ssh zeus and the resolver finds the right host for you. Since it happens on the resolver level, it also works for other programs such as curl and Firefox.

Note that programs like NetworkManager overwrite resolv.conf. In the case of NetworkManager, you need to change the Search Domain setting to my.university.edu.

Documentation:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .