Mac 環境下鏈接多個git — ssh方式

Mac 環境下鏈接多個git — ssh方式

1.查看當前是否存在sshgit

ls ~/.ssh/
看到 id_rsa 與 id_rsa_pub 則說明已經有一對密鑰。

2.生產新的公鑰,並命名它不於以前的衝突github

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

3.配置sshKey對應的Hostshell

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,去相應的地方配置vim

pbcopy < ~/.ssh/id_rsa.pub

5.測試是否成功ssh

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.取消全局 用戶名/郵箱設置,並進入項目文件夾單獨設置ide

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 測試一下命令行

相關文章
相關標籤/搜索