I try to make a config for connecting to a remote ssh server via the command ssh <server short name>. I put this into ~/.ssh/config:

Host <server short name> <server full name>
    Host <server full name>
    User <my username on the remote server>
    Port 22022
    ForwardAgent yes
    ForwardX11 yes

I can connect using

$ ssh <server full name>

but it fails with the command

$ ssh <server short name>
ssh: Could not resolve hostname <server short name>: Name or service not known

I've checked the spelling several times and I could not find a mistake. Any ideas why the second command fails?

  • run the command with verbose logging. And make sure you don't have typo in the name. – Jakuje Oct 11 '15 at 8:19

Host is not as SSH option; it always starts a new section, regardless of indent level. Thus you have two config sections; an empty one matching <shortname> <fullname> and then one matching just <fullname>.

Instead, the second line needs to be HostName <fullname>.

  • having same issue as the OP, except i just copy/pasted an already working section to give a shortened name for a host that already works (e.g. changed Host value only, already have HostName correct) – Michael Aug 19 '17 at 20:25

See the man pages

The host keyword is used to group configuration together and can also be used to define an alias for a host or configure multiple hosts at once.

Consider the following scenario: At work you have two servers, called dev.example.com and test.example.com where you use the same key pair and a github account with a second key pair. You could then setup the following config

host *.example.com
identityfile ~/.ssh/work-key
user bob
Port 22022
ForwardAgent yes
ForwardX11 yes

host github.com
identityfile ~/.ssh/github-key

host dev
hostname dev.example.com

host test
hostname test.example.com

And the use something like this to connect:

ssh dev

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.