需求:
- 代码有多个仓库,需要配置不同的密钥。
- 生成密钥(有的可以跳过)
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/id_rsa_custom_name
- -t rsa 指定使用 RSA 算法。
- -b 4096 指定密钥长度为 4096 位(推荐)。
- -f ~/.ssh/id_rsa_custom_name: 指定生成的密钥文件的路径和名称。
强烈推荐自定义名称
除了RSA算法,ED25519和 ECDSA 也是常见的算法,可以根据平台自行选择。
- 多环境配置匹配密钥
创建 SSH 配置文件:touch ~/.ssh/config
根据环境配置
Host your_host_name
HostName your_host_url
User git
IdentityFile ~/.ssh/id_rsa_custom_name
- Host: 设置匹配的主机名。
- HostName: 实际连接的主机地址。
- IdentityFile: 指定使用的 RSA 私钥路径。
备注:一个文件可以配置多个,用 Host分隔。
- 添加公钥到平台
公钥文件 以 pub 为结尾,例如 id_rsa_custom_name_pub,复制公钥到 GitLab/GitHub,保存。
- 验证连接
ssh -T user@host



![贵州茅台[600519]行情数据接口](https://i-blog.csdnimg.cn/direct/0f78362d4f06471cab8d38e836d0d607.png)










![[工具分享] 根据Excel数据根据Word文档模板,批量创建生成Word文档并重命名,方便快速查找打印](https://i-blog.csdnimg.cn/direct/08c579d95a8449cb9391820c694ea7e3.png)




