helen's blog

ずっとおもしろいことしてたいな。

bitbucket使ってみた

アカウント作成しようとしたらすでにアカウントがあったことはさておき
新しくリポジトリを作ってiTermとの接続のためにいろいろしたのでメモ

ちなみに見た目は同社製品とすごくそっくりです
右上のアカウント名>設定>SSHキーで公開鍵の追加ができそうという既視感を感じたレベル

macで鍵生成して登録

$ mkdir .ssh/bitbucket
$ cd .ssh/bitbucket
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (xxxxxxxxxx/.ssh/id_rsa): id_rsa # ファイル名
Enter passphrase (empty for no passphrase): # パスワード
Enter same passphrase again: # パスワード再入力
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is: ...

# 確認
$ ll
total 16
-rw-------  1 helen  staff   1.7K  4 10 17:03 id_rsa
-rw-r--r--  1 helen  staff   404B  4 10 17:03 id_rsa.pub

オプションいるのかと思ってたけど無しで両方生成された

fingerprintとは
  • 鍵の指紋
  • 公開鍵と秘密鍵の指紋は同じ
  • 公開鍵からハッシュ関数を使って作られる
  • 接続しようとしているサーバーが正しいか確認しやすくしている(短いから)
  • 初回のSSH接続時には表示されるが以降はクライアントに保存される(ぽい)

参考:指紋の話 — 京大マイコンクラブ (KMC)

$ ssh-keygen -l -f 鍵ファイル

で指紋を確認できる
参考:ssh鍵の鍵指紋を表示 - Qiita

よっしゃー鍵登録したからリポジトリクローンするぞ!!
と思ったらできませんでした

$ git clone git@bitbucket.org:xxxxxxx/xxxxxx.git       
Cloning into 'xxxxxxx'...
The authenticity of host 'bitbucket.org' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'bitbucket.org to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

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

known_hostsの追加が必要らしい

$ vim ./.ssh/config

# 追記内容
Host bitbucket.org
Hostname bitbucket.org
Identityfile ~/.ssh/bitbucket/id_rsa

これで接続できた

$ git push origin
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
Everything up-to-date

ウワーGitガ1.7ダー
それgit2.0以上やないと使えないやつやんけーっていうのは置いといて
ちょっとgitignoreをましな状態にして(いつかなおす)

$ git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 246 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@bitbucket.org:xxxxxx/xxxxxxx.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

最初はブランチが存在しないのでrefがないって怒られないために
-uオプションでmasterブランチを作成しつつプッシュ

そのうち.gitconfigきれいにするからな!絶対やるからな!