我试图让我的 .ssh/config 支持同一主机的不同 ssh 密钥,以便我可以作为我的个人或工作用户提交到 bitbucket,而其他 ssh 内容仍然使用我的工作用户。
\n我的配置文件如下所示:
\nHost bitbucket-personal\n HostName bitbucket.com\n User git\n IdentityFile ~/.ssh/personal\n IdentitiesOnly yes\n\nHost *\n AddKeysToAgent yes\n UseKeychain yes\n IdentityFile ~/.ssh/work\n
Run Code Online (Sandbox Code Playgroud)\n当我ssh bitbucket-personal
使用的~/.ssh/work
密钥不是我所期望的(参见下面的文档,它应该使用第一个匹配的 IdentityFile)。但所有其他参数都被正确引用(例如git@bitbucket.com)。如果我删除 Host * 部分,它将使用正确的密钥。
我究竟做错了什么?我猜我误解了这里的优先级是如何工作的。
\n\n\n对于每个参数,将使用第一个获得的值。配置文件包含由 \xe2\x80\x9cHost\xe2\x80\x9d 规范分隔的部分,并且该部分仅适用于与规范中给出的模式之一匹配的主机。匹配的主机名是命令行上给出的主机名。
\n由于使用每个参数的第一个获得的值,因此应在文件开头附近给出更多特定于主机的声明,并在末尾给出一般默认值。
\n
下面是完整详细的跟踪:
\nluke$ ssh -v bitbucket-personal\nOpenSSH_7.8p1, LibreSSL 2.7.3\ndebug1: Reading configuration data /Users/luke/.ssh/config\ndebug1: /Users/luke/.ssh/config line 1: Applying options for bitbucket-personal\ndebug1: /Users/luke/.ssh/config line 7: Applying options for *\ndebug1: Reading configuration data /etc/ssh/ssh_config\ndebug1: …
Run Code Online (Sandbox Code Playgroud)