Ryusuke Fuda's Tech Blog

Softweare Enginier about Web, iOS, Android.

sshキーをホスト毎に分ける。

例えば複数のサーバーで公開鍵を使って認証している場合、gitコマンドで使う鍵を変えなければいけない。

ssh configを設定する

cd ~/.ssh
vim config
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa
    Port 22

Host other.git.com
    HostName other.git.com
    User git
    IdentityFile ~/.ssh/id_rsa_other
    Port 22

ssh configをつくると、git clone {URL}のURLのホストをみて
自動で鍵を切り替えてくれる。

参考)
http://nilfigo.hatenablog.com/entry/20130705/1373000104