Windows建立多個github git ssh祕鑰
阿新 • • 發佈:2021-06-15
一、準備多個郵箱
email1和email2
二、為email1和email2生成公鑰和私鑰(進入.ssh目錄執行一下命令:C:\Users\dev\.ssh實際以自己的本地目錄為準,反正就是找到自己電腦的.ssh目錄下就好了)
ssh-keygen -t rsa -f my_rsa_1 -C email1 ssh-keygen -t rsa -f my_rsa_2 -C email2
執行以上會出現下面截圖顯示的底部倒數4個檔案。黃色圈起來的檔案不用管,系統預設生成的。
重點講一下最上面的config檔案核心配置,這個檔案不是系統生成的,而是需要我們自己建立的。注意這個檔案沒有後綴名的。
Host github.com //可自定義 HostName github.com PreferredAuthentications publickey User git IdentityFile C:/Users/dev/.ssh/my_rsa_1 Host github2 //可自定義 HostName github.com PreferredAuthentications publickey User git IdentityFile C:/Users/dev/.ssh/my_rsa_2
Host
可以自定義的,表示本地hub服務代理,但是這個名字會影響實際遠端倉庫操作的ssh地址。
比如說上面的Host github2,如果你遠端的SSH地址是:git@github.com:test/example-springboot.git
那麼你本地實際操作的地址得寫成:git@github2:test/example-springboot.git
三、配置遠端倉庫的公鑰
將相應的.pub結尾的檔案複製到相應的github平臺就好了。