SSH多密钥管理

在工做中常常须要使用不一样的私钥登陆不一样的服务器,遂须要对不一样的私钥进行管理git

首先,在新增私钥的时候须要经过不一样的文件名来生成不一样的私钥文件github

ssh-keygen -t rsa -f ~/.ssh/id_rsa.work -C "key for work"
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "key for github"

新增ssh配置文件,并修改权限服务器

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

编辑配置文件dom

vi ~/.ssh/config
Host *.workdomain.com
    HostName *.workdomain.com
    IdentityFile ~/.ssh/id_rsa.work
    
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa.github
  • Host为别名
  • HostName为服务器的域名或IP
  • User表示用哪一个用户名登陆
  • IdentityFile表示用哪一个私钥进行认证

登陆ssh

ssh root@www.workdomain.com

code

ssh github.com