我的電腦上有兩個 github 帳戶:一個用于作業,一個用于我的個人帳戶。(我在 Mac 上)我的 .ssh 組態檔:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Host github.com-personalAccount
HostName github.com
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_personal
這作業正常。我將 ssh 密鑰添加到我的 github 帳戶。我可以很好地推送到我的個人存盤庫,也可以推送到作業存盤庫。
現在,我被邀請作為第三個 repo 的合作者,我已經接受了邀請。我想我可以使用我的個人 ssh 密鑰:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Host github.com-personalAccount
HostName github.com
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_personal
Host github.com-otherUserAccount
HostName github.com
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_personal
然后,在回購中:
git remote add origin [email protected]:otherUserAccount/redacted.git
git add .
git commit -m "Initial commit"
git push -u origin master
但它不起作用。我收到此錯誤:
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我已經雙重和三次檢查了。回購地址是正確的。
請幫忙!
提前致謝!
uj5u.com熱心網友回復:
Git 不會傳遞給 SSH 存盤庫名稱,它只會傳遞user@hostname. 因此,要使 SSH 使用正確的密鑰,Git 必須傳遞從遠程 URL 獲取的正確主機名。您.ssh/config的遠程 URL 必須是(就 Git 命令而言):
git remote set-url origin [email protected]:personalAccount/personalRepo.git
和
git remote set-url origin [email protected]:otherUserAccount/otherRepo.git
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/351150.html
