LoginSignup
0
0

More than 5 years have passed since last update.

PyCharm (JetBrains) で複数の private key を github で使う

Last updated at Posted at 2019-04-09

目的達成のために .ssh/config を使いたい

環境

  • Windows 10
  • PyCharm Professional 2018.3
  • git コマンドは cygwin のものを使用

PyCharm の設定は ?

image.png

File->Settings->Git で Path to Get executable を cygwin の git.exe に、SSH executable を Native にする。ここで、どこの git を実行するかは設定できるけど Native がどこの ssh.exe を呼び出すかがわからないので、どこに .ssh/config を置けばいいのかもわからない。

ssh.exe がどこにあるのか調べる

試しにコマンドプロンプトから ssh.exe がどこにあるのか、.ssh ディレクトリをどこに置いたらいいのか推測つけてみる。

C:\Users\yamachan>where ssh
C:\Windows\System32\OpenSSH\ssh.exe
C:\Users\yamachan>set HOMEPATH
HOMEPATH=\Users\yamachan

C:\Windows\System32\OpenSSH\ssh.exe であれば、たぶん \$HOMEPATH/.ssh を読みに行くはず(ディレクトリからして Windows 付属の OpenSSH みたいなので)。そして、たぶん PyCharm もコマンドプロンプトと同じ PATH で ssh.exe を実行(すなわち C:\Windows\System32\OpenSSH\ssh.exe)し、 \$HOMEPATH/.ssh を読みに行くはず。

$HOMEPATH の下に .ssh/config を置いてみる

.ssh/config
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa
Host github.com-piwikjapan
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa-piwikjapan

ドメインが github.com-piwikjapan だったら、id_rsa-piwikjapan という秘密鍵に切り替えられます。実際実験した git レポジトリは、このような名前です:

git@github.com-piwikjapan:piwikjapan/kusanagi-vagrant.git

PyCharm から github に push すると Bad owner or permissions on ...

push_failed.png

  • 別の ID で作ったので、ID わかるところだけ白塗りにした

上記 .ssh/config を設定し PyCharm から github.com-piwikjapan を使って、pull なり push なりすると右下にペロっと表示が出ます。この Bad owner or permissions を誰が出しているか、ですが、試しにコマンドプロンプトから適当な Linux に ssh ログインしてみます:

C:\Users\yamachan>ssh 10.233.3.35
Bad owner or permissions on C:\\Users\\yamachan/.ssh/config

同じメッセージです... つまり PyCharm からも C:\Windows\System32\OpenSSH\ssh.exe を使っていることがわかり、喪目論見通り .ssh/config を読み込みにいっているようです(いままで ssh 10.233.3.35 としても Bad owner or permissions なんて出なかった)。
結局わかったのが cygwin 環境で .ssh/config を作り、\$HOMEPATH(C:\Users\yamachan)に cygwin の cp コマンドでコピーしたのがまずかったようです。cygwin 環境の .ssh/config から、\$HOMEPATH へのコピーを explorer で行うと Bad owner or permissions はでなくなりました。

次は SSH Keyboard Interactive という謎の画面が

push_failed3.png

Bad owner or permissions がなくなったけど、github.com-piwikjapan に push しようとすると、お次は SSH Keyboard Interactive という小窓がでてきて何やら入力しろといわれます、無視して OK をクリックすると:

push_failed2.png

Host key verification failed と右下にペロっと表示されよります。Host key verification とあるので、もしやと思い、コマンドプロンプトから:

C:\Users\yamachan>ssh github.com-piwikjapan
The authenticity of host 'github.com (192.30.255.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi piwikjapan! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

C:\Users\yamachan>

.ssh/known_hosts がなかったんですね。ここまできて、github.com-piwikjapan でも push 可能となりました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0