多个github账号在一台电脑上如何使用呢?
1.生成不同的密钥
cd ~/.ssh
# 为个人账号生成密钥
ssh-keygen -t rsa -C "[email protected]" -f "github-personal"
# 为工作账号生成密钥
ssh-keygen -t rsa -C "[email protected]" -f "github-work"
2.登录账号上传公钥到github
账号
登录个人GitHub
账号,进入 Settings → SSH and GPG keys → New SSH key
,粘贴~/.ssh/github-personal.pub
公钥,点击 Add SSH key 完成添加。
第二个账号同理,这里示例为粘贴~/.ssh/github-work.pub
公钥
3.在当前项目中配置github账号和私钥
进入项目目录,在命令行执行下面的命令,就可以以当前用户名pull / push
# 查看当前git user name
git config user.name
# 查看当前git user email
git config user.email
# 设置当前git user name
git config user.name your_name
# 设置当前git user email
git config user.email [email protected]
# 设置当前使用的git私钥
git config core.sshCommand "ssh -i ~/.ssh/id_rsa -F /dev/null"
License:
CC BY 4.0