@kyanny's blog

My thoughts, my life. Views/opinions are my own.

github に登録する公開鍵ファイルを id_rsa.pub じゃない名前で使いたい→ ~/.ssh/config で解決

github_id_rsa.pub とかを別につくって git コマンドにはそっちのペアを鍵ファイルとして使って欲しいんだけどうまくいかない。

$ export GIT_SSH="ssh -i ~/.ssh/github_id_rsa"
$ git clone git@github.com:XXXX/XXXX
  # Permission denied

Gitのリポジトリにsshでアクセスする | Hiroaki's blog をみて warpper つくってみたけどやっぱりだめ。こちらは ssh コマンドがヘンになるみたい。

$ echo '#!/bin/sh
shift
exec ssh -i ~/.ssh/github_id_rsa $*' > ~/bin/git-ssh
$ export GIT_SSH=$HOME/bin/git-ssh
$ git clone git@github.com:XXXX/XXXX
  # ssh: Could not resolve hostname git-upload-pack: nodename nor servname provided, or not known
  # fatal: The remote end hung up unexpectedly とかエラー

うーん。

追記

Redirecting... に書いてあった。 FAQ だったか。

したのほうの Problems? のところに、 $HOME/.ssh/config ファイルにこうかけ、とかいてあった。これをかいたら動いた。

Host github.com
  User git
  Port 22
  Hostname github.com
  IdentityFile ~/.ssh/github_id_rsa
  TCPKeepAlive yes
  IdentitiesOnly yes

さらに追記 2012/02/09

GIT_SSH 環境変数にラッパースクリプトを指定する方法もある。

http://hisashim.org/2010/02/23/git-ssh-options.html

$ cat git2.sh
#!/bin/sh
exec ssh -o User=kyanny -o IdentityFile=~/.ssh/id_rsa_hoge "$@"
$ GIT_SSH=git2.sh git push origin master