Это ожидаемое поведение согласно странице руководства ssh_config
:
IdentityFile
Specifies a file from which the user's DSA, ECDSA or DSA authentica‐
tion identity is read. The default is ~/.ssh/identity for protocol
version 1, and ~/.ssh/id_dsa, ~/.ssh/id_ecdsa and ~/.ssh/id_rsa for
protocol version 2. Additionally, any identities represented by the
authentication agent will be used for authentication.
[...]
It is possible to have multiple identity files specified in configu‐
ration files; all these identities will be tried in sequence. Mul‐
tiple IdentityFile directives will add to the list of identities
tried (this behaviour differs from that of other configuration
directives).
По сути, указание IdentityFile
s просто добавляет ключи в текущий список, Агент SSH уже представлен клиенту.
Попробуйте переопределить это поведение следующим образом в нижней части вашего .ssh / config
файла:
Host *
IdentitiesOnly yes
Вы также можете переопределить этот параметр на уровне хоста, например:
Host foo
User bar
IdentityFile /path/to/key
IdentitiesOnly yes
После решения James Sneeringer Вы могли бы просто хотеть установить ssh_config вроде:
Host *.mycompany.com
IdentityFile .ssh/id_dsa_mycompany_main
Host *.mycustomer.com
IdentityFile .ssh/id_dsa_mycustomer
Host *
RSAAuthentication no #this should be up top, avoid ssh1 at all costs
PubkeyAuthentication no
Если Вы соединяетесь с конкретным ключом ко многим машинам не в общем домене, считаете предоставление им всем CNAMEs в Вашем собственном DNS. Я делаю это со всеми клиентскими системами.
Подобный решению user23413, можно отключить аутентификацию с открытым ключом в целом для конкретного хоста (или подстановочный шаблон):
Host *.example.org
RSAAuthentication no # SSHv1
PubkeyAuthentication no # SSHv2
Если Вы укажете на конкретный файл ключей с ssh-i/path/to/key, то он будет только использовать тот, даже если другие будут загружены в агент, и Вам не предложат пароль. Можно также отредактировать Вас ~/.ssh/config и реклама что-то вроде этого...
Хост foo.example.com
IdentityFile .ssh/id_rsa_foo.example.com
можно также сделать...
Хост *.example.org
IdentityFile .ssh/id_rsa_example.org
Although others have hinted at this with configuration-based solutions, it's probably worth pointing out that you can easily do this one-time-only on the command line with:
ssh -o 'PubkeyAuthentication no' myhostname.mydomain