Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a simple way to retrieve the IP of a HostName from an ssh config on the command line? Many times I have to use scp and would like to connect to a machine, but I remember only the HostName.

share|improve this question
1  
scp will read your .ssh/config and /etc/ssh/ssh_config. is there a reason you can't scp by the aliases defined in the config? –  Tim Kennedy Nov 29 '11 at 4:57
    
You should add this as an answer. I think when I tried it first, I didn't provide the key or something, so it didn't recognize the host. –  m33lky Nov 29 '11 at 6:33
    
seemed a little light for an answer, but i added it. along with what I consider to be some interesting ssh config related reading. –  Tim Kennedy Nov 29 '11 at 15:25
add comment

3 Answers

up vote 2 down vote accepted

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/

share|improve this answer
    
Short to-the-point answers are great. Otherwise it's easy to go off-topic. Anyone doing tunneling should take a look at sshuttle. –  m33lky Nov 29 '11 at 21:09
add comment

Usually, you can do host HostName and you'll get the IP address.

If host isn't installed (it should be), you can use nslookup HostName 8.8.8.8 which will use the Google DNS servers to do the lookup.

To do these things, either your machine's resolver has to have a correct config (in file /etc/resolv.conf and maybe /etc/nsswitch.conf) or you have to use a "fully qualified domain name", complete with host, domaiin, and "TLD" (.org, .com, .net that sort of suffix).

share|improve this answer
2  
This doesn't look up host aliases in ~/.ssh/config, which I understand to be the point of this question. –  Gilles Nov 29 '11 at 22:06
    
Haha, I just noticed that too. ssh's HostName is an arbitrary alias, not a domain name. –  m33lky Nov 30 '11 at 1:40
add comment

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'
share|improve this answer
add comment

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.