mac对多个git服务器配置ssh

266 阅读1分钟

生成密钥

1.输入命令

ssh-keygen -t rsa -C "your email";

2.按下enter键后首先会让你输入存储的文件名,由于我们要生成多个ssh,所以这里要给一个自定义的文件名而不能用默认的文件名;(如果只配置一个git服务器的秘钥,那么这里就用它的默认文件名就好,一路enter下去就好了)

注意:此处的文件名需要是全路径,例如:~/.ssh/id_test_isa 或 /Users/你的用户名/.ssh/id_test_rsa

3.需要你输入密码,以后如果你需要git pull会要求你输入此处的密钥密码,所以为了方便,直接enter,默认密码为空;

4.确认密码,直接enter;

5.在对应的git网站上添加公钥,公钥是在.pub文件里,可以使用cat id_test_rsa.pub命令来查看,然后复制过去,也可以在访达里用文本编辑打开复制过去;

6.重点:配置config文件

打开config文件(~./ssh/config)
#配置github
Host github.com
HostName github.com
IdentityFile /Users/pengli/.ssh/github_id_rsa
PreferredAuthentications publickey
User xxxx

#配置码云
Host gitee.com
HostName gitee.com
IdentityFile /Users/pengli/.ssh/gitee_id_rsa
PreferredAuthentications publickey
User xxxx

#配置阿里云 Host code.aliyun.com
HostName code.aliyun.com
IdentityFile /Users/pengli/.ssh/aliyun_id_rsa
PreferredAuthentications publickey
User xxxx

7.验证

ssh -T git@github.com
出现以下就是成功:
Hi xxxx! You've successfully authenticated, but GITEE.COM does not provide shell access.