![](https://img-blog.csdnimg.cn/img_convert/f6b75f83c9aec2b3267f235bc8d14f34.jpeg)
In the usual development process, our ssh public key is configured on the company's git, but if we want to pass the ssh clone code from github, what should we do? You can't directly configure the public key configured in the company on git. This is too insecure. There is no good way. The answer must be yes, that is to configure two sets of ssh public keys. No more nonsense, let's start directly.
Step 1: Create ssh-key
If you create an ssh public key locally, you will be prompted to overwrite the existing public key with the same name. This is because I have created a public key with the same name before, but I regenerated it after it expired, so it is directly overwritten. You can see that there are already two pairs of public and private keys in my second picture.
ssh-keygen -t rsa -f ~/.ssh/id_rsa.qlh -C "自己的邮箱"
![](https://img-blog.csdnimg.cn/img_convert/53689ff4a2bc8566e279cf2f2a1f825f.png)
![](https://img-blog.csdnimg.cn/img_convert/6fff58121fda4ea8dc94504020aa155d.png)
Step 2: Modify the configuration
Configuration file path: config under /Users/liluyang/.ssh. According to the format configuration below, the git address of the company is hidden in my second screenshot. You can check the format by comparison.
# second user([email protected])
# 建一个github别名,新建的帐号使用这个别名做克隆和更新
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa.github
# second user([email protected])
# 建一个gitee别名,新建的帐号使用这个别名做克隆和更新
Host gitee
HostName gitee.com
User git
IdentityFile ~/.ssh/id_rsa.gitee
![](https://img-blog.csdnimg.cn/img_convert/09c818f8d737c4cabf8270bea71fc2ba.png)
Step 3: Reference by alias
Establish a connection through an alias. The format used is as follows. It should be noted here that there may be an error message, reminding that the public key is expired. In fact, the configuration in the git warehouse has expired, and it can be replaced with the new one just generated.
ssh -T 这里是你的git地址
![](https://img-blog.csdnimg.cn/img_convert/1e0585aa7fe73f36c74adca8eccd4d9f.png)
By modifying the ssh key of the git warehouse, the specific path is as follows. I will not map the added process, and wait for the last step after adding.
![](https://img-blog.csdnimg.cn/img_convert/c0af470fbbfb9035d24bcf7e1d314dc3.png)
Step 4: Add key to ssh-agent
After the third step is configured, you may also encounter the following errors. Then just add the public key to ssh-agent. The following command can be executed directly if the error is reported.
Warning: Permanently added 'e.coding.net,175.24.250.178' (RSA) to the list of known hosts.
[email protected]: Permission denied (publickey).
ssh-add -K ~/.ssh/id_rsa.qlh
Execute again, ssh -T [email protected] can see the success message.
![](https://img-blog.csdnimg.cn/img_convert/339270fe22eb17de0104fae4fbf5d595.png)
I hope it can help everyone, and I also reserve the operation method for myself, in case I forget to check it in the future.