同时管理多个ssh私钥

来源:互联网 发布:微盘商城源码 编辑:程序博客网 时间:2024/05/19 10:33

在设置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/configchmod 600 ~/.ssh/config

修改config文件的内容

1234567
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 git@github.comOpenSSH_5.2p1, OpenSSL 0.9.8r 8 Feb 2011debug1: Reading configuration data /Users/lee/.ssh/configdebug1: Applying options for github.comdebug1: Reading configuration data /etc/ssh_configdebug1: Connecting to github.com [207.97.227.239] port 22.debug1: Connection established.debug1: identity file /Users/lee/.ssh/id_rsa.github type 1debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5github2debug1: match: OpenSSH_5.1p1 Debian-5github2 pat OpenSSH*
0 0
原创粉丝点击