Mac 环境下连接多个git — ssh方式

Mac 环境下连接多个git — ssh方式

1.查看当前是否存在ssh

ls ~/.ssh/

看到 id_rsa 与 id_rsa_pub 则说明已经有一对密钥。

2.生产新的公钥,并命名它不于之前的冲突

ssh-keygen -t rsa -f ~/.ssh/id_rsa_2 -C "yourmail@xxx.com"

3.配置sshKey对应的Host

vim ~/.ssh/config

根据实际的Host修改文件,例如有github和ieit两个Host,则像如下方式修改

# default                                                                       
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# two                                                                           
Host ieit.github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_2

4.复制新生成的ssh-key,去相应的地方配置

pbcopy < ~/.ssh/id_rsa.pub

5.测试是否成功

ssh -T git@yourhost.com

收到入下信息表示配置成功

The authenticity of host 'github.com (192.30.255.112)' can't be established.
RSA key fingerprint is SHA256:sdfsxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.
Hi gsbybb! You've successfully authenticated, but GitHub does not provide shell access.

6.克隆repo
7.取消全局 用户名/邮箱设置,并进入项目文件夹单独设置

git config --global --list //查看全局设置
git config user.name "yourname"
git config user.email "your@email.com"

8.命令行进入项目目录,重建 origin

git remote rm origin
git remote add origin git@ieit.github.com

9.成功,可以 push 测试一下

    原文作者:gsbybb
    原文地址: https://segmentfault.com/a/1190000012906608
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞