LoginSignup
3
3

More than 5 years have passed since last update.

【GitHub】公開鍵を登録しているのにssh接続できない問題

Last updated at Posted at 2019-05-26

状況

  • git clone git@github.com:username/repo_name.gitをしようとしたら以下のエラーが出る。
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
  • リポジトリは絶対にある。
  • 公開鍵も登録した。
  • なぜ...

解決策

こちらのサイトに助けていただきました。

SSHで接続する際にデフォルトで読みにいく秘密鍵のパスは「~/.ssh/id_rsa」「~/.ssh/id_dsa」「~/.ssh/identity」のいずれかです。それ以外のパスで置いても読み込まれません。

公開鍵に名前を付けていたので、鍵を読みに行ってくれていなかったということでした。.ssh/configのファイルを作成して以下をファイル内に記述。

Host github github.com
  HostName github.com
  IdentityFile ~/.ssh/#秘密鍵のファイル名
  User git
  Port 22

これでいけるか...!

ssh接続テストをしてみた。
ssh -T git@github.com

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for '秘密鍵のpath' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "秘密鍵のpath": bad permissions
git@github.com: Permission denied (publickey).

残念。
秘密鍵のパーミッションがヤバイとのことなので、ファイルのプロパティーから変更。(書き込みをできないようにした)

これで接続成功しました。
ちなみにコマンドラインからパーミッションを変更したい場合、windowsだとchmodがなくてicaclsというコマンドらしい。

3
3
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
3
3