[英]Switching between multiple ssh keys in Git on Windows
我需要在我的客戶端有多個密鑰才能訪問Repository托管上的兩個不同帳戶。 請參閱https://redefy.repositoryhosting.com/support - >如何在我的客戶端上管理多個密鑰對的多個帳戶?
我不明白如何在Windows上的Git中的不同ssh鍵之間進行更改,有人可以幫助我嗎?
我假設你使用git bash和openssh。
與文章中的內容一樣,您可以為ssh客戶端創建一個列出所有帳戶的配置文件。 您可以在~/.ssh/config
自己的ssh客戶端配置文件中編寫以下配置
Host account-one
HostName server.example.com
User user-one
IdentityFile ~/.ssh/key-one
Host account-two
HostName server.example.com
User user-two
IdentityFile ~/.ssh/key-two
它所說的是你定義了兩種名為account-one
和account-two
“主機別名”。 如果您使用它們,在進行連接時,ssh客戶端將使用相應的HostName
, User
和IdentityFile
作為服務器地址,用戶名和ssh密鑰文件。 有了這個,您可以使用它們來訪問同一台服務器上的帳戶和密鑰。
在git中,您可以使用它們定義兩個遙控器
$ git remote add one account-one:repository.git
$ git remote add two account-two:repository.git
然后你可以推送到那些遙控器
$ git push one master
$ git push two master
哪個密鑰用於由git用於連接的SSH程序處理的服務器。 在默認設置中,這應該是命令行SSH客戶端(openSSH?)。
使用openSSH,您可以為~/.ssh/config
文件中的特定主機配置特定的密鑰文件:
Host foo.example.com
IdentityFile ~/.ssh/foo.example.com-id_rsa
Host bar.example.com
IdentityFile ~/.ssh/bar.example.com-id_rsa
其中~/.ssh/*.example.com-id_rsa
是每個服務器的私鑰文件。
我希望這有幫助。
在Windows上,您應該為PuTTY,PSCP,PSFTP和Plink嘗試Pageant SSH身份驗證代理。 此工具可以管理您的ssh密鑰及其密碼短語。 要與Git一起使用,您必須安裝Putty並鏈接到plink.exe設置GIT_SSH變量。
設置GIT_SSH
set GIT_SSH=<path-to-plink.exe>
丹尼爾
我會間接回答這個問題。 我以前使用過git bash,我發現當我通過git bash shell使用git時,它的行為就像一個mac或linux bash shell。 意思是,當使用git bash時,我可以回答你的問題:
'如果你使用git bash,你可以管理多個帳戶,就像你在linux或mac上一樣,使用ssh-agent / ssh-add和friends'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.