..

同时管理多个 SSH Private Key

SSH可以让我们通过不同的私钥来登陆不同的域。

生成私钥

在新增私钥的时候,通过指定不同的文件名来生成不同的私钥文件:

ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C "Key for GitHub"
ssh-keygen -t rsa -f ~/.ssh/id_rsa_gitcoding -C "Key for GitCoding"
ssh-keygen -t rsa -f ~/.ssh/id_rsa_gitosc -C "Key for GitOSC"

配置Config

新增SSH的配置文件,并修改权限:

touch ~/.ssh/config
chmod 600 ~/.ssh/config

修改Config文件的内容:

Host github.com
    IdentityFile ~/.ssh/id_rsa_github
    User Sunnyyoung

Host coding.net
    IdentityFile ~/.ssh/id_rsa_gitcoding
    User Sunnyyoung

Host oschina.net
    IdentityFile ~/.ssh/id_rsa_gitosc
    User Sunnyyoung

测试

最终SSH会根据登陆不同的域来读取相应的私钥文件。