同时管理多个ssh私钥【转载】
在设置github的时候,官方的说明文档要求备份当前的id_rsa,然后生成一份新的私钥用于github的登陆。如果真这样做,那么新的私钥是无法再继续登陆之前的机器的。这种方法有点暴力…
还好ssh可以让我们通过不同的私钥来登陆不同的域。
首先,在新增私钥的时候,通过指定不同的文件名来生成不同的私钥文件
ssh-keygen -t rsa -f ~/.ssh/id_rsa.work -C "Key for Work stuff" ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "Key for GitHub stuff"
新增ssh的配置文件,并修改权限
touch ~/.ssh/config chmod 600 ~/.ssh/config
修改config文件的内容
Host *.workdomain.com
    IdentityFile ~/.ssh/id_rsa.work
    User lee
 
Host github.com
    IdentityFile ~/.ssh/id_rsa.github
    User git这样在登陆的时候,ssh会根据登陆不同的域来读取相应的私钥文
.ssh: lee$ ssh -vT [email protected] OpenSSH_5.2p1, OpenSSL 0.9.8r 8 Feb 2011 debug1: Reading configuration data /Users/lee/.ssh/config debug1: Applying options for github.com debug1: Reading configuration data /etc/ssh_config debug1: Connecting to github.com [207.97.227.239] port 22. debug1: Connection established. debug1: identity file /Users/lee/.ssh/id_rsa.github type 1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5github2 debug1: match: OpenSSH_5.1p1 Debian-5github2 pat OpenSSH*
原文链接:李玉鹏的blog -- http://www.leeyupeng.com/2011/11/multiple-ssh-private-keys/
相关推荐
  lepton    2020-07-04  
   tosim    2020-06-24  
   projava    2020-11-14  
   WanKaShing    2020-11-12  
   airfish000    2020-09-11  
   tryfind    2020-09-14  
   yegen00    2020-09-10  
   kkaazz    2020-09-03  
   风语者    2020-09-02  
   BraveWangDev    2020-08-19  
   lichuanlong00    2020-08-15  
   gsl    2020-08-15  
   pandaphinex    2020-08-09  
   yhuihon    2020-08-09  
   CheNorton    2020-08-02  
   xiangqiao    2020-07-28  
   hpujsj    2020-07-26  
   hpujsj    2020-07-26  
   sshong    2020-07-19