针对于工作环境远程仓库和开源仓库如gitee,github分开账户管理
具体步骤如下:
一、公钥加密
cd ~/.ssh
ssh-keygen -t rsa -C "xxx@qq.com"
#设置文件名,自动生成私钥和公钥(.pub)
Enter file in which to save the key (/c/Users/icecr/.ssh/id_rsa): id_rsa_gitee
#将ssh key添加到SSH agent中
ssh-add ~/.ssh/id_rsa_gitee
如果报错 执行ssh-add时出现Could not open a connection to your authentication agent, 则执行
ssh-agent bash
二、在~/.ssh下新增config文件
host gitee.com
Hostname gitee.com
User 用户名
IdentityFile ~/.ssh/id_rsa_gitee
host gitlab.com
Hostname gitlab.com
User 用户名
IdentityFile ~/.ssh/id_rsa
三、具体到某个项目下,可以设置该项目的git配置,配置信息在项目目录下.git/config
进入项目/.git目录下执行以下命令:
git config user.name icecrea
git config user.email xxxx@qq.com
四、将ssh公钥设置到远程仓库
公钥存储在~/.ssh/id_rsa_gitee.pub
五、测试连接
ssh -T git@gitee.com