我正在使用一個有兩個用戶的 ec2 服務器。讓我們稱它們為 user1 和 user2,它們在 ~/.ssh 檔案夾中具有單獨的 user1key 和 user2key。
我在 ~/.ssh 檔案夾中的 git 組態檔如下所示
Host user1
HostName github.com
IdentityFile ~/.ssh/user1key
Host user2
HostName github.com
IdentityFile ~/.ssh/user2key
我想使用 user1 來拉取并提交對源的更改。但是,當我運行時git pull,它會詢問我沒有的 user2key 的密碼。
我嘗試git config user.name "user1"在存盤庫中使用,然后做了一個git pull,但它再次要求輸入 user2key 的密碼。
我什至嘗試從組態檔中洗掉 user2 的資訊并git pull再次運行,但它仍然要求輸入 user2key 的密碼。
uj5u.com熱心網友回復:
user.name與遠程服務器的身份驗證無關。
如果您使用帶有名為 user1 的主機條目的 ~/.ssh/config,那么您的遠程 URL 必須變為:
git@user1:user1/repo-name
您可以測驗與github.comwith的連接ssh -Tv user1。
同樣,您需要為您的 URL 使用 Host 條目的名稱。
它成為了一條捷徑
ssh -i ~/.ssh/user1key -Tv [email protected]
注意:User git在每個Host小節中添加,這樣您甚至不必指定git@.
Host user1
HostName github.com
User git
IdentityFile ~/.ssh/user1key
Host user2
HostName github.com
User git
IdentityFile ~/.ssh/user2key
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/510508.html
