Version | ssh | scp | IdentityFile Keyword |
---|---|---|---|
SSH1, OpenSSH | ssh1 -i key_file ... | scp1 -i key_file ... | IdentityFile key_file |
SSH2 | ssh2 -i id_file ... | scp2 -i id_file ... | IdentityFile id_file |
#!/bin/csh cd ~/.ssh/my-keys # An example directory
What happens when you invoke an SSH client?foreach keyfile (*) ssh-add $keyfile end
In this case, the remote backup program gets run, authenticating with the key in file id-backups. You see, the wildcard in your script returns a list of key files in alphabetical order, so id-backups is added before id-normal, as if you'd typed:$ ssh server.example.com
Therefore, your SSH clients will always use the key id-backups when connecting to server.example.com because the agent provides it first in response to a client request. This might not be what you intended. The second problem only makes this behavior worse: identities in an agent take precedence over identities used manually. If an identity in the agent can successfully authenticate, there's no way to override the agent manually with the -i command-line option or the IdentityFile keyword. So in the earlier example, there is literally no way to use the identity id-normal. The obvious attempt:$ ssh-add id-backups $ ssh-add id-normal
still authenticates with id-backup s because it is loaded first into the agent. Even nonloaded identities can't override the agent's selection. For example, if you load only one identity into the agent and try authenticating with the other:$ ssh -i id-normal server.example.com
your ssh connection authenticates with the loaded identity, in this case id-normal, regardless of the -i option.[88]$ ssh-add id-normal $ ssh -i id-backups server.example.com
[88]This undocumented behavior drove us insane until we figured out what was happening. Similar behavior occurs with Kerberos authentication in SSH1. If you have Kerberos credentials that allow you to connect, you aren't running an agent, and you specify a key with -i, that key isn't used unless you destroy your Kerberos credentials (or otherwise make them unusable, for instance, hiding them by setting the KRB5CCNAME variable), because Kerberos is tried first.As a general rule, if you have two SSH identities valid on an SSH server, don't load either identity into an agent. Otherwise, one of those identities will be unable to access that server.
6.3. SSH Agents | 6.5. Summary |
Copyright © 2002 O'Reilly & Associates. All rights reserved.