SSH Config
The SSH config is a file that contains shortcuts for frequently used hosts.
The following stanza:
Host github
Hostname github.com
User <username>
IdentityFile ~/.ssh/id_ed25519
enables you to connect to the github server with this command:
ssh github
instead of the more verbose:
ssh -i ~/.ssh/id_ed25519 <username>@github.com
SSH Config syntax
The SSH config file is a plain text file located at ~/.ssh/config
. It can be edited in any text editor.
Each stanza is in the form of:
Host <short name>
Hostname <remote host name or IP address>
User <remote user name>
IdentityFile <path to SSH private key>
Note that indentations are spaces, not tabs.
You can also add a "wildcard" stanza which will apply to all hosts, unless overridden in that host's stanza.
Host *
AddKeysToAgent yes
UseKeychain yes
IdentitiesOnly yes
IdentityFile ~/.ssh/id_ed25519
PreferredAuthentications publickey
User ec2-user
With the above wildcard stanza, the stanza for a host could look like:
Host prod
Hostname a.b.c.d
If another host uses a different username:
Host prod2
Hostname w.x.y.z
User other