一半君的总结纸

听话只听一半君

ssh 使用多组密钥对备忘录

一组key到处乱用不好吧

  1. 首先当然是平时怎么用ssh-keygen还是一样的用,存出一组不同的key pair就行
  2. 然后需要编辑~/.ssh/ssh

ps:
看了一下我的centos7.2上的默认配置 /etc/ssh/ssh_config

pss: 如果同时使用了passphrase,那就得使用ssh-agent,和ssh-add 才能避免每次都要输密码了

Host SERVERNAME1
  IdentitiesOnly yes
  IdentityFile ~/.ssh/id_rsa_SERVER1
  # CheckHostIP yes
  # Port 22

Host SERVERNAME2
  IdentitiesOnly yes
  IdentityFile ~/.ssh/id_rsa_SERVER2
  CheckHostIP no

Host *
  [ global settings .. ]

如果服务器ip地址经常变动,又不想每次看到这警告提示,可以加上CheckHostIP no

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is…

举例,github多账号

#user1 account
Host github.com-user1
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_user1

#user2 account
Host github.com-user2
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_user2

Host *
SendEnv LC_*

repo里也可以设置(不确定需不需要)

git config user.name "user"
git config user.email "user@gmail.com" 

如果 user1 是默认账号,那可以
git config --global user.name "user"
...
eval "$(ssh-agent -s)"

ssh-add ~/.ssh/id_rsa_user1
ssh-add ~/.ssh/id_rsa_user2

参考:
SSH keys – 管理多组密钥对
SSH ControlMaster: The Good, The Bad, The Ugly

Multiple SSH Keys settings for different github account

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: