Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question

migrated from serverfault.com May 28 '13 at 19:34

This question came from our site for professional system and network administrators.

    
Off-topic here, but I really would love to know if this is possible. –  ceejayoz May 28 '13 at 18:17

2 Answers 2

up vote 7 down vote accepted

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).
share|improve this answer
1  
Off topic, but you can find a lot of nice config tricks here –  demure May 28 '13 at 19:31

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:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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