我目前在我的.ssh / config文件中有这个:
Host * AskPassGUI no IdentityFile ~/.ssh/%r@%h IdentityFile ~/.ssh/%h IdentityFile ~/.ssh/id_dsa
当我ssh到一个主机,我没有一个密钥文件,login工程,但我也得到这些错误:
no such identity: /Users/user/.ssh/[email protected]: No such file or directory no such identity: /Users/user/.ssh/example.com: No such file or directory
理想情况下,我想ssh检查文件,但不会抛出一个错误,如果他们中的任何一个找不到。 这个想法是能够把我的.ssh目录下的名为“[email protected]”或“example.com”的私钥放到我的.ssh目录下,并且在使用这个用户/主机组合login时使用这些私钥,而不是抱怨那么如果文件丢失,则正常login。 我不想使用这个答案中描述的Host指令,因为我有很多密钥文件,我宁愿不必将它们添加到文件夹,然后编辑configuration文件,并添加每个主机指令。
这样的事情可能吗?
回顾openssh的源代码后,似乎答案如下:
OpenSSH认为〜/ .ssh / config中的IdentityFile行是“用户提供的”。 如果找不到用户提供的IdentityFile,则会向控制台logging警告。 请参阅sshconnect2.c中的'load_identity_file'函数。
所以不幸的是,我们不可能做到我想做的事情,但存在一些解决方法:
一个是将LogLevel ERROR行添加到〜/ .ssh / config文件中。 这比INFO的默认日志级别低一级。 我没有select这个,因为我不确定会压制哪些警告。
我select的选项是将以下行添加到我的/ etc / ssh_config文件中:
Host * IdentityFile ~/.ssh/%r@%h IdentityFile ~/.ssh/%h # The lines below maintain ssh's default behavior: IdentityFile ~/.ssh/identity IdentityFile ~/.ssh/id_rsa IdentityFile ~/.ssh/id_dsa
然后我从〜/ .ssh / config文件中删除了IdentityFile行。
这些行在/ etc / ssh_config中时不被认为是“用户提供的”,因此当找不到文件时,不会logging任何内容。