SSH: 使用步骤:
1、 生成新的 SSH 密钥
//默认使用ed25519文件名字
ssh-keygen -t ed25519 -C “name1@163.com”
//指定id_ed25519_126文件名字
ssh-keygen -t ed25519 -C “name2@126.com” -f ~/.ssh/id_ed25519_126
2、添加到 SSH 代理:
ssh-add ~/.ssh/id_ed25519_126
可以添加多个: id_ed25519、 id_ed25519_126 等等
3、查看公钥内容
cat ~/.ssh/id_ed25519.pub
cat ~/.ssh/id_ed25519_126.pub
多个公钥配置管理和使用
1、创建config文件:
# 编辑 SSH 配置文件
nano ~/.ssh/config
2、添加以下内容到config文件:(意思是github-getepic域名 指向id_ed25519证书, github-126指向id_ed25519_126证书)
# GitHub 使用 id_ed25519 密钥
# 第一个密钥 – getepic 邮箱(用于原有项目)
Host github-pro1
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
# 第二个密钥 – 126 邮箱(用于新项目)
Host github-126
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_126
IdentitiesOnly yes
3、原来的SSH仓库地址对应修改:
git@
git.com:projectname/abc.git 改成: git@
github-pro1:projectname/abc.git
git@
github.com:projectname/def.git 改成: git@
github-126:projectname/def.git