![服务器始终默认为 github.com,并显示错误消息“权限被拒绝(公钥)”](https://linux22.com/image/733428/%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%A7%8B%E7%BB%88%E9%BB%98%E8%AE%A4%E4%B8%BA%20github.com%EF%BC%8C%E5%B9%B6%E6%98%BE%E7%A4%BA%E9%94%99%E8%AF%AF%E6%B6%88%E6%81%AF%E2%80%9C%E6%9D%83%E9%99%90%E8%A2%AB%E6%8B%92%E7%BB%9D%EF%BC%88%E5%85%AC%E9%92%A5%EF%BC%89%E2%80%9D.png)
我试图通过 ssh 连接到远程服务器,但总是被重定向到 github 并出现错误消息,即使我没有尝试连接到 github:
ssh username@<anyServerName>
[email protected]: Permission denied (publickey).
更新:运行它-v
并且调试日志看起来像这样:
debug1: Reading configuration data /Users/zenghoulim/.ssh/config
debug1: /Users/zenghoulim/.ssh/config line 3: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to github.com port 22.
debug1: Connection established.
debug1: identity file /Users/zenghoulim/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /Users/zenghoulim/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.7
debug1: Remote protocol version 2.0, remote software version babeld-26093308
debug1: no match: babeld-26093308
debug1: Authenticating to github.com:22 as 'zenghou'
我的.ssh/config
文件看起来像这样:
# --- Sourcetree Generated ---
Host *
HostName github.com
User zenghou
PreferredAuthentications publickey
IdentityFile /Users/zenghoulim/.ssh/id_rsa
UseKeychain yes
AddKeysToAgent yes
# ----------------------------
我已经尝试修复这个问题一个星期了,但似乎找不到任何解决方案。任何帮助都将不胜感激!
答案1
这是您的文件中的问题.ssh/config
:
Host *
意思*
是“将以下配置应用于每个 SSH 连接,无论您使用哪个主机名”。
下一行的HostName github.com
意思是“无论您在命令行上写哪个主机名,ssh 都应该始终连接到 github.com。
如果您不想将这些配置行应用于所有主机,则应该将其更改Host *
为仅适用于您实际需要的主机 -Host *.github.com
或者任何您实际想要使用的主机。