我有兩個 SSH 密鑰。一個是我公司的github賬號,另一個是我個人的github賬號。在我為我的個人帳戶創建另一個 SSH 密鑰之前,我的公司帳戶 SSH 密鑰一直運行良好。我創建的最后一個 SSH 密鑰對是用于我的個人帳戶的,并且運行良好。現在,我正在嘗試推送到我的公司帳戶,但收到一條錯誤訊息。有沒有辦法同時使用兩個 SSH 密鑰或在它們之間切換?我將分享我的組態檔。第一個是我公司帳戶的原始 SSH 密鑰。
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Host github.com
HostName github.com
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
uj5u.com熱心網友回復:
Git FAQ 徹底涵蓋了這個主題,包括SSH和HTTPS。對于 SSH,常見問題在您的~/.ssh/config:
# This is the account for author on git.example.org.
Host example_author
HostName git.example.org
User git
# This is the key pair registered for author with git.example.org.
IdentityFile ~/.ssh/id_author
IdentitiesOnly yes
# This is the account for committer on git.example.org.
Host example_committer
HostName git.example.org
User git
# This is the key pair registered for committer with git.example.org.
IdentityFile ~/.ssh/id_committer
IdentitiesOnly yes
然后它指出您需要更改您的網址:
然后,您可以調整您的推送 URL 以使用
git@example_author或git@example_committer代替[email protected](例如,git remote set-url git@example_author:org1/project1.git)。
顯然,在您的情況下,您將要使用github.com代替git.example.org并且您可能希望為主機名使用不同的條目。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/329786.html
