在用户目录下找到 .ssh 文件夹,创建一个名为 config 的文本文件,内容如下:
Host github_a创建完成后,运行以下命令测试 config 文件是否配置正确:
HostName github.com
User myname_a
IdentityFile ~/.ssh/id_rsa_1
Host github_b
HostName github.com
User myname_b
IdentityFile ~/.ssh/id_rsa_2
Host gitlab
HostName 192.168.66.88
User myname_c
IdentityFile ~/.ssh/id_rsa_3
ssh -T git@github_a!!注意:
ssh -T git@github_b
ssh -T git@gitlab
- HostName, User, IdentityFile 这三行前需要有空格
- Host github_b 这一行前不能有空行。同样地,Host gitlab 前也不能有空行。否则会报错,一开始被坑了好多次
- User 一行,用户名不能包含空格
参考:
- https://gist.github.com/JoaquimLey/e6049a12c8fd2923611802384cd2fb4a
- https://www.jianshu.com/p/89cb26e5c3e8
- https://www.cnblogs.com/fanbi/p/7825746.html