MAC GIT 多SSH公钥添加

mac 系统下,多个 ssh公钥 创建添加
[email protected] 替换成对应的账号邮箱

普通权限与root权限的区别就是路径地址不同
普通权限:~/.ssh/
root权限:/var/root/.ssh/

创建 github SSH-KEY

1:生成
按照提示完成三次回车

ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/github_id_rsa
# sudo ssh-keygen -t rsa -C '[email protected]' -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 '[email protected]' -f ~/.ssh/gitee_id_rsa
# sudo ssh-keygen -t rsa -C '[email protected]' -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 [email protected]
# sudo ssh -T [email protected]
# Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

ssh -T [email protected]
# Hi xxx! You've successfully authenticated, but GITEE.COM does not provide shell access.



2020/01/17
遇到了一个问题:使用ssh推送代码到远程git服务器报错,ssh 配置正常没有做任何的修改

ssh: Could not resolve hostname [git.xxx.com](http://git.xxx.com): 
nodename nor servname provided, or not known
fatal: 无法读取远程仓库。

解决办法:

ssh-keyscan -H git.xxx.com >> ~/.ssh/known_hosts

参考:https://blog.csdn.net/Zheng548/article/details/79079293

你可能感兴趣的:(MAC GIT 多SSH公钥添加)