When you manage more than one server or SSH key, a connection can fail even though the right private key is on your machine. OpenSSH may be using a different identity, or the host settings you expected may not match the destination.
IdentityFile lets you associate a private key with a host in your SSH client configuration. Once set up, you can connect with a short alias instead of repeating -i , the username, and the server address each time.
Turn a working command into a host alias
Start with a connection that already works. For example:
ssh -i ~/.ssh/id_ed25519_prod [email protected]
Enter fullscreen mode
Exit fullscreen mode
Add a matching host block to ~/.ssh/config :
Host production HostName server.example.com User deploy IdentityFile ~/.ssh/id_ed25519_prod IdentitiesOnly yes
Enter fullscreen mode
Exit fullscreen mode
Now connect with:
ssh production
Enter fullscreen mode
Exit fullscreen mode
Host is the shortcut you type; HostName is the actual server address.…