管理Git生成多個ssh key
- 生成兩個key
- 生成key的指令
,-f後面給的生成key的名字,如果沒有指定新的名字,那麼每次ssh-keygen生成的名字相同,就會發生覆寫同名檔案的情況的發生。ssh-keygen -t rsa -C “Your Email Address” -f 'Your Name'
- 生成key的指令
- 生成兩個key後,添加到對應伺服器的ssh kyes管理設定中。
- 本地添加私鑰
- 本地添加私鑰名指令,如果出現“Could not open a connection to your authentication agent”的問題,可以執行指令
再運作添加指令。另外,可用通過ssh-agent bash
檢視私鑰清單ssh-add -l
來清空私鑰清單ssh-add -D
-
修改配置檔案
1.在~/.ssh目錄下建立一個config的檔案
2.添加以下内容
3.一點說明# oschina Host git.oschina.net HostName git.oschina.net PreferredAuthentications publickey IdentityFile ~/.ssh/oschina # github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa
- 以上的我采用的是oschina的碼雲和github的兩種kye的結合體,其中每段最後的
跟着是你自己ssh key的名字,不要搞錯了。IdentityFile
- 最後就是測試咯
- oschina的測試方法
;成功收到的回複為“Hi USERNAME! You’ve successfully authenticated, but GITEE.COM does not provide shell access. ”ssh -T [email protected]
- github的測試方法
;成功收到的回複為”Hi ’Your Name‘ ! You’ve successfully authenticated, but GitHub does not provide shell access.“ssh -T [email protected]
- oschina的測試方法
- 以上的我采用的是oschina的碼雲和github的兩種kye的結合體,其中每段最後的
- 借鑒文章
- git 配置多個SSH-Key
- 管理git生成的多個ssh key