公開鍵認証でSSH越しのgit cloneにハマる
意外とやってみてチョットハマったのでメモ、SSHの鍵認証を利用した時のgitでcloneしようと試したのですが、色々試したものの以下のメッセージがでてcloneできない
まず、普通の鍵認証でsshしリモートのサーバーへログインできることが前提です
cuomo@karky7 ~ $ ssh -i ~/.ssh/identkey user@123.456.789.999 Enter passphrase for key '/home/localuser/.ssh/prikey': user@host ~ $
「Permission denied (publickey).」公開鍵が違うじゃねぇーか的なメッセージでてcloneできない
cuomo@karky7 ~ $ git clone ssh://user@123.456.789.999/home/user/mou_muridesu.git Cloning into 'mou_muridesu'... Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. cuomo@karky7 ~ $
ssh越しにgitが出きるように設定する
どうやらgitでsshを利用する際に特定の秘密鍵をしてする方法があるらしく.sshディレクトリ以下のconfigファイルをおくというもの
cuomo@karky7 ~ $ pwd /home/user cuomo@karky7 ~ $ cat .ssh/config Host remotehost HostName 123.456.789.999 Port 22 User user IdentityFile ~/.ssh/prikey cuomo@karky7 ~ $ここで注意することは、ファイルとディレクトリのパーミッション
- .ssh ・・・ 0700
- config ・・・ 0600
にしておいてください、Hostはエイリアスなので自分のわかりやすい接続名をつけてください、あとはわかりますよね。
git cloneしてみる
設定ファイルを置いたらcloneしてみる、ここでホストの部分はエイリアス名を指定する。
cuomo@karky7 ~ $ git clone ssh://remotehost/home/user/mou_muridesu.git Cloning into 'mou_muridesu'... Enter passphrase for key '/home/user/.ssh/identkey': remote: Counting objects: 294, done. remote: Compressing objects: 100% (224/224), done. remote: Total 294 (delta 121), reused 160 (delta 59) Receiving objects: 100% (294/294), 3.02 MiB | 584.00 KiB/s, done. Resolving deltas: 100% (121/121), done. Checking connectivity... done cuomo@karky7 ~ $cloneできました、configファイルを置くとその他のssh接続に影響がある場合がございますのでご注意ください、その他、環境変数 GIT_SSHなるものがありますが調べておりません。
案外面倒...
0 件のコメント:
コメントを投稿