github ssh 配置_Git多使用者配置
阿新 • • 發佈:2020-12-17
技術標籤:github ssh 配置git配置全域性使用者名稱和密碼
Git多使用者配置
“兩個倉庫,github上一個,gitlab上一個,使用者名稱與密碼不同,而且兩個專案都需要處理。這時候就需要配置多個使用者,進行不同倉庫的操作。
1. 清除之前的全域性配置
#列出全域性使用者名稱,郵箱配置
gitconfig--global--list
#重置使用者名稱和郵箱
gitconfig--global--unsetuser.name
gitconfig--global--unsetuser.email
2. 生成新的祕鑰
**刪除舊的祕鑰:**舊的祕鑰存放在使用者目錄的.ssh資料夾中,刪除其中的 id_rsa
id_rsa.pub
之類的公鑰和金鑰檔案。
生成新的祕鑰:
ssh-keygen-trsa-C"[email protected]"
ssh-keygen-trsa-C"[email protected]"
輸入建立的祕鑰檔名稱,為了區分可以分別輸入id_rsa_gitlab
,id_rsa_github
3. 新增ssh key
將公鑰配置到github和gitlab中。
4. 將私鑰新增到本地
ssh-add~/.ssh/id_rsa_github
ssh-add~/.ssh/id_rsa_gitlab
“報錯:Could not open a connection to your authentication agent.解決方法
ssh-agentbash#執行此方法
5. 管理祕鑰
在.ssh資料夾需要建立祕鑰配置檔案config,用來配置不同的祕鑰連線不同的倉庫。
Hostgithub
HostNamegithub.com
Userbinfenshengdai
IdentityFile~/.ssh/id_rsa_github
Hostgitlab
HostNamegitlab.mygitlab.com
Usertest
IdentityFile~/.ssh/id_rsa_gitlab
- **Host:**倉庫的別名,可以隨意取名
- **HostName:**倉庫網站的域名
- **User:**倉庫上面的使用者名稱
- **IdentityFile:**私鑰的絕對路徑
驗證連線是否成功:
ssh-T[email protected]
ssh-T[email protected]
6. 倉庫配置
我們需要為每個倉庫單獨配置使用者名稱資訊,假設我們要配置 github 的某個倉庫,進入該倉庫後,執行:
gitconfig--localuser.name"username"
gitconfig--localuser.email"[email protected]"