Mac 環境下連線多個git — ssh方式

gsbybb發表於2018-01-19

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

相關文章