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.

in .ssh/config file

Scenario is that I have two public ips now (dynamic), one is connect to aws and one is connect to rackspace

Both require different pem keys to connect. But I want to use ssh config file to save my time

Host <ip1> 
User root
Port 22
HostName %h
IdentityFile ~/.ssh/aws.pem

Host <ip2> 
User root
Port 22
HostName %h
IdentityFile ~/.ssh/rackspace.pem

From this setting, i cannot distinguish which pem file to be use. I want to make use of the Host as part of parameter to specify which server to connect to e.g. ssh aws-ip1 ssh rack-ip2

then the config file can distinguish which pem file to use

Anyone know how to do this?

share|improve this question

2 Answers 2

The 'Host' part is kind of 'shortcut' you can use:

Host aws-ip1
    HostName ip-or-name-to-ip1
    IdentityFile ~/.ssh/aws.pem

Host rack-ip2
    HostName ip-or-name-to-ip2
    IdentityFile ~/.ssh/rackspace.pem

and then you just use ssh aws-ip1 or ssh rack-ip2 ...

To quote from man ssh-config:

Host    Restricts the following declarations (up to the next Host key-
        word) to be only for those hosts that match one of the patterns
        given after the keyword.
share|improve this answer
    
Thx: but how can I pass ip1, ip2 to hostname? –  Kit Ho Nov 3 '12 at 11:49
    
you write the ip-address behind the "Hostname" statement. maybe you did not asked exactly what you wanted. do you need a group of hosts having the same setting? –  akira Nov 3 '12 at 11:51
    
then this would be hardcodeded, my question is that how can I pass the parameter using Host, both IP address are dynamically, I want sth that we can pass parameter into HostName –  Kit Ho Nov 3 '12 at 11:54
    
well, you might go with HostName %h in .ssh/config and then you might use ssh aws-ip1 -o HostName real_ip –  akira Nov 3 '12 at 11:56
    
Do you mind describe more how to use %h? If %h is accepted from "Host", then I cannot distinguish aws or rackspace... –  Kit Ho Nov 3 '12 at 12:00

Another option is to use plain old-school shell aliases:

 alias ssh_rack="ssh -i .ssh/rackspace.pem"
 alias ssh_aws="ssh -i .ssh/aws.pem"

and then use them instead of ssh.

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.