mac 系统下,多个 ssh公钥 创建添加
xxx@xxx.xxx 替换成对应的账号邮箱
普通权限与root权限的区别就是路径地址不同
普通权限:~/.ssh/
root权限:/var/root/.ssh/
创建 github SSH-KEY
1:生成
按照提示完成三次回车
ssh-keygen -t rsa -C 'xxx@xxx.xxx' -f ~/.ssh/github_id_rsa
# sudo ssh-keygen -t rsa -C 'xxx@xxx.xxx' -f /var/root/.ssh/github_id_rsa
2:查看 ssh key
cat ~/.ssh/github_id_rsa.pub
# sudo cat /var/root/.ssh/github_id_rsa.pub
# ssh-rsa AAAAB3NzaC1yc2EAAAADAQABA....
3:复制内容到 github 添加 SSH key
创建 gitee(码云) SSH-KEY
1:生成
按照提示完成三次回车
ssh-keygen -t rsa -C 'xxx@xxx.xxx' -f ~/.ssh/gitee_id_rsa
# sudo ssh-keygen -t rsa -C 'xxx@xxx.xxx' -f /var/root/.ssh/gitee_id_rsa
2:查看 ssh key
cat ~/.ssh/gitee_id_rsa.pub
# sudo cat /var/root/.ssh/gitee_id_rsa.pub
# ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB...
3:复制内容到 gitee 添加 SSH key
创建 SSH 用户配置文件 config
touch ~/.ssh/config
# sudo touch /var/root/.ssh/config
添加以下内容
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa
# IdentityFile /var/root/.ssh/github_id_rsa
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
# IdentityFile /var/root/.ssh/gitee_id_rsa
Host 和 HostName 填写 git 服务器的域名
IdentityFile 指定私钥的路径
测试
ssh -T git@github.com
# sudo ssh -T git@github.com
# Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
ssh -T git@gitee.com
# Hi xxx! You've successfully authenticated, but GITEE.COM does not provide shell access.
好文值得转载【转载】https://www.jianshu.com/p/c2e815937746