Git SSH多賬號(hào)配置
未配置過git賬號(hào) 無 .ssh 文件夾
- 查看是否存在 .ssh 文件夾 命令
cd ~/.ssh/
- 創(chuàng)建 .ssh 文件夾 命令
# 這里設(shè)置目錄為 C:\Users
mkdir ../.ssh/
配置全局
- 查看全局配置
# 查詢是否配置過 user.name 和 user.email
git config --global --list
- 設(shè)置全局配置
# 設(shè)置全局用戶名
git config --global user.name 用戶名
# 設(shè)置全局郵箱
git config --global user.email 郵箱
- 清除全局配置
# 清除全局用戶名
git config --global --unset user.name
# 清除全局郵箱
git config --global --unset user.email
git多賬號(hào)配置
- 創(chuàng)建config文件
touch config
- 創(chuàng)建新的SSH keys
# 直接回車 創(chuàng)建的是默認(rèn)生成的 id_rsa和id_rsa.pub
ssh-keygen -t rsa -C 郵箱
注意:
如果需要自定義文件名
則需要在提示輸入文件名的時(shí)候
Enter file in which to save the key (~/.ssh/id_rsa): id_rsa_new
id_rsa_new
就是自定義的文件名
- 添加到SSH agent中
ssh-add ~/.ssh/id_rsa_work
注意:
如果報(bào)錯(cuò)提示 Could not open a connection to your authentication agent
解決方案:
ssh-agent bash
ssh-add ~/.ssh/你設(shè)置的文件名 (例如:id_rsa)
- 配置到 config 文件中
# 這里我以coding為例
Host git@e.coding.net
HostName https://e.coding.net
User git
IdentityFile ~/.ssh/id_rsa_coding_private
- 測(cè)試是否連接到coding
ssh -T git@e.coding.net