The SSH client configuration file
The file is located at
~/.ssh/config
Example 1
A regular configuration:
Host server.tld
User username
IdentityFile ~/.ssh/id_ed25519
ForwardAgent yes
The ForwardAgent option lets you use your local SSH key on the remote server (for example to git pull there) without copying your private key to that server. It’s built into SSH and easy to set up. Only enable it for servers you trust: anyone with root access on that server can use your forwarded agent while you are connected.
Example 2
Here I added a Hostname, so you can connect with the short name server01. You can also use an IP address as the hostname.
Host server01
User root
Hostname server01.sub.tld
IdentityFile ~/.ssh/id_ed25519
ForwardAgent yes
More options
ProxyJump jump.server.tld
This connects to the remote host through a jump host (bastion).
Defaults for every host
Settings under Host * apply to every connection. Put this block at the end of the file, because SSH uses the first value it finds:
Host *
IdentitiesOnly yes # only offer the key set for that host, not every key in the agent
ServerAliveInterval 60 # keep idle connections open (no "broken pipe")
ServerAliveCountMax 3
AddKeysToAgent yes # add the key to the agent after the first use
IdentitiesOnly yes also prevents Too many authentication failures when your agent holds many keys.
Reuse one connection (faster logins)
Host *
ControlMaster auto
ControlPath ~/.ssh/control-%C
ControlPersist 10m
The first ssh to a host opens the connection; the next ssh, scp or git to the same host for the next 10 minutes reuses it and starts instantly.