LoginSignup
0
0

More than 5 years have passed since last update.

'git push -u origin --all'を阻まれたでござるの巻

Last updated at Posted at 2017-03-04

こんにちは`Permission denied (publickey).

久しぶりにbitbucketにpushしようとしたら…

$ git push -u origin --all
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

お馴染みのPermission denied (publickey).と遭遇.

とりあえず「Permission denied bitbucket」,というシンプルなググりをすると,解決できそうな記事に出会いました.いい時代です.

参考文献:Gitで”Permission denied (publickey).” が出たときのメモ
http://qiita.com/sygnas/items/43306a738f01cb7ab45c

さて,これを頼りに解決しますか…

解決編

書き忘れてましたがMac OSXの話です.
上記参考文献に従ってまずはsshの鍵を作成します.
デフォルトだとid_rsaに吐かれるようなのですが,既にid_rsaが有ったのでわかりやすいようにbitbucket_rsaという名前で作ります.

$ ssh-keygen -t rsa -C <bitbucket登録メールアドレス>
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/***/.ssh/id_rsa): /Users/***/.ssh/bitbucket_rsa

この時passphraseを聞かれましたが,いちいちパスワード入れるの面倒くさいので無しでEnterを叩きました.
これで~/.sshbitbucket_rsabitbucket_rsa.pubが作られたと思います.

で,鍵ができたのでconfigの中身を変更します.

~/.ssh/config
Host bitbucket.org
  HostName bitbucket.org
  User git
  Port 22
  IdentityFile ~/.ssh/bitbucket_rsa
  TCPKeepAlive yes
  IdentitiesOnly yes

次はbitbucket側に公開鍵情報を登録しに行きます.

$ pbcopy < bitbucket_rsa.pub

で公開鍵の中身をクリップボードにコピーし.bitbucketのアカウント管理のところに貼ってください.詳しくは下記の参考文献の方を参照してください…

参考文献:Bitbucketアカウントに公開鍵をインストールする方法
https://confluence.atlassian.co.jp/pages/viewpage.action?pageId=35095449

さて,これで大丈夫なはず!
ログインできるか確認してみましょう.

$ ssh -T git@bitbucket.org
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/Users/***/.ssh/bitbucket_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /Users/***/.ssh/bitbucket_rsa
Permission denied (publickey).

あれ…(汗)
パーミッションの設定が開きすぎだぞって怒られました.
そこで,秘密鍵のパーミッションを644(-rw-r--r-)から600(-rw-------)に変更します.

$ chmod 600 bitbucket_rsa

一応$ls -laで確認してみるとちゃんとbitbucket_rsaのパーミッションが変更されていたので,再びログインできるか確認.

$ ssh -T git@bitbucket.org
logged in as ***

You can use git or hg to connect to Bitbucket. Shell access is disabled.

できました.

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