how to find out the ip of an ssh HostName

To map from the host argument given on the command line to the ssh_config hostname entry is easy using ssh itself.

You can ask it to evaluate and print out what it would use for the configuration for a command line, without actually connecting. Then you simply need to pull out what it lists for hostname (Note that it canonicalizes configuration key names by converting them to lower case). A simple example is:

ssh -G database | awk '/^hostname / { print $2 }'

If .ssh/config contains:

Host database
Hostname database.example.com

This will print out database.example.com.

To ping it, you can of course evaluate the output and use it as an argument:

ping $(ssh -G database | awk '/^hostname / { print $2 }')

scp will read your ~/.ssh/config and /etc/ssh/ssh_config. as long as you scp to/from the name of one of the host aliases in your ssh config, it should work.

since that seems sort of short to be an answer, here's some more info with things you can do with your ssh config...

Here's a post that describes some of the advanced features of the ssh config file: http://magazine.redhat.com/2007/11/27/advanced-ssh-configuration-and-tunneling-we-dont-need-no-stinking-vpn-software/

Need to tunnel ssh/scp through an http proxy? no problem, just use the steps outlined here: http://www.mtu.net/~engstrom/ssh-proxy.php

Another use of the ProxyCommand option: http://jasonmc.wordpress.com/2008/04/16/ssh-magic/


There's no need to do that for scp, but you can use ssh's debugging traces.

ssh -v HostName ' ' 2>&1 | grep '^debug1: Connecting to'