I know this question is super old, but figuring out the right answer was driving me crazy (because the man
explanations seem contradictory and the other answer to this question is simply wrong).
In commonsimple usage:
Host
is for the actual hostname & there's no HostName
OR
Host
is the nickname of the host. & (You can do fancier things with this field, but that's outside the scope of this answer.)
HostnameHostName
is for the actual hostname.
Simple example:
$ cat ~/.ssh/config
Host dev
Hostname <hostname>
User <username>
IdentityFile <path_to_private_key>
$ ssh dev
# Equivalent to "ssh -i <path_to_private_key> <username>@<hostname>"
Note: II've found there's a slight complication for git repo servers, because often theirnicknames can be problematic with any services that give you example command uses the full hostnamecommands, e.g.:
$ cat ~/.ssh/config
Host git
Hostname github.com
User <username>
IdentityFile <path_to_private_key>
$ git clone [email protected]:<username>/<project>.git
Permission denied (publickey). # Failure
For a host like this, it probably makes more sense forYou either have to edit the example command to use your nickname or put the actual hostname in the Host
value to be the full hostnamefield.
$ cat ~/.ssh/config
Host github.com
User <username>
IdentityFile <path_to_private_key>
$ git clone [email protected]:<username>/<project>.git
Cloning... # Success!