由于个人有公司和个人多个git 账户 ,问了区分,我们需要配置多个ssh key
1.生成不同的ssh key
larances-Mac-mini:~ larance$ ssh-keygen -t rsa -b 2048 -C your@hostname.com
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/larance/.ssh/id_rsa): /Users/larance/.ssh/id_lenovo_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/larance/.ssh/id_xx_rsa.
Your public key has been saved in /Users/larance/.ssh/id_xxx_rsa.pub.
让你选择在哪里选择存放key的时候写个名字,比如 id_xxx_rsa,之后的两个回车。
2.配置config
若.ssh目录(就是私钥所在的文件夹)下无config文件,那么创建
输入一下
# gitlab company
Host company.com
HostName company.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_company_rsa
User name@company.com
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
User larance@126.com
然后保存起来