ssh not using server name in config
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?
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>
.
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