我们在日常工作中会遇到同一台服务器部署多个放在github上的应用,这样我们就需要配置不同的ssh-key对应不同的环境。
1,生成ssh-key
ssh-keygen -t rsa -C 'youremail@your.com' -f ~/.ssh/xxx_rsa

2,将xxx_rsa.pub中的内容添加到自己的github中。
cat ~/.ssh/xxx_rsa.pub

3,添加到github

4,进入到~/.ssh目录下新建config文件,用编辑器打开config文件并添加内容
# xx1项目
Host github-tm.com # 访问git网址的域名
HostName github.com # git官网地址,都是github.com
User git
IdentityFile /root/.ssh/id_rsa # rsa绝对路径
# xx2项目
Host github-dk.com
HostName github.com
User git
IdentityFile /root/.ssh/xiaoke_rsa

5,测试
ssh -T git@github-xxx.com

6,Git命令clone项目
git clone git@github-xxx.com:leadson/xxx.git
网友评论