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 it possible to query ~/.ssh/config in the command line? Let's say I would like to retrieve what IP address does the particular alias point to in a separate program, is it possible?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

If I understand that you just want the IP address returned, ie., 192.168.1.1, then this is one (incredibly brittle) way of querying the file from the command line, provided you have the appropriate permissions to read it and your .ssh/config is consistently formatted:

awk '/Host $youralias/ {getline; print $2}' .ssh/config


I am only posting this as I would like to understand how to use awk to do this, but my knowledge is, obviously, quite limited.

share|improve this answer

Not totally sure what you are asking...

Say you have a SSH alias for 'mainserver' so you can do ssh mainserver. If you want it to also work for ping mainserver, you need to put an alias in /etc/hosts, like so:

/etc/hosts:

192.168.0.1 comp-one
192.168.0.2 comp-two

192.168.0.20 mainserver

Then you could do ping mainserver and it would ping 192.168.0.20.

share|improve this answer

The file you mention is a text file, it contains host names and possibly IP addresses to identify the machines you connect to. Host names can be resolved to IP addresses using the host(1) command. The format is quite simple, so it isn't too hard to find out what is in there. Note that wildcards can be used in the file (mine states *.fedoraproject.org).

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.