git配置多账户

查看全局配置

git config --global user.name
git config --global user.email

修改全局设置

git config --global user.name "xxx" // 配置全局用户名,如Github上注册的用户名
git config --global user.email "xxx@xx.com" // 配置全局邮箱,如Github上配置的邮箱

清除全局配置

git config --global --unset user.name
git config --global --unset user.email

1. 生成密钥

cd ~/.ssh
ssh-keygen -t rsa -C "xxx@xx.xom"
输入对应配置账户的存放私钥文件名

2. 将公钥添加到本地

ssh-add ~/.ssh/id_rsa_github

3. 修改配置文件对本地密钥进行管理

Host github // 别名
HostName github.com // 托管网站的域名
User xxx // 托管网站上的用户名
IdentityFile ~/.ssh/id_rsa_github // 使用的密钥文件

4. 在对应平台上添加公钥

cat ~/.ssh/id_rsa_github.pub

5. 测试

ssh -T git@github.com
posted @ 2024-03-27 21:51  BrandonV  阅读(32)  评论(0)    收藏  举报