我使用三個不同的 GitHub 帳戶。
我已經正確設定了我的 ssh 密鑰(創建、添加到密鑰環、添加到 github)。
做ssh-add -l回報:
3072 SHA256:/Vq3tN5FxtE64LALAe25GQr MpIPbGg [email protected] (RSA)
3072 SHA256:9NheazRnzMzicLALA6z70kQeO6tQcNZcePJw0RRk [email protected] (RSA)
3072 SHA256:r7uaTSfE9ZXn7LALAGHIn4syyaKPPyXsKdK8Sjk [email protected] (RSA)
在我的~/.ssh/.config檔案中,我有:
# GITHUB FIRST
Host github.com-first-user
HostName github.com
User git
IdentityFile ~/.ssh/first-user
# GITHUB SECOND
Host github.com-second-user
HostName github.com
User git
IdentityFile ~/.ssh/second-user
# GITHUB THIRD
Host github.com-third-user
HostName github.com
User git
IdentityFile ~/.ssh/third-user
在我的全域 git 配置中,我沒有添加任何用戶/電子郵件配置。
每個存盤庫都包含正確的用戶和電子郵件。
當我嘗試推送時,它說first-user沒有權限。
ERROR: Permission to user/repo.git denied to first-user.
fatal: Could not read from remote repository.
我相信在某處讀過 git 使用它看到的 ssh 密鑰,所以它可能正在看到第一個密鑰并使用它。
git config --list --show-origin --show-scope在 repo 檔案夾中做,我得到:
global file:/home/user/.gitconfig core.autocrlf=input
local file:.git/config user.name=Second
local file:.git/config [email protected]
第一個用戶沒有任何設定。
做git remote -v回報:
origin [email protected]:user/repo.git (fetch)
origin [email protected]:user/repo.git (push)
相關說明:
執行ssh -T github.com-second-user回傳Hi first-user!,您已成功通過身份驗證...
注意:使用 git cli 和通過 phpStorm UI 使用 git 都會發生此錯誤。
如何強制它為第二個用戶使用第二個密鑰?
謝謝!
uj5u.com熱心網友回復:
添加:
IdentitiesOnly yes
(對于三個別名的每個Host條目,或全域)。如果沒有此設定,ssh首先嘗試所有代理提供的身份,然后嘗試列出的檔案。由于第一個代理提供的物體作為第一個用戶作業,這讓你作為第一個用戶進入 GitHub:第二個用戶的密鑰從未嘗試過,GitHub 認為你是第一個用戶。
使用IdentitiesOnly yes, ssh 僅嘗試列出的IdentityFile條目,按照它們出現的順序(仍然根據需要從代理獲取密鑰,因此您只需將.pub檔案存盤在有問題的計算機上,如果那不是您的主系統)。
(Git在這里所做的沒有任何區別:所有這些都完全取決于 ssh 和 GitHub。)
uj5u.com熱心網友回復:
嘗試將您的來源更改為:
[email protected]:user/repo.git
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/523768.html
標籤:混帐SSH
