Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 1 down vote accepted

If I understand that you just want the IP address returned, ie.,, 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: comp-one comp-two mainserver

Then you could do ping mainserver and it would ping

share|improve this answer

This is a slightly more robust way of retrieving the HostName based on Host in the .ssh/config file.

    awk "\$1==\"Host\" {host=\$2} \$1==\"HostName\" && host==\"$1\" {print \$2}" "$HOME/.ssh/config"
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


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.