如何添加public key使能访问多个git 服务器

1. 在~/.ssh下添加config文件,如下步骤:

~/.ssh
$ vi config
Host git.oschina.net
  HostName git.oschina.net
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/osc_id_rsa

Host github.com
  HostName github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/git_id_rsa

 

 2. 为不同git服务器分别添加public key,如下步骤:

  
ssh-keygen -t rsa -C "[email protected]"  -f ~/.ssh/osc_id_rsa  
ssh-keygen -t rsa -C "[email protected]"  -f ~/.ssh/git_id_rsa

 

这样就可以同时访问github.com与git.oschina.net服务器了。

测试一下:

$ ssh -T [email protected]
Enter passphrase for key '/c/Documents and Settings/Beam.Sun.EIFESUN-5D6445F/.ss
h/git_id_rsa':
Hi sunxboy! You've successfully authenticated, but GitHub does not provide shell
 access.

Beam.Sun@EIFESUN-5D6445F ~
$ ssh -T [email protected]
Enter passphrase for key '/c/Documents and Settings/Beam.Sun.EIFESUN-5D6445F/.ss
h/osc_id_rsa':
Welcome to Git@OSC, sunxboy!

 

你可能感兴趣的:(public)